diff --git a/lib/Internal/Controls.js b/lib/Internal/Controls.js index 1e644bf94d..df11fbd33b 100644 --- a/lib/Internal/Controls.js +++ b/lib/Internal/Controls.js @@ -95,6 +95,32 @@ const CHOICES_BUTTON_WITH_VARIABLES = serializeIsVisibleFn([ }, ]) +const CHOICES_STEP_WITH_VARIABLES = serializeIsVisibleFn([ + { + type: 'checkbox', + label: 'Use variables for step', + id: 'step_from_expression', + default: false, + }, + { + type: 'number', + label: 'Step', + tooltip: 'Which Step?', + id: 'step', + default: 1, + min: 1, + isVisible: (options) => !options.step_from_expression, + }, + { + type: 'textinput', + label: 'Step (expression)', + id: 'step_expression', + default: '1', + isVisible: (options) => !!options.step_from_expression, + useVariables: true, + }, +]) + const ButtonStylePropertiesExt = [ ...ButtonStyleProperties, { id: 'show_topbar', label: 'Topbar' }, @@ -149,6 +175,16 @@ export default class Controls extends CoreBase { } } + #fetchStep(options) { + let theStep = options.step + + if (options.step_from_expression) { + theStep = this.instance.variable.parseExpression(options.step_expression, 'number').value + } + + return theStep + } + getActionDefinitions() { return { button_pressrelease: { @@ -339,18 +375,7 @@ export default class Controls extends CoreBase { bank_current_step: { label: 'Button: Set current step', previewControlIdFn: previewControlIdFn, - options: [ - ...CHOICES_PAGE_WITH_VARIABLES, - ...CHOICES_BUTTON_WITH_VARIABLES, - { - type: 'number', - label: 'Step', - tooltip: 'Which Step?', - id: 'step', - default: 1, - min: 1, - }, - ], + options: [...CHOICES_PAGE_WITH_VARIABLES, ...CHOICES_BUTTON_WITH_VARIABLES, ...CHOICES_STEP_WITH_VARIABLES], }, bank_current_step_condition: { label: 'Button: Set current step if variable meets condition', @@ -382,14 +407,7 @@ export default class Controls extends CoreBase { }, ...CHOICES_PAGE_WITH_VARIABLES, ...CHOICES_BUTTON_WITH_VARIABLES, - { - type: 'number', - label: 'Step', - tooltip: 'Which Step?', - id: 'step', - default: 1, - min: 1, - }, + ...CHOICES_STEP_WITH_VARIABLES, ], }, bank_current_step_if_expression: { @@ -405,14 +423,7 @@ export default class Controls extends CoreBase { }, ...CHOICES_PAGE_WITH_VARIABLES, ...CHOICES_BUTTON_WITH_VARIABLES, - { - type: 'number', - label: 'Step', - tooltip: 'Which Step?', - id: 'step', - default: 1, - min: 1, - }, + ...CHOICES_STEP_WITH_VARIABLES, ], }, bank_current_step_delta: { @@ -700,14 +711,16 @@ export default class Controls extends CoreBase { return true } else if (action.action == 'bank_current_step') { const { theControlId } = this.#fetchPageAndButton(action.options, extras, true) + const theStep = this.#fetchStep(action.options) const control = this.controls.getControl(theControlId) if (control && typeof control.stepMakeCurrent === 'function') { - control.stepMakeCurrent(action.options.step) + control.stepMakeCurrent(theStep) } } else if (action.action == 'bank_current_step_condition') { const { theControlId } = this.#fetchPageAndButton(action.options, extras, true) + const theStep = this.#fetchStep(action.options) const control = this.controls.getControl(theControlId) @@ -739,11 +752,12 @@ export default class Controls extends CoreBase { if (pressIt) { if (control && typeof control.stepMakeCurrent === 'function') { - control.stepMakeCurrent(action.options.step) + control.stepMakeCurrent(theStep) } } } else if (action.action == 'bank_current_step_if_expression') { const { theControlId } = this.#fetchPageAndButton(action.options, extras, true) + const theStep = this.#fetchStep(action.options) const control = this.controls.getControl(theControlId) @@ -751,7 +765,7 @@ export default class Controls extends CoreBase { if (pressIt) { if (control && typeof control.stepMakeCurrent === 'function') { - control.stepMakeCurrent(action.options.step) + control.stepMakeCurrent(theStep) } } } else if (action.action == 'bank_current_step_delta') {