Procházet zdrojové kódy

Fix non-looping timers not working

tags/v0.1.2
Fen Dweller před 6 roky
rodič
revize
685507b373
1 změnil soubory, kde provedl 18 přidání a 20 odebrání
  1. +18
    -20
      game.js

+ 18
- 20
game.js Zobrazit soubor

@@ -94,33 +94,31 @@ Returns the timeout id - but you still need to cancel it through stopTimer!

*/
function startTimer(config, state) {
if (config.loop) {
const timeout = setTimeout(() => {
const result = config.func(state, config);
refresh();
const timeout = setTimeout(() => {
const result = config.func(state, config);
refresh();

// the timer may have terminated itself!
// we have to make sure it still exists
// the timer may have terminated itself!
// we have to make sure it still exists

if (state.timers.some(x => x.timeout == timeout)){
state.timers = state.timers.filter(x => x.timeout != timeout);
if (typeof(result) === "number") {
config.delay = result;
}

// you shouldn't use a delay of 0 anyway
if (result) {
startTimer(config, state);
}
if (state.timers.some(x => x.timeout == timeout)){
state.timers = state.timers.filter(x => x.timeout != timeout);
if (typeof(result) === "number") {
config.delay = result;
}

// you shouldn't use a delay of 0 anyway
if (result && config.loop) {
startTimer(config, state);
}

}, config.delay);
}

state.timers.push({id: config.id, timeout: timeout, room: config.room, classes: config.classes || []});
}, config.delay);

return timeout;
}
state.timers.push({id: config.id, timeout: timeout, room: config.room, classes: config.classes || []});

return timeout;
}

function stopTimer(id, state) {


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