redraw cards
This commit is contained in:
@@ -130,6 +130,19 @@ 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);
|
||||
}
|
||||
|
||||
updateSettings(gameID: string, settings: Settings) {
|
||||
const game = this.getGame(gameID);
|
||||
|
||||
|
||||
@@ -19,6 +19,30 @@ export default class TarokkaDeck {
|
||||
);
|
||||
}
|
||||
|
||||
drawLow(exclude: TarokkaGameCard[] = []): TarokkaGameCard {
|
||||
const excludeIDs = exclude.map(({ id }) => id);
|
||||
|
||||
return {
|
||||
...getRandomItems(
|
||||
this.commonDeck.filter(({ id }) => !excludeIDs.includes(id)),
|
||||
1,
|
||||
)[0],
|
||||
flipped: false,
|
||||
};
|
||||
}
|
||||
|
||||
drawHigh(exclude: TarokkaGameCard[] = []): TarokkaGameCard {
|
||||
const excludeIDs = exclude.map(({ id }) => id);
|
||||
|
||||
return {
|
||||
...getRandomItems(
|
||||
this.highDeck.filter(({ id }) => !excludeIDs.includes(id)),
|
||||
1,
|
||||
)[0],
|
||||
flipped: false,
|
||||
};
|
||||
}
|
||||
|
||||
getBack(): TarokkaCard {
|
||||
return this.backs[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user