Explorar el Código

Fix non-looping timers not working

tags/v0.1.2
Fen Dweller hace 6 años
padre
commit
685507b373
Se han modificado 1 ficheros con 18 adiciones y 20 borrados
  1. +18
    -20
      game.js

+ 18
- 20
game.js Ver fichero

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


*/ */
function startTimer(config, state) { 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) { function stopTimer(id, state) {


Cargando…
Cancelar
Guardar