Skip to content

feat: drive button current step from expression #3128 #3225

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions companion/lib/Controls/ControlTypes/Button/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class ButtonControlBase<TJson, TOptions extends Record<string, a
pushed = false

/**
* The variabls referenced in the last draw. Whenever one of these changes, a redraw should be performed
* The variables referenced in the last draw. Whenever one of these changes, a redraw should be performed
*/
protected last_draw_variables: Set<string> | null = null

Expand All @@ -82,6 +82,13 @@ export abstract class ButtonControlBase<TJson, TOptions extends Record<string, a
instanceDefinitions: deps.instance.definitions,
internalModule: deps.internalModule,
moduleHost: deps.instance.moduleHost,
executeExpressionInControl: (expression, requiredType, injectedVariableValues) =>
deps.variables.values.executeExpression(
expression,
deps.page.getLocationOfControlId(this.controlId),
requiredType,
injectedVariableValues
),
},
this.sendRuntimePropsChange.bind(this)
)
Expand Down Expand Up @@ -215,7 +222,8 @@ export abstract class ButtonControlBase<TJson, TOptions extends Record<string, a

...cloneDeep(style),

step_cycle: undefined,
stepCurrent: 1,
stepCount: 1,

pushed: !!this.pushed,
action_running: this.actionRunner.hasRunningChains,
Expand Down
34 changes: 26 additions & 8 deletions companion/lib/Controls/ControlTypes/Button/Normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ControlButtonNormal
this.options = {
...cloneDeep(ButtonControlBase.DefaultOptions),
rotaryActions: false,
stepAutoProgress: true,
stepProgression: 'auto',
}

if (!storage) {
Expand All @@ -70,6 +70,7 @@ export class ControlButtonNormal
this.options = Object.assign(this.options, storage.options || {})
this.entities.setupRotaryActionSets(!!this.options.rotaryActions, true)
this.entities.loadStorage(storage, true, isImport)
this.entities.stepExpressionUpdate(this.options)

// Ensure control is stored before setup
if (isImport) setImmediate(() => this.postProcessImport())
Expand Down Expand Up @@ -118,9 +119,8 @@ export class ControlButtonNormal
const style = super.getDrawStyle()
if (!style) return style

if (this.entities.getStepIds().length > 1) {
style.step_cycle = this.entities.getActiveStepIndex() + 1
}
style.stepCurrent = this.entities.getActiveStepIndex() + 1
style.stepCount = this.entities.getStepIds().length

return style
}
Expand Down Expand Up @@ -159,13 +159,21 @@ export class ControlButtonNormal
/**
* Update an option field of this control
*/
optionsSetField(key: string, value: any): boolean {
optionsSetField(key0: string, value: any): boolean {
const key = key0 as keyof NormalButtonOptions

// Check if rotary_actions should be added/remove
if (key === 'rotaryActions') {
this.entities.setupRotaryActionSets(!!value, true)
}

return super.optionsSetField(key, value)
const changed = super.optionsSetField(key, value)

if (key === 'stepProgression' || key === 'stepExpression') {
this.entities.stepExpressionUpdate(this.options)
}

return changed
}

/**
Expand All @@ -175,7 +183,7 @@ export class ControlButtonNormal
* @param force Trigger actions even if already in the state
*/
pressControl(pressed: boolean, surfaceId: string | undefined, force: boolean): void {
const [thisStepId, nextStepId] = this.entities.validateCurrentStepIdAndGetNext()
const [thisStepId, nextStepId] = this.entities.validateCurrentStepIdAndGetNextProgression()

let pressedDuration = 0
let pressedStep = thisStepId
Expand Down Expand Up @@ -210,7 +218,7 @@ export class ControlButtonNormal
if (
thisStepId !== null &&
nextStepId !== null &&
this.options.stepAutoProgress &&
this.options.stepProgression === 'auto' &&
!pressed &&
(pressedStep === undefined || thisStepId === pressedStep)
) {
Expand Down Expand Up @@ -289,6 +297,16 @@ export class ControlButtonNormal
})
}

/**
* Propagate variable changes
* @param allChangedVariables - variables with changes
*/
onVariablesChanged(allChangedVariables: Set<string>): void {
super.onVariablesChanged(allChangedVariables)

this.entities.stepCheckExpressionOnVariablesChanged(allChangedVariables)
}

/**
* Convert this control to JSON
* To be sent to the client and written to the db
Expand Down
2 changes: 2 additions & 0 deletions companion/lib/Controls/ControlTypes/Triggers/Trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export class ControlTrigger
instanceDefinitions: deps.instance.definitions,
internalModule: deps.internalModule,
moduleHost: deps.instance.moduleHost,
executeExpressionInControl: (expression, requiredType, injectedVariableValues) =>
deps.variables.values.executeExpression(expression, null, requiredType, injectedVariableValues),
})

this.#eventBus = eventBus
Expand Down
7 changes: 7 additions & 0 deletions companion/lib/Controls/Entities/EntityListPoolBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type { InternalController } from '../../Internal/Controller.js'
import { isEqual } from 'lodash-es'
import type { ButtonStyleProperties } from '@companion-app/shared/Model/StyleModel.js'
import type { InstanceDefinitionsForEntity } from './Types.js'
import type { CompanionVariableValues } from '@companion-module/base'
import type { ExecuteExpressionResult } from '../../Variables/Util.js'

export interface ControlEntityListPoolProps {
instanceDefinitions: InstanceDefinitionsForEntity
Expand All @@ -21,6 +23,11 @@ export interface ControlEntityListPoolProps {
controlId: string
commitChange: (redraw?: boolean) => void
triggerRedraw: () => void
executeExpressionInControl: (
expression: string,
requiredType?: string,
injectedVariableValues?: CompanionVariableValues
) => ExecuteExpressionResult
}

export abstract class ControlEntityListPoolBase {
Expand Down
Loading
Loading