mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
Refactor: split runtime state (#1725)
* refactor: runtime types * refactor: runtimeState functions to use the split type * refactor: RuntimeService to use the new split data * refactor: use the split data in the UI * update comments * refactor: rename runtime to offset * fix utils test
This commit is contained in:
committed by
Carlos Valente
parent
ed93cf313a
commit
048a9c96ea
@@ -112,23 +112,23 @@ export function skippedOutOfEvent(state: RuntimeState, previousTime: number, ski
|
||||
* Positive offset is over time / behind schedule
|
||||
* Negative offset is under time / ahead of schedule
|
||||
*/
|
||||
export function getRuntimeOffset(state: RuntimeState): { offsetAbs: number; offsetRel: number } {
|
||||
export function getRuntimeOffset(state: RuntimeState): { absolute: number; relative: number } {
|
||||
const { eventNow, clock } = state;
|
||||
const { addedTime, current, startedAt } = state.timer;
|
||||
// nothing to calculate if there are no loaded events or if we havent started
|
||||
if (eventNow === null || startedAt === null) {
|
||||
return { offsetAbs: 0, offsetRel: 0 };
|
||||
return { absolute: 0, relative: 0 };
|
||||
}
|
||||
|
||||
const { countToEnd, timeStart } = eventNow;
|
||||
const { plannedStart, actualStart } = state.runtime;
|
||||
const { plannedStart, actualStart } = state.rundown;
|
||||
|
||||
// eslint-disable-next-line no-unused-labels -- dev code path
|
||||
DEV: {
|
||||
// we know current exists as long as eventNow exists
|
||||
if (current === null) throw new Error('timerUtils.getRuntimeOffset: state.timer.current must be set');
|
||||
if (plannedStart === null) throw new Error('timerUtils.getRuntimeOffset: state.runtime.plannedStart must be set');
|
||||
if (actualStart === null) throw new Error('timerUtils.getRuntimeOffset: state.runtime.actualStart must be set');
|
||||
if (plannedStart === null) throw new Error('timerUtils.getRuntimeOffset: state.rundown.plannedStart must be set');
|
||||
if (actualStart === null) throw new Error('timerUtils.getRuntimeOffset: state.rundown.plannedStart must be set');
|
||||
}
|
||||
|
||||
// difference between planned event start and actual event start (will be positive if we stared behind )
|
||||
@@ -140,13 +140,13 @@ export function getRuntimeOffset(state: RuntimeState): { offsetAbs: number; offs
|
||||
// time the playback was paused, the different from now to when we paused is added to the offset TODO: brakes when crossing midnight
|
||||
const pausedTime = state._timer.pausedAt === null ? 0 : clock - state._timer.pausedAt;
|
||||
|
||||
const offsetAbs = eventStartOffset + overtime + pausedTime + addedTime;
|
||||
const absolute = eventStartOffset + overtime + pausedTime + addedTime;
|
||||
|
||||
// the relative offset i the same as the absolute offset but adjusted relative to the actual start time
|
||||
const offsetRel = offsetAbs + plannedStart - actualStart;
|
||||
const relative = absolute + plannedStart - actualStart;
|
||||
|
||||
// in case of count to end, the absolute offset is just the overtime
|
||||
return countToEnd ? { offsetAbs: overtime, offsetRel } : { offsetAbs, offsetRel };
|
||||
return countToEnd ? { absolute: overtime, relative } : { absolute, relative };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user