diff --git a/engine/systems/ChoiceSystem.ts b/engine/systems/ChoiceSystem.ts index f0c63be..4faa4f7 100644 --- a/engine/systems/ChoiceSystem.ts +++ b/engine/systems/ChoiceSystem.ts @@ -23,11 +23,10 @@ export class ChoiceSystem { const timed = choices.filter((c) => c.timeLimit && c.timeLimit > 0) if (timed.length === 0) return - const maxLimit = Math.max(...timed.map((c) => c.timeLimit!)) + const maxLimitSec = Math.max(...timed.map((c) => c.timeLimit!)) + const maxLimitMs = maxLimitSec * 1000 - const maxLimitSec = maxLimit / 1000 - - this.timeLimit = maxLimit + this.timeLimit = maxLimitMs this.elapsed = 0 this.onUpdate = onUpdate this.onTimeout = onTimeout @@ -36,21 +35,19 @@ export class ChoiceSystem { this.timerId = setInterval(() => { this.elapsed += this.tickMs - const remaining = Math.max(0, this.timeLimit - this.elapsed) / 1000 - const nextState: ChoiceTimerState = { - total: this.timeLimit / 1000, - remaining: Math.ceil(remaining * 10) / 10, - } - this.onUpdate?.(nextState) + const remainingSec = Math.max(0, maxLimitMs - this.elapsed) / 1000 + this.onUpdate?.({ + total: maxLimitSec, + remaining: Math.ceil(remainingSec * 10) / 10, + }) }, this.tickMs) this.timeoutId = setTimeout(() => { this.clear() - // Pick the first choice as default on timeout if (choices.length > 0) { this.onTimeout?.(choices[0]) } - }, this.timeLimit) + }, maxLimitMs) } stop() {