@@ -23,7 +23,7 @@ import { PieceInstance, PieceInstancePiece } from '../dataModel/PieceInstance.js
2323import { Rundown } from '../dataModel/Rundown.js'
2424import { DBRundownPlaylist , QuickLoopMarkerType } from '../dataModel/RundownPlaylist.js'
2525import { DBSegment , SegmentExtended , SegmentOrphanedReason } from '../dataModel/Segment.js'
26- import { assertNever , literal , groupByToMap } from '../lib.js'
26+ import { assertNever , literal , groupByToMap , Complete } from '../lib.js'
2727import { FindOneOptions , FindOptions , MongoQuery , mongoWhereFilter } from '../mongo.js'
2828import { protectString } from '../protectedString.js'
2929import {
@@ -37,16 +37,21 @@ import {
3737 buildPiecesStartingInThisPartQuery ,
3838 getPieceInstancesForPart ,
3939} from './infinites.js'
40- import { DBShowStyleBase , IOutputLayerExtended , ISourceLayerExtended } from '../dataModel/ShowStyleBase.js'
40+ import {
41+ DBShowStyleBase ,
42+ IOutputLayerExtended ,
43+ ISourceLayerExtended ,
44+ UIShowStyleBase ,
45+ } from '../dataModel/ShowStyleBase.js'
4146import { applyAndValidateOverrides } from '../settings/objectWithOverrides.js'
4247import { PartInstance , PartInstanceLimited } from '../dataModel/PartInstance.js'
4348import { UIStudio } from '../dataModel/Studio.js'
4449import { ReadonlyDeep } from 'type-fest'
4550import { TimeDuration } from '@sofie-automation/shared-lib/dist/lib/lib'
4651
4752type SegmentsFindOne = (
48- selector ? : SegmentId | MongoQuery < DBSegment > ,
49- options ? : FindOneOptions < DBSegment >
53+ selector : SegmentId | MongoQuery < DBSegment > ,
54+ options : FindOneOptions < DBSegment >
5055) => DBSegment | undefined
5156type PieceInstancesFind = (
5257 selector ?: PieceInstanceId | MongoQuery < PieceInstance > ,
@@ -126,7 +131,7 @@ export function getPieceStatusClassName(status: PieceStatusCode | undefined): st
126131 * @return {* } {({
127132 */
128133export function getResolvedSegment (
129- showStyleBase : DBShowStyleBase ,
134+ showStyleBaseProp : DBShowStyleBase | UIShowStyleBase ,
130135 studio : UIStudio | undefined ,
131136 playlist : DBRundownPlaylist ,
132137 rundown : Pick < Rundown , '_id' | 'showStyleBaseId' > ,
@@ -137,16 +142,16 @@ export function getResolvedSegment(
137142 orderedAllPartIds : PartId [ ] ,
138143 currentPartInstance : PartInstance | undefined ,
139144 nextPartInstance : PartInstance | undefined ,
140- pieceInstanceSimulation : boolean = false ,
141- includeDisabledPieces : boolean = false ,
142145 // TODO: Add new parameters to JSDOC
143146 segmentsFindOne : SegmentsFindOne ,
144147 getSegmentsAndPartsSync : GetSegmentsAndPartsSync ,
145148 getActivePartInstances : GetActivePartInstances ,
146149 piecesFind : PiecesFind ,
147150 pieceInstancesFind : PieceInstancesFind ,
148151 getCurrentTime : GetCurrentTime = ( ) => Date . now ( ) ,
149- showHiddenSourceLayers : boolean ,
152+ pieceInstanceSimulation : boolean = false ,
153+ includeDisabledPieces : boolean = false ,
154+ showHiddenSourceLayers : boolean = false ,
150155 defaultDisplayDuration : number = 0 // I think 0 here is reasonable, and should be overridden by an actual value when used in a UI.
151156) : {
152157 /** A Segment with some additional information */
@@ -177,8 +182,9 @@ export function getResolvedSegment(
177182 let hasAlreadyPlayed = false
178183 let hasRemoteItems = false
179184 let hasGuestItems = false
180- const resolvedOutputLayers = applyAndValidateOverrides ( showStyleBase . outputLayersWithOverrides ) . obj
181- const resolvedSourceLayers = applyAndValidateOverrides ( showStyleBase . sourceLayersWithOverrides ) . obj
185+ const showStyleBase = isUIShowStyleBase ( showStyleBaseProp )
186+ ? showStyleBaseProp
187+ : convertToUIShowStyleBase ( showStyleBaseProp )
182188
183189 let autoNextPart = false
184190
@@ -220,7 +226,7 @@ export function getResolvedSegment(
220226 // create local deep copies of the studio outputLayers and sourceLayers so that we can store
221227 // pieces present on those layers inside and also figure out which layers are used when inside the rundown
222228 const outputLayers : Record < string , IOutputLayerExtended > = { }
223- for ( const [ id , layer ] of Object . entries < IOutputLayer | undefined > ( resolvedOutputLayers ) ) {
229+ for ( const [ id , layer ] of Object . entries < IOutputLayer | undefined > ( showStyleBase . outputLayers ) ) {
224230 if ( layer ) {
225231 outputLayers [ id ] = {
226232 ...layer ,
@@ -230,7 +236,7 @@ export function getResolvedSegment(
230236 }
231237 }
232238 const sourceLayers : Record < string , ISourceLayerExtended > = { }
233- for ( const [ id , layer ] of Object . entries < ISourceLayer | undefined > ( resolvedSourceLayers ) ) {
239+ for ( const [ id , layer ] of Object . entries < ISourceLayer | undefined > ( showStyleBase . sourceLayers ) ) {
234240 if ( layer ) {
235241 sourceLayers [ id ] = {
236242 ...layer ,
@@ -364,7 +370,7 @@ export function getResolvedSegment(
364370
365371 const partTimes = createPartCurrentTimes ( getCurrentTime ( ) , partE . instance . timings ?. plannedStartedPlayback )
366372 const preprocessedPieces = processAndPrunePieceInstanceTimings (
367- resolvedSourceLayers ,
373+ showStyleBase . sourceLayers ,
368374 rawPieceInstances ,
369375 partTimes ,
370376 includeDisabledPieces
@@ -927,3 +933,27 @@ export function wrapPartToTemporaryInstance(
927933 part : part as DBPart ,
928934 }
929935}
936+
937+ export function convertToUIShowStyleBase ( showStyleBase : DBShowStyleBase ) : UIShowStyleBase {
938+ return literal < Complete < UIShowStyleBase > > ( {
939+ _id : showStyleBase . _id ,
940+ name : showStyleBase . name ,
941+ hotkeyLegend : showStyleBase . hotkeyLegend ,
942+ sourceLayers : applyAndValidateOverrides ( showStyleBase . sourceLayersWithOverrides ) . obj ,
943+ outputLayers : applyAndValidateOverrides ( showStyleBase . outputLayersWithOverrides ) . obj ,
944+ abChannelDisplay : showStyleBase . abChannelDisplay ,
945+ } )
946+ }
947+
948+ export function isUIShowStyleBase ( value : unknown ) : value is UIShowStyleBase {
949+ if ( ! value || typeof value !== 'object' ) return false
950+
951+ const v = value as Partial < UIShowStyleBase >
952+
953+ return (
954+ typeof v . sourceLayers === 'object' &&
955+ v . sourceLayers !== null &&
956+ typeof v . outputLayers === 'object' &&
957+ v . outputLayers !== null
958+ )
959+ }
0 commit comments