From 64cf846ea23dde937c01d6db15b8d177ade5b92d Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 8 Jan 2019 11:12:01 -0500 Subject: [PATCH] Added a basic timer system --- game.js | 20 ++++++++++++++++++++ satiate.js | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/game.js b/game.js index 13f8975..ff81b9f 100644 --- a/game.js +++ b/game.js @@ -35,3 +35,23 @@ function updatePlayerInfo(state) { 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); + } +} diff --git a/satiate.js b/satiate.js index cedda58..f9fe71d 100644 --- a/satiate.js +++ b/satiate.js @@ -68,6 +68,12 @@ function init(story) { rooms: { } + }, + timers: { + room: { + + }, + global: new Set() } };