Add optional chaining for backward compatibility with old game states

This commit is contained in:
coyotte508 2026-08-24 13:40:49 +00:00
commit 9f665c4a07
3 changed files with 5 additions and 2 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ dist
dist-test dist-test
.pnpm-store .pnpm-store
.playwright-mcp .playwright-mcp
*.tgz

View file

@ -285,7 +285,8 @@ export function mustAutoPassBid(state: GameState, seat: number): boolean {
if (publicMaxBid(state, seat, auction.upgrade) <= auction.highBid) { if (publicMaxBid(state, seat, auction.upgrade) <= auction.highBid) {
return true; return true;
} }
return player.settings.autoPassBids === true && maxBid(state, seat, auction.upgrade) <= auction.highBid; // Optional chain: states saved before the settings field existed lack it.
return player.settings?.autoPassBids === true && maxBid(state, seat, auction.upgrade) <= auction.highBid;
} }
/** Coarse list of the moves available to a player, for the BGS sidebar. */ /** Coarse list of the moves available to a player, for the BGS sidebar. */

View file

@ -145,7 +145,8 @@ export function setPlayerSettings(data: GameState, player: number, settings: Rec
} }
export function playerSettings(data: GameState, player: number): Record<string, unknown> { export function playerSettings(data: GameState, player: number): Record<string, unknown> {
return { autoPassBids: data.players[player]?.settings.autoPassBids === true }; // Optional chain: states saved before the settings field existed lack it.
return { autoPassBids: data.players[player]?.settings?.autoPassBids === true };
} }
// Every state must be persisted: the platform keeps no memory between requests // Every state must be persisted: the platform keeps no memory between requests