From c7d035bd8f34e26796d673d186463a4a7e882497 Mon Sep 17 00:00:00 2001 From: cocos02 Date: Sun, 7 Jun 2026 18:56:30 +0800 Subject: [PATCH] fix: interpret Choice.timeLimit as seconds, convert to ms internally Previously maxLimit was passed directly to setTimeout/setInterval (ms), so a JSON value of 10 meant 10ms instead of the intended 10 seconds. Now timeLimit in JSON represents seconds, engine multiplies by 1000. --- engine/systems/ChoiceSystem.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) 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() {