Bladeren bron

Added a basic timer system

tags/v0.1.0
Fen Dweller 6 jaren geleden
bovenliggende
commit
64cf846ea2
2 gewijzigde bestanden met toevoegingen van 26 en 0 verwijderingen
  1. +20
    -0
      game.js
  2. +6
    -0
      satiate.js

+ 20
- 0
game.js Bestand weergeven

@@ -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 Bestand weergeven

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

}
},
timers: {
room: {

},
global: new Set()
}
};



Laden…
Annuleren
Opslaan