@@ -25,16 +25,20 @@ import { protectString } from '../../lib/tempLib'
2525import { StudioActionManager , StudioActionManagers } from './StudioActionManagers'
2626import { DeviceTriggerMountedActionAdlibsPreview , DeviceTriggerMountedActions } from './observer'
2727import { ContentCache } from './reactiveContentCache'
28+ import { ContentCache as PieceInstancesContentCache } from './reactiveContentCacheForPieceInstances'
2829import { logger } from '../../logging'
2930import { SomeAction , SomeBlueprintTrigger } from '@sofie-automation/blueprints-integration'
3031import { DeviceActions } from '@sofie-automation/shared-lib/dist/core/model/ShowStyle'
3132import { DummyReactiveVar } from '@sofie-automation/meteor-lib/dist/triggers/reactive-var'
3233import { MeteorTriggersContext } from './triggersContext'
34+ import { TagsService } from './TagsService'
3335
3436export class StudioDeviceTriggerManager {
3537 #lastShowStyleBaseId: ShowStyleBaseId | null = null
3638
37- constructor ( public studioId : StudioId ) {
39+ lastCache : ContentCache | undefined
40+
41+ constructor ( public studioId : StudioId , protected tagsService : TagsService ) {
3842 if ( StudioActionManagers . get ( studioId ) ) {
3943 logger . error ( `A StudioActionManager for "${ studioId } " already exists` )
4044 return
@@ -45,6 +49,7 @@ export class StudioDeviceTriggerManager {
4549
4650 async updateTriggers ( cache : ContentCache , showStyleBaseId : ShowStyleBaseId ) : Promise < void > {
4751 const studioId = this . studioId
52+ this . lastCache = cache
4853 this . #lastShowStyleBaseId = showStyleBaseId
4954
5055 const [ showStyleBase , rundownPlaylist ] = await Promise . all ( [
@@ -79,6 +84,8 @@ export class StudioDeviceTriggerManager {
7984 const upsertedDeviceTriggerMountedActionIds : DeviceTriggerMountedActionId [ ] = [ ]
8085 const touchedActionIds : DeviceActionId [ ] = [ ]
8186
87+ this . tagsService . clearObservedTags ( )
88+
8289 for ( const rawTriggeredAction of allTriggeredActions ) {
8390 const triggeredAction = convertDocument ( rawTriggeredAction )
8491
@@ -163,6 +170,8 @@ export class StudioDeviceTriggerManager {
163170 sourceLayerType : undefined ,
164171 sourceLayerName : undefined ,
165172 styleClassNames : triggeredAction . styleClassNames ,
173+ isActive : undefined ,
174+ isNext : undefined ,
166175 } ) ,
167176 } )
168177 } else {
@@ -174,6 +183,9 @@ export class StudioDeviceTriggerManager {
174183 )
175184
176185 addedPreviewIds . push ( adLibPreviewId )
186+
187+ this . tagsService . observeTallyTags ( adLib )
188+ const { isActive, isNext } = this . tagsService . getTallyStateFromTags ( adLib )
177189 return DeviceTriggerMountedActionAdlibsPreview . upsertAsync ( adLibPreviewId , {
178190 $set : literal < PreviewWrappedAdLib > ( {
179191 ...adLib ,
@@ -192,6 +204,8 @@ export class StudioDeviceTriggerManager {
192204 }
193205 : undefined ,
194206 styleClassNames : triggeredAction . styleClassNames ,
207+ isActive,
208+ isNext,
195209 } ) ,
196210 } )
197211 } )
@@ -224,6 +238,18 @@ export class StudioDeviceTriggerManager {
224238 actionManager . deleteActionsOtherThan ( touchedActionIds )
225239 }
226240
241+ protected async updateTriggersFromLastCache ( ) : Promise < void > {
242+ if ( ! this . lastCache || ! this . #lastShowStyleBaseId) return
243+ return this . updateTriggers ( this . lastCache , this . #lastShowStyleBaseId)
244+ }
245+
246+ async updatePieceInstances ( cache : PieceInstancesContentCache , showStyleBaseId : ShowStyleBaseId ) : Promise < void > {
247+ const shouldUpdateTriggers = this . tagsService . updatePieceInstances ( cache , showStyleBaseId )
248+ if ( shouldUpdateTriggers ) {
249+ await this . updateTriggersFromLastCache ( )
250+ }
251+ }
252+
227253 async clearTriggers ( ) : Promise < void > {
228254 const studioId = this . studioId
229255 const showStyleBaseId = this . #lastShowStyleBaseId
0 commit comments