stories = []; function initGame(story, state) { state.info = {}; state.info.time = 60 * 60 * 9; state.player.stats = {}; state.player.stats.health = 100; } // TODO: format string this lol function renderTime(time) { let hours = Math.floor(time / 3600) % 12; const ampm = Math.floor(time / 3600) % 24 < 12 ? "AM" : "PM"; let minutes = Math.floor(time / 60) % 60; let seconds = time % 60; if (minutes <= 9) minutes = "0" + minutes; if (seconds <= 9) seconds = "0" + seconds; return hours + ":" + minutes + ":" + seconds + " " + ampm; } function updateWorldInfo(state) { const timeInfo = document.querySelector("#world-info-time"); timeInfo.textContent = "Time: " + renderTime(state.info.time); } function updatePlayerInfo(state) { const health = document.querySelector("#player-info-health"); health.textContent = "Health: " + state.player.stats.health; } /* { func: the function to invoke delay: how long to wait between invocations loop: false = no looping, true = loop forever } */ function startTimer(config, state) { if (config.loop) { const timeout = setTimeout(() => { config.func(); state.timers.global.delete(timeout); startTimer(config, state); }, config.delay); state.timers.global.add(timeout); } }