Skip to content

Commit

Permalink
wip: constant value
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Feb 23, 2025
1 parent 4b5a677 commit 20ebd61
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
26 changes: 26 additions & 0 deletions companion/lib/Resources/LocalVariableEntityDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EntityModelType } from '@companion-app/shared/Model/EntityModel.js'
import { InternalActionInputField, InternalFeedbackInputField } from '@companion-app/shared/Model/Options.js'

export enum LocalVariableEntityDefinitionType {
ConstantValue = 'constant-value',
DynamicExpression = 'dynamic-expression',
}

Expand All @@ -25,6 +26,31 @@ const commonOptions: (InternalActionInputField | InternalFeedbackInputField)[] =
]

export const LocalVariableEntityDefinitions: Record<LocalVariableEntityDefinitionType, ClientEntityDefinition> = {
[LocalVariableEntityDefinitionType.ConstantValue]: {
entityType: EntityModelType.LocalVariable,
label: 'Constant Value',
description: 'A constant value that can be used in other fields',
options: [
...commonOptions,
{
id: 'value',
label: 'Value',
type: 'textinput',
default: '1',
isExpression: false,
// useVariables: {
// local: true,
// },
},
],
feedbackType: null,
feedbackStyle: undefined,
hasLearn: false,
learnTimeout: undefined,
showInvert: false,
showButtonPreview: false,
supportsChildGroups: [],
},
[LocalVariableEntityDefinitionType.DynamicExpression]: {
entityType: EntityModelType.LocalVariable,
label: 'Reusable Expression',
Expand Down
8 changes: 6 additions & 2 deletions companion/lib/Variables/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,18 @@ export class VariablesAndExpressionParser {
if (variable.type !== EntityModelType.LocalVariable || variable.connectionId !== 'internal') continue
if (!variable.options.name) continue

const fullId = `$(local:${variable.options.name})`

// TODO-localvariable: can this be made stricter?
const definitionId = variable.definitionId as LocalVariableEntityDefinitionType
switch (definitionId) {
case LocalVariableEntityDefinitionType.ConstantValue: {
this.#localValues.set(fullId, variable.options.value)
break
}
case LocalVariableEntityDefinitionType.DynamicExpression: {
let computedResult: CompanionVariableValue | undefined = undefined

const fullId = `$(local:${variable.options.name})`

const expression = variable.options.expression
this.#localValues.set(fullId, () => {
if (computedResult !== undefined) return computedResult
Expand Down
13 changes: 8 additions & 5 deletions webui/src/Services/Controls/ControlEntitiesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ export function useControlEntitiesEditorService(
})
},

setEnabled: (entityId: string, enabled: boolean) => {
socket.emitPromise('controls:entity:enabled', [controlId, listId, entityId, enabled]).catch((e) => {
console.error('Failed to enable/disable entity', e)
})
},
setEnabled:
entityModelType !== EntityModelType.LocalVariable
? (entityId: string, enabled: boolean) => {
socket.emitPromise('controls:entity:enabled', [controlId, listId, entityId, enabled]).catch((e) => {
console.error('Failed to enable/disable entity', e)
})
}
: undefined,

setHeadline: (entityId: string, headline: string) => {
socket.emitPromise('controls:entity:set-headline', [controlId, listId, entityId, headline]).catch((e) => {
Expand Down

0 comments on commit 20ebd61

Please sign in to comment.