Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: combined stepped and normal button types #2187

Merged
merged 26 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/Controls/ActionRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ export default class ActionRecorder extends CoreBase {

this.commitChanges([sessionId])
})
client.onPromise('action-recorder:session:save-to-control', (sessionId, controlId, setId, mode) => {
client.onPromise('action-recorder:session:save-to-control', (sessionId, controlId, stepId, setId, mode) => {
if (!this.#currentSession || this.#currentSession.id !== sessionId)
throw new Error(`Invalid session: ${sessionId}`)

this.saveToControlId(controlId, setId, mode)
this.saveToControlId(controlId, stepId, setId, mode)
})
}

Expand Down Expand Up @@ -382,24 +382,25 @@ export default class ActionRecorder extends CoreBase {
/**
* Save the recorded actions to a control
* @param {string} controlId The id of the control
* @param {string} stepId
* @param {string} setId The action-set to write to (if applicable)
* @param {string} mode 'replace' or 'append'
*/
saveToControlId(controlId, setId, mode) {
saveToControlId(controlId, stepId, setId, mode) {
if (mode !== 'replace' && mode !== 'append') throw new Error(`Invalid mode: ${mode}`)

const control = this.controls.getControl(controlId)
if (!control) throw new Error(`Unknown control: ${controlId}`)

if (mode === 'append') {
if (control.actions && typeof control.actions.actionAppend === 'function') {
if (!control.actions.actionAppend(setId, this.#currentSession.actions)) throw new Error('Unknown set')
if (typeof control.actionAppend === 'function') {
if (!control.actionAppend(stepId, setId, this.#currentSession.actions)) throw new Error('Unknown set')
} else {
throw new Error('Not supported by control')
}
} else {
if (control.actions && typeof control.actions.actionReplaceAll === 'function') {
if (!control.actions.actionReplaceAll(setId, this.#currentSession.actions)) throw new Error('Unknown set')
if (typeof control.actionReplaceAll === 'function') {
if (!control.actionReplaceAll(stepId, setId, this.#currentSession.actions)) throw new Error('Unknown set')
} else {
throw new Error('Not supported by control')
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Controls/ControlBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ export default class ControlBase extends CoreBase {
this.io.emitToRoom(roomName, `controls:runtime-${this.controlId}`, false)
}

/**
* Get all the actions on this control
*/
getAllActions() {
throw new Error('must be implemented by subclass!')
}

/**
* Get the size of the bitmap render of this control
* @access public
Expand Down
64 changes: 43 additions & 21 deletions lib/Controls/ControlTypes/Button/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ export default class ButtonControlBase extends ControlBase {
relativeDelay: false,
}

/**
* The actions fragment
* @access public
*/
actions

/**
* The feedbacks fragment
* @access public
Expand Down Expand Up @@ -98,12 +92,6 @@ export default class ButtonControlBase extends ControlBase {
constructor(registry, controlId, logSource, debugNamespace) {
super(registry, controlId, logSource, debugNamespace)

this.actions = new FragmentActions(
registry,
controlId,
this.commitChange.bind(this),
this.checkButtonStatus.bind(this)
)
this.feedbacks = new FragmentFeedbacks(
registry,
controlId,
Expand All @@ -122,9 +110,11 @@ export default class ButtonControlBase extends ControlBase {
checkButtonStatus(redraw = true) {
// Find all the instances referenced by the bank
const instance_ids = new Set()
for (const actions in Object.values(this.actions.action_sets)) {
for (const action of actions) {
instance_ids.add(action.instance)
for (const step of Object.values(this.steps)) {
for (const actions in Object.values(step.action_sets)) {
for (const action of actions) {
instance_ids.add(action.instance)
}
}
}

Expand Down Expand Up @@ -162,9 +152,12 @@ export default class ButtonControlBase extends ControlBase {
* @access public
*/
destroy() {
this.actions.destroy()
this.feedbacks.destroy()

for (const step of Object.values(this.steps)) {
step.destroy()
}

super.destroy()
}

Expand All @@ -175,15 +168,35 @@ export default class ButtonControlBase extends ControlBase {
*/
forgetInstance(instanceId) {
const changedFeedbacks = this.feedbacks.forgetInstance(instanceId)
const changedActions = this.actions.forgetInstance(instanceId)

if (changedActions || changedFeedbacks) {
let changedSteps = false
for (const step of Object.values(this.steps)) {
const changed = step.forgetInstance(instanceId)
changedSteps = changedSteps || changed
}

if (changedFeedbacks || changedSteps) {
this.checkButtonStatus(false)

this.commitChange()
}
}

/**
* Get all the actions on this control
*/
getAllActions() {
const actions = []

for (const step of Object.values(this.steps)) {
for (const set of Object.values(step.action_sets)) {
actions.push(...set)
}
}

return actions
}

/**
* Get the size of the bitmap render of this control
* @access public
Expand Down Expand Up @@ -266,12 +279,16 @@ export default class ButtonControlBase extends ControlBase {
const ps = []

ps.push(this.feedbacks.postProcessImport())
ps.push(this.actions.postProcessImport())

for (const step of Object.values(this.steps)) {
ps.push(step.postProcessImport())
}

Promise.all(ps).catch((e) => {
this.logger.silly(`postProcessImport for ${this.controlId} failed: ${e.message}`)
})

this.checkButtonStatus()
this.commitChange()
this.sendRuntimePropsChange()
}
Expand Down Expand Up @@ -389,10 +406,15 @@ export default class ButtonControlBase extends ControlBase {
* @access public
*/
verifyInstanceIds(knownInstanceIds) {
const changedActions = this.actions.verifyInstanceIds(knownInstanceIds)
const changedFeedbacks = this.feedbacks.verifyInstanceIds(knownInstanceIds)

if (changedFeedbacks || changedActions) {
let changedSteps = false
for (const step of Object.values(this.steps)) {
const changed = step.verifyInstanceIds(knownInstanceIds)
changedSteps = changedSteps || changed
}

if (changedFeedbacks || changedSteps) {
this.commitChange()
}
}
Expand Down
Loading