select cards

This commit is contained in:
Gavin McDonald
2025-06-12 18:05:17 -04:00
parent e75d9b41bc
commit 4583b06eba
11 changed files with 217 additions and 13 deletions

View File

@@ -143,6 +143,20 @@ export default class GameStore {
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);

View File

@@ -8,8 +8,8 @@ export default class TarokkaDeck {
private backs: TarokkaCard[] = [];
constructor() {
this.highDeck = cards.filter((card) => !card.back && card.suit === 'High Deck');
this.commonDeck = cards.filter((card) => !card.back && card.suit !== 'High Deck');
this.highDeck = cards.filter((card) => card.deck === 'high');
this.commonDeck = cards.filter((card) => card.deck === 'common');
this.backs = cards.filter((card) => card.back);
}
@@ -19,6 +19,14 @@ export default class TarokkaDeck {
);
}
getLow(): TarokkaGameCard[] {
return this.commonDeck.map((card) => ({ ...card, flipped: false }));
}
getHigh(): TarokkaGameCard[] {
return this.highDeck.map((card) => ({ ...card, flipped: false }));
}
drawLow(exclude: TarokkaGameCard[] = []): TarokkaGameCard {
const excludeIDs = exclude.map(({ id }) => id);
@@ -43,6 +51,17 @@ export default class TarokkaDeck {
};
}
select(id: string): TarokkaGameCard | null {
const card = cards.find((card) => card.id === id);
if (!card) return null;
return {
...card,
flipped: false,
};
}
getBack(): TarokkaCard {
return this.backs[0];
}