stack-the-deck (#1)

Allow for redrawing or explicitly selecting a card for replacement.

Co-authored-by: Gavin McDonald <gavinmcdoh@gmail.com>
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2025-06-13 07:38:51 -04:00
parent c4f4b09f18
commit 5444e25249
14 changed files with 376 additions and 20 deletions

View File

@@ -130,6 +130,33 @@ export default class GameStore {
return this.gameUpdate(game);
}
redraw(gameID: string, cardIndex: number): GameUpdate {
const game = this.getGame(gameID);
const card = game.cards[cardIndex];
if (!card) throw new Error(`Card ${cardIndex} not found`);
game.cards[cardIndex] =
card.suit === 'High Deck' ? deck.drawHigh(game.cards) : deck.drawLow(game.cards);
game.lastUpdated = Date.now();
return this.gameUpdate(game);
}
select(gameID: string, cardIndex: number, cardID: string): GameUpdate {
const game = this.getGame(gameID);
const card = game.cards[cardIndex];
const replacement = deck.select(cardID);
if (!card) throw new Error(`Card ${cardIndex} not found`);
if (!replacement) throw new Error(`Card ${cardID} not found`);
game.cards[cardIndex] = replacement;
game.lastUpdated = Date.now();
return this.gameUpdate(game);
}
updateSettings(gameID: string, settings: Settings) {
const game = this.getGame(gameID);