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:
@@ -575,7 +575,8 @@ const RaceToStep = ({ onNext, onCancel, initialValue = '', gameType }) => {
|
|||||||
}, [gameType, initialValue, defaultValue]);
|
}, [gameType, initialValue, defaultValue]);
|
||||||
|
|
||||||
const handleQuickPick = (value) => {
|
const handleQuickPick = (value) => {
|
||||||
setRaceTo(value);
|
// For endlos (endless) games, use Infinity to prevent automatic completion
|
||||||
|
setRaceTo(value === 0 ? 'Infinity' : value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInputChange = (e) => {
|
const handleInputChange = (e) => {
|
||||||
@@ -584,7 +585,9 @@ const RaceToStep = ({ onNext, onCancel, initialValue = '', gameType }) => {
|
|||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onNext(parseInt(raceTo, 10) || 0);
|
// Handle Infinity for endlos games, otherwise parse as integer
|
||||||
|
const raceToValue = raceTo === 'Infinity' ? Infinity : (parseInt(raceTo, 10) || 0);
|
||||||
|
onNext(raceToValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -600,7 +603,7 @@ const RaceToStep = ({ onNext, onCancel, initialValue = '', gameType }) => {
|
|||||||
<div className={styles['endlos-container']}>
|
<div className={styles['endlos-container']}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`${styles['race-to-btn']} ${styles['endlos-btn']} ${raceTo === 0 ? styles.selected : ''}`}
|
className={`${styles['race-to-btn']} ${styles['endlos-btn']} ${raceTo === 'Infinity' ? styles.selected : ''}`}
|
||||||
onClick={() => handleQuickPick(0)}
|
onClick={() => handleQuickPick(0)}
|
||||||
>
|
>
|
||||||
Endlos
|
Endlos
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ export class GameService {
|
|||||||
static isGameCompleted(game: Game): boolean {
|
static isGameCompleted(game: Game): boolean {
|
||||||
if (game.status === 'completed') return true;
|
if (game.status === 'completed') return true;
|
||||||
|
|
||||||
|
// If raceTo is Infinity, the game never completes automatically
|
||||||
|
if (game.raceTo === Infinity) return false;
|
||||||
|
|
||||||
if ('players' in game) {
|
if ('players' in game) {
|
||||||
// EndlosGame
|
// EndlosGame
|
||||||
return game.players.some(player => player.score >= game.raceTo);
|
return game.players.some(player => player.score >= game.raceTo);
|
||||||
@@ -96,6 +99,9 @@ export class GameService {
|
|||||||
static getGameWinner(game: Game): string | null {
|
static getGameWinner(game: Game): string | null {
|
||||||
if (!this.isGameCompleted(game)) return null;
|
if (!this.isGameCompleted(game)) return null;
|
||||||
|
|
||||||
|
// If raceTo is Infinity, there's no automatic winner
|
||||||
|
if (game.raceTo === Infinity) return null;
|
||||||
|
|
||||||
if ('players' in game) {
|
if ('players' in game) {
|
||||||
// EndlosGame
|
// EndlosGame
|
||||||
const winner = game.players.find(player => player.score >= game.raceTo);
|
const winner = game.players.find(player => player.score >= game.raceTo);
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ export function getGameDuration(game: Game): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function calculateGameProgress(game: Game): number {
|
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)) {
|
if (isEndlosGame(game)) {
|
||||||
const maxScore = Math.max(...game.players.map(p => p.score));
|
const maxScore = Math.max(...game.players.map(p => p.score));
|
||||||
return Math.min((maxScore / game.raceTo) * 100, 100);
|
return Math.min((maxScore / game.raceTo) * 100, 100);
|
||||||
@@ -61,6 +64,9 @@ export function getGameWinner(game: Game): string | null {
|
|||||||
return game.winner;
|
return game.winner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If raceTo is Infinity, there's no automatic winner
|
||||||
|
if (game.raceTo === Infinity) return null;
|
||||||
|
|
||||||
if (isEndlosGame(game)) {
|
if (isEndlosGame(game)) {
|
||||||
const winner = game.players.find(player => player.score >= game.raceTo);
|
const winner = game.players.find(player => player.score >= game.raceTo);
|
||||||
return winner?.name || null;
|
return winner?.name || null;
|
||||||
|
|||||||
Reference in New Issue
Block a user