mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 06:29:07 +00:00
refactor: use runtime metadate in runtimeState (#1653)
* change load to use metadata * update roll to use metadata * remove filterTimedEvents * add comment * atempth to refactor rollUtils * refactor util functions
This commit is contained in:
committed by
GitHub
parent
e090bde8bb
commit
14a99ce27b
@@ -1,22 +1,25 @@
|
||||
import { dayInMs, getFirstEvent } from 'ontime-utils';
|
||||
import { OntimeEvent, MaybeNumber, PlayableEvent, isPlayableEvent } from 'ontime-types';
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
import { MaybeNumber, PlayableEvent, Rundown } from 'ontime-types';
|
||||
|
||||
import { normaliseEndTime } from './timerUtils.js';
|
||||
import { RundownMetadata } from '../api-data/rundown/rundown.types.js';
|
||||
import { getTimedIndexFromPlayableIndex } from '../api-data/rundown/rundown.utils.js';
|
||||
|
||||
/**
|
||||
* Finds current event in a rolling rundown
|
||||
*/
|
||||
export function loadRoll(
|
||||
timedEvents: OntimeEvent[],
|
||||
rundown: Rundown,
|
||||
metadata: RundownMetadata,
|
||||
timeNow: number,
|
||||
): {
|
||||
event: PlayableEvent | null;
|
||||
index: MaybeNumber;
|
||||
isPending?: boolean;
|
||||
} {
|
||||
const { firstEvent } = getFirstEvent(timedEvents);
|
||||
const firstEventId = metadata.playableEventOrder[0];
|
||||
|
||||
if (!firstEvent) {
|
||||
if (!firstEventId) {
|
||||
return { event: null, index: null };
|
||||
}
|
||||
|
||||
@@ -24,13 +27,8 @@ export function loadRoll(
|
||||
// account for number of times we went over midnight
|
||||
let daySpan = 0;
|
||||
|
||||
for (let i = 0; i < timedEvents.length; i++) {
|
||||
const event = timedEvents[i];
|
||||
|
||||
if (!isPlayableEvent(event)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let i = 0; i < metadata.playableEventOrder.length; i++) {
|
||||
const event = rundown.entries[metadata.playableEventOrder[i]] as PlayableEvent;
|
||||
if (event.duration === 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -62,16 +60,17 @@ export function loadRoll(
|
||||
const isFromDayBefore = normalEnd > dayInMs && timeNow < event.timeEnd;
|
||||
const hasStarted = isFromDayBefore || timeNow >= event.timeStart;
|
||||
if (hasStarted) {
|
||||
return { event, index: i };
|
||||
return { event, index: getTimedIndexFromPlayableIndex(metadata, i) };
|
||||
}
|
||||
|
||||
// 3. event will run in the future
|
||||
// we set the isPending flag to indicate that the event is currently playing
|
||||
return { event, index: i, isPending: true };
|
||||
return { event, index: getTimedIndexFromPlayableIndex(metadata, i), isPending: true };
|
||||
}
|
||||
|
||||
// in case we were unable to find anything, we load the first event
|
||||
return { event: firstEvent, index: 0, isPending: true };
|
||||
console.log('returning first event');
|
||||
return { event: rundown.entries[firstEventId] as PlayableEvent, index: 0, isPending: true };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user