|
|
@@ -6,6 +6,10 @@ function initGame(story, state) { |
|
|
|
|
|
|
|
|
state.player.stats = {}; |
|
|
state.player.stats = {}; |
|
|
state.player.stats.health = 100; |
|
|
state.player.stats.health = 100; |
|
|
|
|
|
|
|
|
|
|
|
state.timers = []; |
|
|
|
|
|
|
|
|
|
|
|
state.timers.global = new Set(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: format string this lol |
|
|
// TODO: format string this lol |
|
|
@@ -38,20 +42,46 @@ function updatePlayerInfo(state) { |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
{ |
|
|
{ |
|
|
|
|
|
id: an optional name; needed to manually kill a timer |
|
|
func: the function to invoke |
|
|
func: the function to invoke |
|
|
delay: how long to wait between invocations |
|
|
delay: how long to wait between invocations |
|
|
loop: false = no looping, true = loop forever |
|
|
loop: false = no looping, true = loop forever |
|
|
|
|
|
room: the room associated with the timer |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Returns the timeout id - but you still need to cancel it through stopTimer! |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
function startTimer(config, state) { |
|
|
function startTimer(config, state) { |
|
|
if (config.loop) { |
|
|
if (config.loop) { |
|
|
const timeout = setTimeout(() => { |
|
|
const timeout = setTimeout(() => { |
|
|
config.func(); |
|
|
config.func(); |
|
|
state.timers.global.delete(timeout); |
|
|
|
|
|
|
|
|
state.timers = state.timers.filter(x => x.timeout != timeout); |
|
|
startTimer(config, state); |
|
|
startTimer(config, state); |
|
|
}, config.delay); |
|
|
}, config.delay); |
|
|
|
|
|
|
|
|
state.timers.global.add(timeout); |
|
|
|
|
|
|
|
|
state.timers.push({id: config.id, timeout: timeout, room: config.room}); |
|
|
|
|
|
|
|
|
|
|
|
return timeout; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function stopTimer(id, state) { |
|
|
|
|
|
const matches = state.timers.filter(timer => timer.id == id); |
|
|
|
|
|
matches.forEach(timer => clearTimeout(timer.timeout)); |
|
|
|
|
|
|
|
|
|
|
|
state.timers = state.timers.filter(timer => timer.id != id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function stopRoomTimers(room, state) { |
|
|
|
|
|
const matches = state.timers.filter(timer => timer.room == room); |
|
|
|
|
|
matches.forEach(timer => clearTimeout(timer.timeout)); |
|
|
|
|
|
|
|
|
|
|
|
state.timers = state.timers.filter(timer => timer.room != room); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function stopAllTimers(state) { |
|
|
|
|
|
state.timers.forEach(x => clearTimeout(x.timeout)); |
|
|
|
|
|
state.timers = []; |
|
|
|
|
|
} |