Skip to content

Commit

Permalink
feat: allow adlib-actions to remove pieces from the current partInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Feb 3, 2025
1 parent 902e7ff commit 33514b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ export class PartAndPieceInstanceActionService {
this.showStyleCompound = showStyle
}

private _getPartInstance(part: 'current' | 'next'): PlayoutPartInstanceModel | null {
#trackStateChange(part: 'current' | 'next', change: ActionPartChange): void {
if (part === 'current') {
this.currentPartState = Math.max(this.currentPartState, change)
} else {
this.nextPartState = Math.max(this.nextPartState, change)
}
}

#getPartInstance(part: 'current' | 'next'): PlayoutPartInstanceModel | null {
switch (part) {
case 'current':
return this._playoutModel.currentPartInstance
Expand All @@ -109,16 +117,16 @@ export class PartAndPieceInstanceActionService {
}

async getPartInstance(part: 'current' | 'next'): Promise<IBlueprintPartInstance | undefined> {
const partInstance = this._getPartInstance(part)
const partInstance = this.#getPartInstance(part)

return partInstance ? convertPartInstanceToBlueprints(partInstance.partInstance) : undefined
}
async getPieceInstances(part: 'current' | 'next'): Promise<IBlueprintPieceInstance[]> {
const partInstance = this._getPartInstance(part)
const partInstance = this.#getPartInstance(part)
return partInstance?.pieceInstances?.map((p) => convertPieceInstanceToBlueprints(p.pieceInstance)) ?? []
}
async getResolvedPieceInstances(part: 'current' | 'next'): Promise<IBlueprintResolvedPieceInstance[]> {
const partInstance = this._getPartInstance(part)
const partInstance = this.#getPartInstance(part)
if (!partInstance) {
return []
}
Expand Down Expand Up @@ -244,7 +252,7 @@ export class PartAndPieceInstanceActionService {
}

async insertPiece(part: 'current' | 'next', rawPiece: IBlueprintPiece): Promise<IBlueprintPieceInstance> {
const partInstance = this._getPartInstance(part)
const partInstance = this.#getPartInstance(part)
if (!partInstance) {
throw new Error('Cannot insert piece when no active part')
}
Expand All @@ -270,11 +278,7 @@ export class PartAndPieceInstanceActionService {
// Do the work
const newPieceInstance = partInstance.insertAdlibbedPiece(piece, undefined)

if (part === 'current') {
this.currentPartState = Math.max(this.currentPartState, ActionPartChange.SAFE_CHANGE)
} else {
this.nextPartState = Math.max(this.nextPartState, ActionPartChange.SAFE_CHANGE)
}
this.#trackStateChange(part, ActionPartChange.SAFE_CHANGE)

return convertPieceInstanceToBlueprints(newPieceInstance.pieceInstance)
}
Expand Down Expand Up @@ -330,8 +334,8 @@ export class PartAndPieceInstanceActionService {

// setupPieceInstanceInfiniteProperties(pieceInstance)

this.nextPartState = Math.max(this.nextPartState, updatesNextPart)
this.currentPartState = Math.max(this.currentPartState, updatesCurrentPart)
this.#trackStateChange('next', updatesNextPart)
this.#trackStateChange('current', updatesCurrentPart)

return convertPieceInstanceToBlueprints(pieceInstance.pieceInstance)
}
Expand All @@ -340,7 +344,7 @@ export class PartAndPieceInstanceActionService {
part: 'current' | 'next',
props: Partial<IBlueprintMutatablePart>
): Promise<IBlueprintPartInstance> {
const partInstance = this._getPartInstance(part)
const partInstance = this.#getPartInstance(part)
if (!partInstance) {
throw new Error('PartInstance could not be found')
}
Expand All @@ -351,14 +355,7 @@ export class PartAndPieceInstanceActionService {
throw new Error('Some valid properties must be defined')
}

this.nextPartState = Math.max(
this.nextPartState,
part === 'next' ? ActionPartChange.SAFE_CHANGE : ActionPartChange.NONE
)
this.currentPartState = Math.max(
this.currentPartState,
part === 'current' ? ActionPartChange.SAFE_CHANGE : ActionPartChange.NONE
)
this.#trackStateChange(part, ActionPartChange.SAFE_CHANGE)

return convertPartInstanceToBlueprints(partInstance.partInstance)
}
Expand Down Expand Up @@ -451,7 +448,7 @@ export class PartAndPieceInstanceActionService {
}

async removePieceInstances(part: 'current' | 'next', pieceInstanceIds: string[]): Promise<string[]> {
const partInstance = this._getPartInstance(part)
const partInstance = this.#getPartInstance(part)
if (!partInstance) {
throw new Error('Cannot remove pieceInstances when no selected partInstance')
}
Expand All @@ -466,7 +463,7 @@ export class PartAndPieceInstanceActionService {
}
}

this.nextPartState = Math.max(this.nextPartState, ActionPartChange.SAFE_CHANGE)
this.#trackStateChange(part, ActionPartChange.SAFE_CHANGE)

return unprotectStringArray(removedPieceInstanceIds)
}
Expand Down Expand Up @@ -505,7 +502,7 @@ export class PartAndPieceInstanceActionService {
)

if (stoppedIds.length > 0) {
this.currentPartState = Math.max(this.currentPartState, ActionPartChange.SAFE_CHANGE)
this.#trackStateChange('current', ActionPartChange.SAFE_CHANGE)
}

return unprotectStringArray(stoppedIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ describe('Test blueprint api context', () => {

// Ensure it was all removed
expect(playoutModel.findPieceInstance(targetPieceInstance.pieceInstance._id)).toBeFalsy()
expect(service.nextPartState).toEqual(ActionPartChange.SAFE_CHANGE)
expect(service.currentPartState).toEqual(ActionPartChange.SAFE_CHANGE)
})
})
})
Expand Down

0 comments on commit 33514b1

Please sign in to comment.