add relevantBlock function (#1100)

* feat: current block

* pass full rundown to functions and use filter utils
This commit is contained in:
Alex Christoffer Rasmussen
2024-07-23 12:22:47 +02:00
committed by GitHub
parent 20838c038a
commit 158ef05ff0
18 changed files with 246 additions and 49 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { OntimeEvent } from 'ontime-types';
import { OntimeRundown } from 'ontime-types';
import * as runtimeState from '../stores/runtimeState.js';
import type { UpdateResult } from '../stores/runtimeState.js';
@@ -106,7 +106,7 @@ export class TimerService {
* Loads roll information into timer service
* @param {OntimeEvent[]} rundown -- list of events to run
*/
roll(rundown: OntimeEvent[]) {
roll(rundown: OntimeRundown) {
runtimeState.roll(rundown);
}
@@ -25,13 +25,14 @@ import { eventStore } from '../../stores/EventStore.js';
type PatchWithId = (Partial<OntimeEvent> | Partial<OntimeBlock> | Partial<OntimeDelay>) & { id: string };
type CompleteEntry<T> = T extends Partial<OntimeEvent>
? OntimeEvent
: T extends Partial<OntimeDelay>
? OntimeDelay
: T extends Partial<OntimeBlock>
? OntimeBlock
: never;
type CompleteEntry<T> =
T extends Partial<OntimeEvent>
? OntimeEvent
: T extends Partial<OntimeDelay>
? OntimeDelay
: T extends Partial<OntimeBlock>
? OntimeBlock
: never;
function generateEvent<T extends Partial<OntimeEvent> | Partial<OntimeDelay> | Partial<OntimeBlock>>(
eventData: T,
@@ -240,7 +241,7 @@ function notifyChanges(options: { timer?: boolean | string[]; external?: boolean
// notify timer service of changed events
// timer can be true or an array of changed IDs
const affected = Array.isArray(options.timer) ? options.timer : undefined;
runtimeService.maybeUpdate(playableEvents, affected);
runtimeService.maybeUpdate(affected);
}
}
@@ -9,7 +9,7 @@ import {
TimerLifeCycle,
TimerPhase,
} from 'ontime-types';
import { millisToString, validatePlayback } from 'ontime-utils';
import { filterPlayable, millisToString, validatePlayback } from 'ontime-utils';
import { deepEqual } from 'fast-equals';
@@ -28,6 +28,7 @@ import {
getNextEventWithCue,
getEventWithId,
getPlayableEvents,
getRundown,
} from '../rundown-service/rundownUtils.js';
import { skippedOutOfEvent } from '../timerUtils.js';
import { integrationService } from '../integration-service/IntegrationService.js';
@@ -95,7 +96,7 @@ class RuntimeService {
}
// we dont call this.roll because we need to bypass the checks
const rundown = getPlayableEvents();
const rundown = getRundown();
// TODO: by not calling roll, we dont get the events
this.eventTimer.roll(rundown);
}
@@ -217,7 +218,7 @@ class RuntimeService {
* Called when the underlying data has changed,
* we check if the change affects the runtime
*/
maybeUpdate(playableEvents: OntimeEvent[], affectedIds?: string[]) {
maybeUpdate(affectedIds?: string[]) {
const state = runtimeState.getState();
const hasLoadedElements = state.eventNow !== null || state.eventNext !== null;
if (!hasLoadedElements) {
@@ -245,7 +246,8 @@ class RuntimeService {
if (onlyChangedNow) {
runtimeState.reload(eventNow);
} else {
runtimeState.reloadAll(eventNow, playableEvents);
const rundown = getRundown();
runtimeState.reloadAll(eventNow, rundown);
}
return;
}
@@ -253,7 +255,8 @@ class RuntimeService {
// Maybe the event will become the next
isNext = this.isNewNext();
if (isNext) {
runtimeState.loadNext(playableEvents);
const rundown = getRundown();
runtimeState.loadNext(rundown);
}
}
@@ -269,8 +272,8 @@ class RuntimeService {
return false;
}
const timedEvents = getPlayableEvents();
const success = runtimeState.load(event, timedEvents);
const rundown = getRundown();
const success = runtimeState.load(event, rundown);
if (success) {
logger.info(LogOrigin.Playback, `Loaded event with ID ${event.id}`);
@@ -513,13 +516,14 @@ class RuntimeService {
return;
}
const playableEvents = getPlayableEvents();
const rundown = getRundown();
const playableEvents = filterPlayable(rundown);
if (playableEvents.length === 0) {
logger.warning(LogOrigin.Server, 'Roll: no events found');
return;
}
this.eventTimer.roll(playableEvents);
this.eventTimer.roll(rundown);
const state = runtimeState.getState();
const newState = state.timer.playback;
@@ -543,14 +547,14 @@ class RuntimeService {
}
// the db would have to change for the event not to exist
// we do not kow the reason for the crash, so we check anyway
// we do not know the reason for the crash, so we check anyway
const event = getEventWithId(selectedEventId);
if (!event || !isOntimeEvent(event)) {
return;
}
const timedEvents = getPlayableEvents();
runtimeState.resume(restorePoint, event, timedEvents);
const rundown = getRundown();
runtimeState.resume(restorePoint, event, rundown);
logger.info(LogOrigin.Playback, 'Resuming playback');
}
@@ -620,6 +624,11 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
updateEventIfChanged('eventNext', state);
updateEventIfChanged('publicEventNext', state);
if (!deepEqual(RuntimeService?.previousState.currentBlock, state.currentBlock)) {
eventStore.set('currentBlock', state.currentBlock);
RuntimeService.previousState.currentBlock = { ...state.currentBlock };
}
if (shouldUpdateClock) {
RuntimeService.previousClockUpdate = state.clock;
eventStore.set('clock', state.clock);
+8 -4
View File
@@ -127,10 +127,14 @@ type RollTimers = {
/**
* Finds loading information given a current rundown and time
* @param {OntimeEvent[]} rundown - List of playable events
* @param {OntimeEvent[]} playableEvents - List of playable events
* @param {number} timeNow - time now in ms
*/
export const getRollTimers = (rundown: OntimeEvent[], timeNow: number, currentIndex?: number | null): RollTimers => {
export const getRollTimers = (
playableEvents: OntimeEvent[],
timeNow: number,
currentIndex?: number | null,
): RollTimers => {
let nowIndex: MaybeNumber = null; // index of event now
let nowId: MaybeString = null; // id of event now
let publicIndex: MaybeNumber = null; // index of public event now
@@ -140,8 +144,8 @@ export const getRollTimers = (rundown: OntimeEvent[], timeNow: number, currentIn
let publicTimeToNext: MaybeNumber = null; // counter: time for next public event
const hasLoaded = currentIndex !== null;
const canFilter = hasLoaded && currentIndex === rundown.length - 1;
const filteredRundown = canFilter ? rundown.slice(currentIndex) : rundown;
const canFilter = hasLoaded && currentIndex === playableEvents.length - 1;
const filteredRundown = canFilter ? playableEvents.slice(currentIndex) : playableEvents;
const lastEvent = filteredRundown.at(-1);
const lastNormalEnd = normaliseEndTime(lastEvent.timeStart, lastEvent.timeEnd);