block end calculation (#1683)

This commit is contained in:
Alex Christoffer Rasmussen
2025-07-13 17:01:21 +02:00
committed by Carlos Valente
parent e811a82be2
commit e9dda817e5
15 changed files with 474 additions and 376 deletions
+12 -3
View File
@@ -18,6 +18,7 @@ import { timeNow } from '../utils/time.js';
import type { RestorePoint } from '../services/RestoreService.js';
import {
getCurrent,
getExpectedBlockFinish,
getExpectedEnd,
getExpectedFinish,
getRuntimeOffset,
@@ -27,11 +28,12 @@ import { loadRoll, normaliseRollStart } from '../services/rollUtils.js';
import { timerConfig } from '../setup/config.js';
import { RundownMetadata } from '../api-data/rundown/rundown.types.js';
import { getPlayableIndexFromTimedIndex } from '../api-data/rundown/rundown.utils.js';
import { getCurrentRundown } from '../api-data/rundown/rundown.dao.js';
export type RuntimeState = {
clock: number; // realtime clock
blockNow: BlockState | null;
blockNext: BlockState | null;
blockNext: MaybeString;
eventNow: PlayableEvent | null;
eventNext: PlayableEvent | null;
runtime: Runtime;
@@ -90,6 +92,8 @@ export function clearEventData() {
runtimeState.runtime.expectedEnd = null;
runtimeState.runtime.selectedEventIndex = null;
if (runtimeState.blockNow) runtimeState.blockNow.expectedEnd = null;
runtimeState.timer.playback = Playback.Stop;
runtimeState.clock = timeNow();
runtimeState.timer = { ...runtimeStorePlaceholder.timer };
@@ -509,6 +513,11 @@ export function update(): UpdateResult {
runtimeState.timer.expectedFinish = getExpectedFinish(runtimeState);
}
if (runtimeState.blockNow) {
const expectedBlockFinish = getExpectedBlockFinish(runtimeState, getCurrentRundown());
runtimeState.blockNow.expectedEnd = expectedBlockFinish;
}
return { hasTimerFinished: finishedNow, hasSecondaryTimerFinished: false };
function updateIfIdle() {
@@ -690,7 +699,7 @@ export function loadBlock(rundown: Rundown, state = runtimeState) {
let foundEventNow = false;
for (const id of rundown.order) {
if (foundEventNow && isOntimeBlock(rundown.entries[id])) {
state.blockNext = { id, startedAt: null }; // the id is set here, the start time is set in other placed that handel starting events
state.blockNext = id; // the id is set here, the start time is set in other placed that handel starting events
break;
}
if (id === state.eventNow.id) {
@@ -707,7 +716,7 @@ export function loadBlock(rundown: Rundown, state = runtimeState) {
//we went into a new block - and it is different from the one we might have come from
if ((state.blockNow != null && state.blockNow.id != currentBlockId) || state.blockNow == null) {
state.blockNow = { id: currentBlockId, startedAt: null }; // the id is set here, the start time is set in other placed that handel starting events
state.blockNow = { id: currentBlockId, startedAt: null, expectedEnd: null }; // the id is set here, the start time is set in other placed that handel starting events
}
}