From 9a802b358de0bcf47bc89ce0dc3fc5044f19c0b9 Mon Sep 17 00:00:00 2001 From: ThePendulum Date: Thu, 8 Oct 2026 05:16:34 +0200 Subject: [PATCH] Fixed game reminder spacing during short timeouts. --- src/games/letters.js | 25 ++++++++++++------------- src/games/numbers.js | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/games/letters.js b/src/games/letters.js index 1c4dcb9..446f7e2 100755 --- a/src/games/letters.js +++ b/src/games/letters.js @@ -18,6 +18,7 @@ const availableLetters = { const types = { v: 'vowel', c: 'consonant' }; const settings = { ...config.letters }; +const minReminderInterval = 10; // seconds const games = new Map(); function getBoard(context) { @@ -106,22 +107,20 @@ async function play(context) { game.state = 'words'; game.counts = countLetters(game.word); - context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(settings.timeout))} seconds, let's start!`, context.room.id); + // lock in the timeout so changing it mid-round doesn't skew the countdown + const { timeout } = settings; + const steps = Math.max(1, Math.min(5, Math.floor(timeout / minReminderInterval))); // don't repeat the board too often on short timeouts + + context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(timeout))} seconds, let's start!`, context.room.id); try { - await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal }); + for (let step = 1; step <= steps; step += 1) { + await timers.setTimeout((timeout / steps) * 1000, null, { signal: game.ac.signal }); // eslint-disable-line no-await-in-loop - context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((settings.timeout / 5) * 4)} seconds`))} left`, context.room.id); - await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal }); - - context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((settings.timeout / 5) * 3)} seconds`))} left`, context.room.id); - await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal }); - - context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((settings.timeout / 5) * 2)} seconds`))} left`, context.room.id); - await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal }); - - context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round(settings.timeout / 5)} seconds`))} left`, context.room.id); - await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal }); + if (step < steps) { + context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((timeout / steps) * (steps - step))} seconds`))} left`, context.room.id); + } + } stop(context); } catch (error) { diff --git a/src/games/numbers.js b/src/games/numbers.js index 058a8ac..645db58 100644 --- a/src/games/numbers.js +++ b/src/games/numbers.js @@ -41,6 +41,7 @@ limitedMath.import({ }, { override: true }); const settings = { ...config.numbers }; +const minReminderInterval = 10; // seconds const games = new Map(); /* eslint-disable no-irregular-whitespace */ @@ -177,17 +178,21 @@ async function play(context) { game.state = 'solutions'; - context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(settings.timeout))} seconds, let's start!`, context.room.id); + // lock in the timeout so changing it mid-round doesn't skew the countdown + const { timeout } = settings; + const steps = Math.max(1, Math.min(3, Math.floor(timeout / minReminderInterval))); // don't repeat the board too often on short timeouts + + context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(timeout))} seconds, let's start!`, context.room.id); context.logger.info(`Numbers game started by ${context.user.username}, numbers ${game.numbers.join('|')}, target ${game.target}, ${game.solution.answer === game.target ? 'exact' : 'closest'} solution for ${game.solution.answer} is: ${game.solution.solution}`); try { - await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal }); - context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round((settings.timeout / 3) * 2)} seconds`))} left`, context.room.id); + for (let step = 1; step <= steps; step += 1) { + await timers.setTimeout((timeout / steps) * 1000, null, { signal: game.ac.signal }); // eslint-disable-line no-await-in-loop - await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal }); - context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round(settings.timeout / 3)} seconds`))} left`, context.room.id); - - await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal }); + if (step < steps) { + context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round((timeout / steps) * (steps - step))} seconds`))} left`, context.room.id); + } + } stop(context); } catch (error) {