@@ -25,16 +25,20 @@ import { protectString } from '../../lib/tempLib'
25
25
import { StudioActionManager , StudioActionManagers } from './StudioActionManagers'
26
26
import { DeviceTriggerMountedActionAdlibsPreview , DeviceTriggerMountedActions } from './observer'
27
27
import { ContentCache } from './reactiveContentCache'
28
+ import { ContentCache as PieceInstancesContentCache } from './reactiveContentCacheForPieceInstances'
28
29
import { logger } from '../../logging'
29
30
import { SomeAction , SomeBlueprintTrigger } from '@sofie-automation/blueprints-integration'
30
31
import { DeviceActions } from '@sofie-automation/shared-lib/dist/core/model/ShowStyle'
31
32
import { DummyReactiveVar } from '@sofie-automation/meteor-lib/dist/triggers/reactive-var'
32
33
import { MeteorTriggersContext } from './triggersContext'
34
+ import { TagsService } from './TagsService'
33
35
34
36
export class StudioDeviceTriggerManager {
35
37
#lastShowStyleBaseId: ShowStyleBaseId | null = null
36
38
37
- constructor ( public studioId : StudioId ) {
39
+ lastCache : ContentCache | undefined
40
+
41
+ constructor ( public studioId : StudioId , protected tagsService : TagsService ) {
38
42
if ( StudioActionManagers . get ( studioId ) ) {
39
43
logger . error ( `A StudioActionManager for "${ studioId } " already exists` )
40
44
return
@@ -45,6 +49,7 @@ export class StudioDeviceTriggerManager {
45
49
46
50
async updateTriggers ( cache : ContentCache , showStyleBaseId : ShowStyleBaseId ) : Promise < void > {
47
51
const studioId = this . studioId
52
+ this . lastCache = cache
48
53
this . #lastShowStyleBaseId = showStyleBaseId
49
54
50
55
const [ showStyleBase , rundownPlaylist ] = await Promise . all ( [
@@ -79,6 +84,8 @@ export class StudioDeviceTriggerManager {
79
84
const upsertedDeviceTriggerMountedActionIds : DeviceTriggerMountedActionId [ ] = [ ]
80
85
const touchedActionIds : DeviceActionId [ ] = [ ]
81
86
87
+ this . tagsService . clearObservedTags ( )
88
+
82
89
for ( const rawTriggeredAction of allTriggeredActions ) {
83
90
const triggeredAction = convertDocument ( rawTriggeredAction )
84
91
@@ -163,6 +170,8 @@ export class StudioDeviceTriggerManager {
163
170
sourceLayerType : undefined ,
164
171
sourceLayerName : undefined ,
165
172
styleClassNames : triggeredAction . styleClassNames ,
173
+ isActive : undefined ,
174
+ isNext : undefined ,
166
175
} ) ,
167
176
} )
168
177
} else {
@@ -174,6 +183,9 @@ export class StudioDeviceTriggerManager {
174
183
)
175
184
176
185
addedPreviewIds . push ( adLibPreviewId )
186
+
187
+ this . tagsService . observeTallyTags ( adLib )
188
+ const { isActive, isNext } = this . tagsService . getTallyStateFromTags ( adLib )
177
189
return DeviceTriggerMountedActionAdlibsPreview . upsertAsync ( adLibPreviewId , {
178
190
$set : literal < PreviewWrappedAdLib > ( {
179
191
...adLib ,
@@ -192,6 +204,8 @@ export class StudioDeviceTriggerManager {
192
204
}
193
205
: undefined ,
194
206
styleClassNames : triggeredAction . styleClassNames ,
207
+ isActive,
208
+ isNext,
195
209
} ) ,
196
210
} )
197
211
} )
@@ -224,6 +238,18 @@ export class StudioDeviceTriggerManager {
224
238
actionManager . deleteActionsOtherThan ( touchedActionIds )
225
239
}
226
240
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
+
227
253
async clearTriggers ( ) : Promise < void > {
228
254
const studioId = this . studioId
229
255
const showStyleBaseId = this . #lastShowStyleBaseId
0 commit comments