Fixed game reminder spacing during short timeouts.
This commit is contained in:
+12
-13
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user