From 2d2b3613e1bef661c00c6d4fc02c8f8e063525fa Mon Sep 17 00:00:00 2001 From: REllEK-IO Date: Wed, 8 May 2024 08:29:58 -0700 Subject: [PATCH] Time Model POC, just need to work it into stage planner beat --- src/model/time.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/model/time.ts b/src/model/time.ts index d40e780..0056266 100644 --- a/src/model/time.ts +++ b/src/model/time.ts @@ -23,7 +23,8 @@ const handleTimedRun = (axiumState: AxiumState, func: (() => Action)[], timed: n const timerList = timerKeys.map(t => Number(t)).sort((a, b) => a - b); const slot = axiumState.timerLedger.get(timerList[0]); if (slot) { - axiumState.timer.push(setTimeout(() => handleTimedRun(axiumState, slot[0], slot[1]), slot[1])); + const someTime = slot[1] - Date.now(); + axiumState.timer.push(setTimeout(() => handleTimedRun(axiumState, slot[0], slot[1]), someTime >= 0 ? someTime : 0)); } } if (axiumState.lastRun < Date.now()) { @@ -49,12 +50,12 @@ export const axiumTimeOut = (concepts: Concepts, func: () => Action, timeOut: nu const slot = axiumState.timerLedger.get(timed); if (slot) { slot[0].push(func); - ledger.set(timed, [slot[0], timeOut]); + ledger.set(timed, [slot[0], timed]); axiumState.timer.push(setTimeout(() => { handleTimedRun(axiumState, slot[0], timed); }, timeOut)); } else { - ledger.set(timed, [[func], timeOut]); + ledger.set(timed, [[func], timed]); axiumState.timer.push(setTimeout(() => { handleTimedRun(axiumState, [func], timed); }, timeOut)); @@ -63,11 +64,11 @@ export const axiumTimeOut = (concepts: Concepts, func: () => Action, timeOut: nu const slot = axiumState.timerLedger.get(timed); if (slot) { slot[0].push(func); - ledger.set(timed, [slot[0], timeOut]); + ledger.set(timed, [slot[0], timed]); } } } else { - ledger.set(timed, [[func], timeOut]); + ledger.set(timed, [[func], timed]); axiumState.timer.push(setTimeout(() => { handleTimedRun(axiumState, [func], timed); }, timeOut));