MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / timerFn

Function timerFn

src/engine/ui.ts:258–273  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

256 let expected = Date.now () + interval;
257
258 const timerFn = () => {
259 const now = Date.now () - expected; // the drift (positive for overshooting)
260 if (now > interval) {
261 // something really bad happened. Maybe the browser (tab) was inactive?
262 // possibly special handling to avoid futile "catch up" run
263 }
264 engine.proceed ({ userInitiated: false, skip: false, autoPlay: true }).then (() => {
265 expected += interval;
266 setTimeout (engine.global ('_auto_play_timer') as () => void, Math.max (0, interval - now)); // take into account drift
267 }).catch (() => {
268 // An action waiting for user interaction or something else
269 // is blocking the game.
270 expected += interval;
271 setTimeout (engine.global ('_auto_play_timer') as () => void, Math.max (0, interval - now)); // take into account drift
272 });
273 };
274
275 engine.global ('_auto_play_timer', timerFn);
276 setTimeout (timerFn, interval);

Callers

nothing calls this directly

Calls 2

proceedMethod · 0.80
globalMethod · 0.80

Tested by

no test coverage detected