Files
Werewolf/client/modules/DeckStateManager.js
2021-11-08 23:38:41 -05:00

49 lines
1.3 KiB
JavaScript

export class DeckStateManager {
constructor() {
this.deck = null;
this.customRoleOptions = null;
}
addToDeck(role) {
let option = this.customRoleOptions.find((option) => option.role === role)
let existingCard = this.deck.find((card) => card.role === role)
if (option && !existingCard) {
option.quantity = 0;
this.deck.push(option);
this.customRoleOptions.splice(this.customRoleOptions.indexOf(option), 1);
}
}
addToCustomRoleOptions(role) {
this.customRoleOptions.push(role);
}
addCopyOfCard(role) {
let existingCard = this.deck.find((card) => card.role === role)
if (existingCard) {
existingCard.quantity += 1;
}
}
removeCopyOfCard(role) {
let existingCard = this.deck.find((card) => card.role === role)
if (existingCard && existingCard.quantity > 0) {
existingCard.quantity -= 1;
}
}
getCurrentDeck() { return this.deck }
getCard(role) { return this.deck.find((card) => card.role === role) }
getCurrentCustomRoleOptions() { return this.customRoleOptions }
getDeckSize() {
let total = 0;
for (let role of this.deck) {
total += role.quantity;
}
return total;
}
}