Procházet zdrojové kódy

Added a basic timer system

tags/v0.1.0
Fen Dweller před 6 roky
rodič
revize
64cf846ea2
2 změnil soubory, kde provedl 26 přidání a 0 odebrání
  1. +20
    -0
      game.js
  2. +6
    -0
      satiate.js

+ 20
- 0
game.js Zobrazit soubor

@@ -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 Zobrazit soubor

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

}
},
timers: {
room: {

},
global: new Set()
}
};



Načítá se…
Zrušit
Uložit