diff --git a/src/services/CardDeck.ts b/src/services/CardDeck.ts index 8c4600c..e294eee 100644 --- a/src/services/CardDeck.ts +++ b/src/services/CardDeck.ts @@ -11,9 +11,9 @@ import rollDice from '@brdgm/brdgm-commons/src/util/random/rollDice' export default class CardDeck { // special cards for setup - private static readonly CARD_2 = 2 - private static readonly CARD_9 = 9 - private static readonly CARD_15 = 15 + private static readonly CARD_2 = '2' + private static readonly CARD_9 = '9' + private static readonly CARD_15 = '15' private _deck : Card[] private _reserve : Card[] @@ -135,7 +135,7 @@ export default class CardDeck { } -function moveCardToDeck(deck1: Card[], deck2: Card[], cardId: number) { +function moveCardToDeck(deck1: Card[], deck2: Card[], cardId: string) { const cardIndex = deck1.findIndex(card => card.id == cardId) const movedCard = deck1.splice(cardIndex, 1)[0] deck2.unshift(movedCard) diff --git a/src/store/state.ts b/src/store/state.ts index 9521993..4eac480 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -79,7 +79,7 @@ export interface RoundTurn { cardDeck?: CardDeckPersistence } export interface CardDeckPersistence { - deck: number[] - reserve: number[] - discard: number[] + deck: string[] + reserve: string[] + discard: string[] } diff --git a/tests/unit/services/BotActions.spec.ts b/tests/unit/services/BotActions.spec.ts index 5f8ebe1..f082598 100644 --- a/tests/unit/services/BotActions.spec.ts +++ b/tests/unit/services/BotActions.spec.ts @@ -11,7 +11,7 @@ import { expect } from 'chai' describe('BotActions', () => { it('1,6-round1', () => { - const botActions = new BotActions(Cards.get(1), Cards.get(6), + const botActions = new BotActions(Cards.get('1'), Cards.get('6'), 1, BotFaction.TERRANS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(2) @@ -26,7 +26,7 @@ describe('BotActions', () => { }) it('13/2-terrans', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.TERRANS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(3) @@ -46,7 +46,7 @@ describe('BotActions', () => { }) it('13/2-xenos', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.XENOS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(3) @@ -66,7 +66,7 @@ describe('BotActions', () => { }) it('13/2-taklons', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.TAKLONS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(3) @@ -86,7 +86,7 @@ describe('BotActions', () => { }) it('13/2-hadsch-hallas', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.HADSCH_HALLAS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(2) @@ -101,7 +101,7 @@ describe('BotActions', () => { }) it('13/2-geodens', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.GEODENS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(3) @@ -121,7 +121,7 @@ describe('BotActions', () => { }) it('13/2-firaks', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.FIRAKS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(2) @@ -136,7 +136,7 @@ describe('BotActions', () => { }) it('13/2-itars', () => { - const botActions = new BotActions(Cards.get(13), Cards.get(2), + const botActions = new BotActions(Cards.get('13'), Cards.get('2'), 1, BotFaction.ITARS, DifficultyLevel.AUTOMA) expect(botActions.actions.length).to.eq(3) diff --git a/tests/unit/services/CardDeck.spec.ts b/tests/unit/services/CardDeck.spec.ts index 5e1a3ac..054f273 100644 --- a/tests/unit/services/CardDeck.spec.ts +++ b/tests/unit/services/CardDeck.spec.ts @@ -27,7 +27,7 @@ describe('CardDeck', () => { expect(cardDeck.discard.length, 'discard size').to.eq(0) const persistence = cardDeck.toPersistence() - expect(persistence.deck.includes(9), '9 in deck').to.true + expect(persistence.deck.includes('9'), '9 in deck').to.true }) it('new-level4', () => { @@ -38,8 +38,8 @@ describe('CardDeck', () => { expect(cardDeck.discard.length, 'discard size').to.eq(0) const persistence = cardDeck.toPersistence() - expect(persistence.deck.includes(9), '9 in deck').to.true - expect(persistence.deck.includes(15), '15 in deck').to.true + expect(persistence.deck.includes('9'), '9 in deck').to.true + expect(persistence.deck.includes('15'), '15 in deck').to.true }) it('new-level5', () => { @@ -50,61 +50,61 @@ describe('CardDeck', () => { expect(cardDeck.discard.length, 'discard size').to.eq(0) const persistence = cardDeck.toPersistence() - expect(persistence.deck.includes(9), '9 in deck').to.true - expect(persistence.deck.includes(15), '15 in deck').to.true + expect(persistence.deck.includes('9'), '9 in deck').to.true + expect(persistence.deck.includes('15'), '15 in deck').to.true }) it('draw-pass-deck-empty', () => { const cardDeck = CardDeck.fromPersistence({ - deck: [4,6,7,9], + deck: ['4','6','7','9'], discard: [], reserve: [] }) expect(cardDeck.draw(), '1st draw').to.true - expect(cardDeck.actionCard?.id, '1st action card').to.eq(6) - expect(cardDeck.supportCard?.id, '1st support card').to.eq(4) + expect(cardDeck.actionCard?.id, '1st action card').to.eq('6') + expect(cardDeck.supportCard?.id, '1st support card').to.eq('4') expect(cardDeck.isPass(), '1st pass').to.false expect(cardDeck.draw(), '2nd draw').to.true - expect(cardDeck.actionCard?.id, '2nd action card').to.eq(7) - expect(cardDeck.supportCard?.id, '2nd support card').to.eq(6) + expect(cardDeck.actionCard?.id, '2nd action card').to.eq('7') + expect(cardDeck.supportCard?.id, '2nd support card').to.eq('6') expect(cardDeck.isPass(), '2nd pass').to.false expect(cardDeck.draw(), '3rd draw').to.true - expect(cardDeck.actionCard?.id, '3rd action card').to.eq(9) - expect(cardDeck.supportCard?.id, '3rd support card').to.eq(7) + expect(cardDeck.actionCard?.id, '3rd action card').to.eq('9') + expect(cardDeck.supportCard?.id, '3rd support card').to.eq('7') expect(cardDeck.isPass(), '3rd pass').to.false expect(cardDeck.draw(), '4th draw').to.false expect(cardDeck.actionCard, '4th action card').to.undefined - expect(cardDeck.supportCard?.id, '4th support card').to.eq(9) + expect(cardDeck.supportCard?.id, '4th support card').to.eq('9') expect(cardDeck.isPass(), '4th pass').to.true }) it('draw-pass-last-3', () => { const cardDeck = CardDeck.fromPersistence({ - deck: [1,2,3,4], + deck: ['1','2','3','4'], discard: [], reserve: [] }) expect(cardDeck.draw(), '1st draw').to.true - expect(cardDeck.actionCard?.id, '1st action card').to.eq(2) - expect(cardDeck.supportCard?.id, '1st support card').to.eq(1) + expect(cardDeck.actionCard?.id, '1st action card').to.eq('2') + expect(cardDeck.supportCard?.id, '1st support card').to.eq('1') expect(cardDeck.isPass(), '1st pass').to.false expect(cardDeck.draw(), '2nd draw').to.true - expect(cardDeck.actionCard?.id, '2nd action card').to.eq(3) - expect(cardDeck.supportCard?.id, '2nd support card').to.eq(2) + expect(cardDeck.actionCard?.id, '2nd action card').to.eq('3') + expect(cardDeck.supportCard?.id, '2nd support card').to.eq('2') expect(cardDeck.isPass(), '2nd pass').to.true }) it('prepareForNextRound', () => { const cardDeck = CardDeck.fromPersistence({ - deck: [1,2], - discard: [3,4], - reserve: [6,7] + deck: ['1','2'], + discard: ['3','4'], + reserve: ['6','7'] }) cardDeck.prepareForNextRound() @@ -113,6 +113,6 @@ describe('CardDeck', () => { expect(persistence.deck.length, 'deck size').to.eq(5) expect(persistence.discard.length, 'deck size').to.eq(0) expect(persistence.reserve.length, 'deck size').to.eq(1) - expect(persistence.deck.includes(6), 'includes reserve card').to.true + expect(persistence.deck.includes('6'), 'includes reserve card').to.true }) }) diff --git a/tests/unit/services/Cards.spec.ts b/tests/unit/services/Cards.spec.ts index 7ded347..5fb5127 100644 --- a/tests/unit/services/Cards.spec.ts +++ b/tests/unit/services/Cards.spec.ts @@ -4,10 +4,10 @@ import { expect } from 'chai' describe('Cards', () => { it('get', () => { - const card = Cards.get(1) + const card = Cards.get('1') expect(card).not.undefined - expect(card?.id).to.eq(1) + expect(card?.id).to.eq('1') }) it('getAll', () => {