@@ -10,10 +10,18 @@ import { getPieceControlObjectId } from './ids'
10
10
/**
11
11
* Get the `enable: { start: ?? }` for the new piece in terms that can be used as an `end` for another object
12
12
*/
13
- function getPieceStartTime ( newPieceStart : number | 'now' , newPiece : PieceInstance ) : number | string {
13
+ function getPieceStartTimeAsReference ( newPieceStart : number | 'now' , newPiece : PieceInstance ) : number | string {
14
14
return typeof newPieceStart === 'number' ? newPieceStart : `#${ getPieceControlObjectId ( newPiece ) } .start`
15
15
}
16
16
17
+ function getPieceStartTimeWithinPart ( p : PieceInstance ) : 'now' | number {
18
+ if ( p . piece . enable . start === 'now' || ! p . dynamicallyInserted ) {
19
+ return p . piece . enable . start
20
+ } else {
21
+ return p . piece . enable . start + ( p . piece . prerollDuration ?? 0 )
22
+ }
23
+ }
24
+
17
25
function isClear ( piece ?: PieceInstance ) : boolean {
18
26
return ! ! piece ?. piece . virtual
19
27
}
@@ -85,7 +93,7 @@ export function processAndPrunePieceInstanceTimings(
85
93
for ( const pieces of groupedPieces . values ( ) ) {
86
94
// Group and sort the pieces so that we can step through each point in time
87
95
const piecesByStart : Array < [ number | 'now' , PieceInstance [ ] ] > = _ . sortBy (
88
- Array . from ( groupByToMapFunc ( pieces , ( p ) => p . piece . enable . start ) . entries ( ) ) . map ( ( [ k , v ] ) =>
96
+ Array . from ( groupByToMapFunc ( pieces , ( p ) => getPieceStartTimeWithinPart ( p ) ) . entries ( ) ) . map ( ( [ k , v ] ) =>
89
97
literal < [ number | 'now' , PieceInstance [ ] ] > ( [ k === 'now' ? 'now' : Number ( k ) , v ] )
90
98
) ,
91
99
( [ k ] ) => ( k === 'now' ? nowInPart : k )
@@ -120,7 +128,7 @@ function updateWithNewPieces(
120
128
if ( newPiece ) {
121
129
const activePiece = activePieces [ key ]
122
130
if ( activePiece ) {
123
- activePiece . resolvedEndCap = getPieceStartTime ( newPiecesStart , newPiece )
131
+ activePiece . resolvedEndCap = getPieceStartTimeAsReference ( newPiecesStart , newPiece )
124
132
}
125
133
// track the new piece
126
134
activePieces [ key ] = newPiece
@@ -145,7 +153,7 @@ function updateWithNewPieces(
145
153
( newPiecesStart !== 0 || isCandidateBetterToBeContinued ( activePieces . other , newPiece ) )
146
154
) {
147
155
// These modes should stop the 'other' when they start if not hidden behind a higher priority onEnd
148
- activePieces . other . resolvedEndCap = getPieceStartTime ( newPiecesStart , newPiece )
156
+ activePieces . other . resolvedEndCap = getPieceStartTimeAsReference ( newPiecesStart , newPiece )
149
157
activePieces . other = undefined
150
158
}
151
159
}
0 commit comments