Ver código fonte

Added a basic timer system

tags/v0.1.0
Fen Dweller 6 anos atrás
pai
commit
64cf846ea2
2 arquivos alterados com 26 adições e 0 exclusões
  1. +20
    -0
      game.js
  2. +6
    -0
      satiate.js

+ 20
- 0
game.js Ver arquivo

@@ -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);
}
}

+ 6
- 0
satiate.js Ver arquivo

@@ -68,6 +68,12 @@ function init(story) {
rooms: {

}
},
timers: {
room: {

},
global: new Set()
}
};



Carregando…
Cancelar
Salvar