fix: prevent endlos games from ending immediately on first score

- Change endlos raceTo from 0 to Infinity to prevent automatic completion
- Update NewGame component to handle Infinity values properly
- Add Infinity checks in game completion and winner logic
- Fix game progress calculation for endless games

Fixes issue where selecting 'endlos' mode would end the match
immediately when any player scored their first point.
This commit is contained in:
Frank Schwenk
2025-10-28 16:44:57 +01:00
parent 8bbe3b9b70
commit e89ae1039d
3 changed files with 18 additions and 3 deletions

View File

@@ -44,6 +44,9 @@ export function getGameDuration(game: Game): string {
}
export function calculateGameProgress(game: Game): number {
// If raceTo is Infinity, progress is always 0 (endless game)
if (game.raceTo === Infinity) return 0;
if (isEndlosGame(game)) {
const maxScore = Math.max(...game.players.map(p => p.score));
return Math.min((maxScore / game.raceTo) * 100, 100);
@@ -61,6 +64,9 @@ export function getGameWinner(game: Game): string | null {
return game.winner;
}
// If raceTo is Infinity, there's no automatic winner
if (game.raceTo === Infinity) return null;
if (isEndlosGame(game)) {
const winner = game.players.find(player => player.score >= game.raceTo);
return winner?.name || null;