1
0

Fixed turn timer calculation

This commit is contained in:
James Ketr 2025-10-13 14:17:44 -07:00
parent dd8b930d0b
commit dfce3aa2f4

View File

@ -2342,7 +2342,15 @@ const pass = (game: Game, session: Session): string | undefined => {
if (!next || !next.player) { if (!next || !next.player) {
return `Unable to find the next player to pass to.`; return `Unable to find the next player to pass to.`;
} }
session.player.totalTime += Date.now() - session.player.turnStart; // Only accumulate totalTime if turnStart is a valid timestamp
if (session.player.turnStart && typeof session.player.turnStart === 'number' && session.player.turnStart > 0) {
const delta = Date.now() - session.player.turnStart;
if (!isNaN(delta) && delta > 0) {
session.player.totalTime += delta;
}
} else {
console.warn(`${session.short}: pass() called but player.turnStart is not set; skipping time accumulation.`);
}
session.player.turnNotice = ''; session.player.turnNotice = '';
game.turn = newTurn(next.player); game.turn = newTurn(next.player);
next.player.turnStart = Date.now(); next.player.turnStart = Date.now();
@ -3099,7 +3107,17 @@ const placeRoad = (game: Game, session: Session, index: number): string | undefi
} }
addChatMessage(game, null, `Everyone has placed their two settlements!`); addChatMessage(game, null, `Everyone has placed their two settlements!`);
// Ensure the first player's turn timer and turnStart are initialized
if (game.turn && game.turn.color) {
const firstSession = sessionFromColor(game, game.turn.color);
if (firstSession && firstSession.player) {
// initialize turnStart if not already set
if (!firstSession.player.turnStart || firstSession.player.turnStart === 0) {
firstSession.player.turnStart = Date.now();
}
startTurnTimer(game, firstSession);
}
}
/* Figure out which players received which resources for their /* Figure out which players received which resources for their
* initial (second) settlement placement. This mirrors the original * initial (second) settlement placement. This mirrors the original
* behaviour where the player receives resources adjacent to their * behaviour where the player receives resources adjacent to their