@@ -95,7 +95,15 @@ export class PartAndPieceInstanceActionService {
95
95
this . showStyleCompound = showStyle
96
96
}
97
97
98
- private _getPartInstance ( part : 'current' | 'next' ) : PlayoutPartInstanceModel | null {
98
+ #trackStateChange( part : 'current' | 'next' , change : ActionPartChange ) : void {
99
+ if ( part === 'current' ) {
100
+ this . currentPartState = Math . max ( this . currentPartState , change )
101
+ } else {
102
+ this . nextPartState = Math . max ( this . nextPartState , change )
103
+ }
104
+ }
105
+
106
+ #getPartInstance( part : 'current' | 'next' ) : PlayoutPartInstanceModel | null {
99
107
switch ( part ) {
100
108
case 'current' :
101
109
return this . _playoutModel . currentPartInstance
@@ -109,16 +117,16 @@ export class PartAndPieceInstanceActionService {
109
117
}
110
118
111
119
async getPartInstance ( part : 'current' | 'next' ) : Promise < IBlueprintPartInstance | undefined > {
112
- const partInstance = this . _getPartInstance ( part )
120
+ const partInstance = this . #getPartInstance ( part )
113
121
114
122
return partInstance ? convertPartInstanceToBlueprints ( partInstance . partInstance ) : undefined
115
123
}
116
124
async getPieceInstances ( part : 'current' | 'next' ) : Promise < IBlueprintPieceInstance [ ] > {
117
- const partInstance = this . _getPartInstance ( part )
125
+ const partInstance = this . #getPartInstance ( part )
118
126
return partInstance ?. pieceInstances ?. map ( ( p ) => convertPieceInstanceToBlueprints ( p . pieceInstance ) ) ?? [ ]
119
127
}
120
128
async getResolvedPieceInstances ( part : 'current' | 'next' ) : Promise < IBlueprintResolvedPieceInstance [ ] > {
121
- const partInstance = this . _getPartInstance ( part )
129
+ const partInstance = this . #getPartInstance ( part )
122
130
if ( ! partInstance ) {
123
131
return [ ]
124
132
}
@@ -244,7 +252,7 @@ export class PartAndPieceInstanceActionService {
244
252
}
245
253
246
254
async insertPiece ( part : 'current' | 'next' , rawPiece : IBlueprintPiece ) : Promise < IBlueprintPieceInstance > {
247
- const partInstance = this . _getPartInstance ( part )
255
+ const partInstance = this . #getPartInstance ( part )
248
256
if ( ! partInstance ) {
249
257
throw new Error ( 'Cannot insert piece when no active part' )
250
258
}
@@ -270,11 +278,7 @@ export class PartAndPieceInstanceActionService {
270
278
// Do the work
271
279
const newPieceInstance = partInstance . insertAdlibbedPiece ( piece , undefined )
272
280
273
- if ( part === 'current' ) {
274
- this . currentPartState = Math . max ( this . currentPartState , ActionPartChange . SAFE_CHANGE )
275
- } else {
276
- this . nextPartState = Math . max ( this . nextPartState , ActionPartChange . SAFE_CHANGE )
277
- }
281
+ this . #trackStateChange( part , ActionPartChange . SAFE_CHANGE )
278
282
279
283
return convertPieceInstanceToBlueprints ( newPieceInstance . pieceInstance )
280
284
}
@@ -330,8 +334,8 @@ export class PartAndPieceInstanceActionService {
330
334
331
335
// setupPieceInstanceInfiniteProperties(pieceInstance)
332
336
333
- this . nextPartState = Math . max ( this . nextPartState , updatesNextPart )
334
- this . currentPartState = Math . max ( this . currentPartState , updatesCurrentPart )
337
+ this . #trackStateChange ( 'next' , updatesNextPart )
338
+ this . #trackStateChange ( 'current' , updatesCurrentPart )
335
339
336
340
return convertPieceInstanceToBlueprints ( pieceInstance . pieceInstance )
337
341
}
@@ -340,7 +344,7 @@ export class PartAndPieceInstanceActionService {
340
344
part : 'current' | 'next' ,
341
345
props : Partial < IBlueprintMutatablePart >
342
346
) : Promise < IBlueprintPartInstance > {
343
- const partInstance = this . _getPartInstance ( part )
347
+ const partInstance = this . #getPartInstance ( part )
344
348
if ( ! partInstance ) {
345
349
throw new Error ( 'PartInstance could not be found' )
346
350
}
@@ -351,14 +355,7 @@ export class PartAndPieceInstanceActionService {
351
355
throw new Error ( 'Some valid properties must be defined' )
352
356
}
353
357
354
- this . nextPartState = Math . max (
355
- this . nextPartState ,
356
- part === 'next' ? ActionPartChange . SAFE_CHANGE : ActionPartChange . NONE
357
- )
358
- this . currentPartState = Math . max (
359
- this . currentPartState ,
360
- part === 'current' ? ActionPartChange . SAFE_CHANGE : ActionPartChange . NONE
361
- )
358
+ this . #trackStateChange( part , ActionPartChange . SAFE_CHANGE )
362
359
363
360
return convertPartInstanceToBlueprints ( partInstance . partInstance )
364
361
}
@@ -451,7 +448,7 @@ export class PartAndPieceInstanceActionService {
451
448
}
452
449
453
450
async removePieceInstances ( part : 'current' | 'next' , pieceInstanceIds : string [ ] ) : Promise < string [ ] > {
454
- const partInstance = this . _getPartInstance ( part )
451
+ const partInstance = this . #getPartInstance ( part )
455
452
if ( ! partInstance ) {
456
453
throw new Error ( 'Cannot remove pieceInstances when no selected partInstance' )
457
454
}
@@ -466,7 +463,7 @@ export class PartAndPieceInstanceActionService {
466
463
}
467
464
}
468
465
469
- this . nextPartState = Math . max ( this . nextPartState , ActionPartChange . SAFE_CHANGE )
466
+ this . #trackStateChange ( part , ActionPartChange . SAFE_CHANGE )
470
467
471
468
return unprotectStringArray ( removedPieceInstanceIds )
472
469
}
@@ -505,7 +502,7 @@ export class PartAndPieceInstanceActionService {
505
502
)
506
503
507
504
if ( stoppedIds . length > 0 ) {
508
- this . currentPartState = Math . max ( this . currentPartState , ActionPartChange . SAFE_CHANGE )
505
+ this . #trackStateChange ( 'current' , ActionPartChange . SAFE_CHANGE )
509
506
}
510
507
511
508
return unprotectStringArray ( stoppedIds )
0 commit comments