Skip to content

Commit

Permalink
feat: add $(this:step) and $(internal:b_step_X_X_X) variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed May 16, 2024
1 parent fadd96c commit ab5b204
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
37 changes: 22 additions & 15 deletions companion/lib/Graphics/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,30 @@ class GraphicsController extends CoreBase {
const control = controlId ? this.controls.getControl(controlId) : undefined
const buttonStyle = control?.getDrawStyle() ?? undefined

let render
if (location && locationIsInBounds && buttonStyle && buttonStyle.style) {
if (location && locationIsInBounds) {
// Update the internal b_text_1_4 variable
if (location && 'text' in buttonStyle) {
const variableValue = buttonStyle.text
setImmediate(() => {
const values = {
[`b_text_${location.pageNumber}_${location.row}_${location.column}`]: variableValue,
}

const bankIndex = xyToOldBankIndex(location.column, location.row)
if (bankIndex) values[`b_text_${location.pageNumber}_${bankIndex}`] = variableValue

this.instance.variable.setVariableValues('internal', values)
})
}
setImmediate(() => {
/** @type {import('@companion-module/base').CompanionVariableValues} */
const values = {}

// Update text, if it is present
values[`b_text_${location.pageNumber}_${location.row}_${location.column}`] =
buttonStyle?.style === 'button' ? buttonStyle.text : undefined
const bankIndex = xyToOldBankIndex(location.column, location.row)
if (bankIndex)
values[`b_text_${location.pageNumber}_${bankIndex}`] =
buttonStyle?.style === 'button' ? buttonStyle.text : undefined

// Update step
values[`b_step_${location.pageNumber}_${location.row}_${location.column}`] =
buttonStyle?.style === 'button' ? buttonStyle.step_cycle ?? 1 : undefined

this.instance.variable.setVariableValues('internal', values)
})
}

let render
if (location && locationIsInBounds && buttonStyle && buttonStyle.style) {
const pagename = this.page.getPageName(location.pageNumber)

// Check if the image is already present in the render cache and if so, return it
Expand Down
4 changes: 4 additions & 0 deletions companion/lib/Instance/Variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ class InstanceVariable extends CoreBase {
'$(this:page)': location?.pageNumber,
'$(this:column)': location?.column,
'$(this:row)': location?.row,
// Reactivity happens for these because of references to the inner variables
'$(this:page_name)': location ? `$(internal:page_number_${location.pageNumber}_name)` : VARIABLE_UNKNOWN_VALUE,
'$(this:step)': location
? `$(internal:b_step_${location.pageNumber}_${location.row}_${location.column})`
: VARIABLE_UNKNOWN_VALUE,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions webui/src/Components/TextInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ function VariablesSelect({
value: 'this:row',
label: 'This row',
},
{
value: 'this:step',
label: 'The step of this button',
},
{
value: 'this:page_name',
label: 'This page name',
Expand Down

0 comments on commit ab5b204

Please sign in to comment.