Add optional chaining for backward compatibility with old game states
This commit is contained in:
parent
fc3da1727b
commit
9f665c4a07
3 changed files with 5 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,3 +6,4 @@ dist
|
||||||
dist-test
|
dist-test
|
||||||
.pnpm-store
|
.pnpm-store
|
||||||
.playwright-mcp
|
.playwright-mcp
|
||||||
|
*.tgz
|
||||||
|
|
|
||||||
|
|
@ -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. */
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue