Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import debounceFn from 'debounce-fn'
import type { JsonValue } from 'type-fest'
import { formatLocation } from '@companion-app/shared/ControlId.js'
import type { ControlLocation } from '@companion-app/shared/Model/Common.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import type { ResolvedFeedbackStyleOverride } from '@companion-app/shared/Model/EntityModel.js'
import type { SomeButtonGraphicsElement } from '@companion-app/shared/Model/StyleLayersModel.js'
import {
ButtonGraphicsShowStatusIcons,
Expand Down Expand Up @@ -31,7 +30,7 @@ export interface DrawElementsVisitor {
*/
export interface LayeredButtonDrawerEntitySource {
getLocalVariableEntities(): ControlEntityInstance[]
getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>>
getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>>
}

/**
Expand Down
10 changes: 3 additions & 7 deletions companion/lib/Controls/Entities/EntityListPoolBase.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import debounceFn from 'debounce-fn'
import type { JsonValue } from 'type-fest'
import {
EntityModelType,
type FeedbackEntityStyleOverride,
type ResolvedFeedbackStyleOverride,
type SomeReplaceableEntityModel,
type SomeSocketEntityLocation,
} from '@companion-app/shared/Model/EntityModel.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import { stringifyVariableValue, type VariableValues } from '@companion-app/shared/Model/Variables.js'
import type { InstanceProcessManager } from '../../Instance/ProcessManager.js'
import type { InternalController } from '../../Internal/Controller.js'
Expand Down Expand Up @@ -223,12 +222,9 @@ export abstract class ControlEntityListPoolBase {

/**
* Get all the style overrides for the layered drawing elements
* @returns A map of elementId -> elementProperty -> override value
* @returns A map of elementId -> elementProperty -> resolved override
*/
abstract getFeedbackStyleOverrides(): ReadonlyMap<
string,
ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>
>
abstract getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>>

getLocalVariableValues(): VariableValues {
const entities = this.getLocalVariableEntities()
Expand Down
54 changes: 34 additions & 20 deletions companion/lib/Controls/Entities/EntityListPoolButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { ButtonModelBase, ButtonOptionsBase, NormalButtonSteps } from '@com
import {
EntityModelType,
FeedbackEntitySubType,
type ResolvedFeedbackStyleOverride,
type SomeEntityModel,
type SomeSocketEntityLocation,
} from '@companion-app/shared/Model/EntityModel.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import { stringifyVariableValue, type VariableValues } from '@companion-app/shared/Model/Variables.js'
import { assertNever } from '@companion-app/shared/Util.js'
import type { IPageStore } from '../../Page/Store.js'
Expand Down Expand Up @@ -202,29 +202,30 @@ export abstract class ButtonEntityListPoolBase extends ControlEntityListPoolBase
return entityLists
}

getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>> {
const result = new Map<string, Map<string, ExpressionOrValue<JsonValue | undefined>>>()
getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>> {
const result = new Map<string, Map<string, ResolvedFeedbackStyleOverride>>()

const pushOverride = (
elementId: string,
elementProperty: string,
override: ExpressionOrValue<JsonValue | undefined>
) => {
const targetMap = result.get(elementId) ?? new Map<string, ExpressionOrValue<JsonValue | undefined>>()
const pushOverride = (elementId: string, elementProperty: string, override: ResolvedFeedbackStyleOverride) => {
const targetMap = result.get(elementId) ?? new Map<string, ResolvedFeedbackStyleOverride>()

// Hack: merge imageBuffers so that they stack instead of replacing
if (elementProperty === 'base64Image') {
// Only applies to plain (boolean/advanced) overrides, not value-feedback transforms
if (elementProperty === 'base64Image' && override.thisContext === null) {
const existing = targetMap.get(elementProperty)
if (
existing &&
!existing.isExpression &&
!override.isExpression &&
Array.isArray(existing.value) &&
Array.isArray(override.value)
existing.thisContext === null &&
!existing.value.isExpression &&
!override.value.isExpression &&
Array.isArray(existing.value.value) &&
Array.isArray(override.value.value)
) {
override = {
isExpression: false,
value: [...existing.value, ...override.value],
thisContext: null,
value: {
isExpression: false,
value: [...existing.value.value, ...override.value.value],
},
}
}
}
Expand Down Expand Up @@ -264,7 +265,10 @@ export abstract class ButtonEntityListPoolBase extends ControlEntityListPoolBase
// And the override stores the value to be applied
if (feedback.getBooleanFeedbackValue(null)) {
for (const override of overrides) {
pushOverride(override.elementId, override.elementProperty, override.override)
pushOverride(override.elementId, override.elementProperty, {
value: override.override,
thisContext: null,
})
}
}
break
Expand All @@ -282,15 +286,25 @@ export abstract class ButtonEntityListPoolBase extends ControlEntityListPoolBase
override.elementProperty
)
if (newValue) {
pushOverride(override.elementId, override.elementProperty, newValue)
pushOverride(override.elementId, override.elementProperty, { value: newValue, thisContext: null })
}
}

break
}
case FeedbackEntitySubType.Value:
// Not compatible here
case FeedbackEntitySubType.Value: {
// For value feedbacks, the override is an expression transform of the feedback's value.
// The feedback value is bound to `$(this:value)` and the expression is evaluated at draw time
// (see ElementExpressionHelper), where an `undefined` result means "no override".
const thisContext = { value: feedback.feedbackValue as JsonValue | undefined }
for (const override of overrides) {
pushOverride(override.elementId, override.elementProperty, {
value: override.override,
thisContext,
})
}
break
}
case FeedbackEntitySubType.StyleOverride:
case null:
// Not a real feedback
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { JsonValue } from 'type-fest'
import {
EntityModelType,
FeedbackEntitySubType,
type ResolvedFeedbackStyleOverride,
type SomeSocketEntityLocation,
} from '@companion-app/shared/Model/EntityModel.js'
import type { ExpressionVariableModel } from '@companion-app/shared/Model/ExpressionVariableModel.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import type {
ExpressionParserOptions,
Expand Down Expand Up @@ -99,10 +98,7 @@ export class EntityListPoolExpressionVariable extends WithEntityEditing(ControlE
this.tryTriggerLocalVariablesChanged(...changedVariableEntities)
}

public getFeedbackStyleOverrides(): ReadonlyMap<
string,
ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>
> {
public getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>> {
return new Map()
}

Expand Down
8 changes: 2 additions & 6 deletions companion/lib/Controls/Entities/EntityListPoolPage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { JsonValue } from 'type-fest'
import { ParseControlId } from '@companion-app/shared/ControlId.js'
import {
EntityModelType,
FeedbackEntitySubType,
type ResolvedFeedbackStyleOverride,
type SomeSocketEntityLocation,
} from '@companion-app/shared/Model/EntityModel.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import type { PageControlModel } from '@companion-app/shared/Model/PageControlModel.js'
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import type { IPageStore } from '../../Page/Store.js'
Expand Down Expand Up @@ -101,10 +100,7 @@ export class EntityListPoolPage extends WithEntityEditing(ControlEntityListPoolB
this.tryTriggerLocalVariablesChanged(...changedVariableEntities)
}

public getFeedbackStyleOverrides(): ReadonlyMap<
string,
ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>
> {
public getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>> {
return new Map()
}

Expand Down
8 changes: 2 additions & 6 deletions companion/lib/Controls/Entities/EntityListPoolTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { JsonValue } from 'type-fest'
import {
EntityModelType,
FeedbackEntitySubType,
type ResolvedFeedbackStyleOverride,
type SomeSocketEntityLocation,
} from '@companion-app/shared/Model/EntityModel.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import type { TriggerModel } from '@companion-app/shared/Model/TriggerModel.js'
import type { VariableValues } from '@companion-app/shared/Model/Variables.js'
import type {
Expand Down Expand Up @@ -120,10 +119,7 @@ export class ControlEntityListPoolTrigger extends WithEntityEditing(ControlEntit
this.tryTriggerLocalVariablesChanged(...changedVariableEntities)
}

public getFeedbackStyleOverrides(): ReadonlyMap<
string,
ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>
> {
public getFeedbackStyleOverrides(): ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>> {
return new Map()
}

Expand Down
3 changes: 2 additions & 1 deletion companion/lib/Graphics/ConvertGraphicsElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getElementSchemaProperty,
} from '@companion-app/shared/Graphics/ElementPropertiesSchemas.js'
import type { ControlLocation } from '@companion-app/shared/Model/Common.js'
import type { ResolvedFeedbackStyleOverride } from '@companion-app/shared/Model/EntityModel.js'
import type { ExpressionOrValue } from '@companion-app/shared/Model/Options.js'
import type {
ButtonGraphicsBorder,
Expand Down Expand Up @@ -96,7 +97,7 @@ export async function ConvertSomeButtonGraphicsElementForDrawing(
parser: VariablesAndExpressionParser,
drawPixelBuffers: DrawPixelBuffers,
elements: SomeButtonGraphicsElement[],
feedbackOverrides: ReadonlyMap<string, ReadonlyMap<string, ExpressionOrValue<JsonValue | undefined>>>,
feedbackOverrides: ReadonlyMap<string, ReadonlyMap<string, ResolvedFeedbackStyleOverride>>,
onlyEnabled: boolean,
cache: ElementConversionCache | null,
currentLocationStr: string | null = null,
Expand Down
Loading
Loading