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 types = { v: 'vowel', c: 'consonant' };
|
||||||
|
|
||||||
const settings = { ...config.letters };
|
const settings = { ...config.letters };
|
||||||
|
const minReminderInterval = 10; // seconds
|
||||||
const games = new Map();
|
const games = new Map();
|
||||||
|
|
||||||
function getBoard(context) {
|
function getBoard(context) {
|
||||||
@@ -106,22 +107,20 @@ async function play(context) {
|
|||||||
game.state = 'words';
|
game.state = 'words';
|
||||||
game.counts = countLetters(game.word);
|
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 {
|
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);
|
if (step < steps) {
|
||||||
await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal });
|
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((timeout / steps) * (steps - step))} seconds`))} left`, context.room.id);
|
||||||
|
}
|
||||||
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 });
|
|
||||||
|
|
||||||
stop(context);
|
stop(context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+12
-7
@@ -41,6 +41,7 @@ limitedMath.import({
|
|||||||
}, { override: true });
|
}, { override: true });
|
||||||
|
|
||||||
const settings = { ...config.numbers };
|
const settings = { ...config.numbers };
|
||||||
|
const minReminderInterval = 10; // seconds
|
||||||
const games = new Map();
|
const games = new Map();
|
||||||
|
|
||||||
/* eslint-disable no-irregular-whitespace */
|
/* eslint-disable no-irregular-whitespace */
|
||||||
@@ -177,17 +178,21 @@ async function play(context) {
|
|||||||
|
|
||||||
game.state = 'solutions';
|
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}`);
|
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 {
|
try {
|
||||||
await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal });
|
for (let step = 1; step <= steps; step += 1) {
|
||||||
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round((settings.timeout / 3) * 2)} seconds`))} left`, context.room.id);
|
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 });
|
if (step < steps) {
|
||||||
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round(settings.timeout / 3)} seconds`))} left`, context.room.id);
|
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round((timeout / steps) * (steps - step))} seconds`))} left`, context.room.id);
|
||||||
|
}
|
||||||
await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal });
|
}
|
||||||
|
|
||||||
stop(context);
|
stop(context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user