From 07c93d21b7b1937937bbf8b43491ddb76a78a0fb Mon Sep 17 00:00:00 2001 From: oskarrough Date: Sat, 22 Jul 2023 10:14:06 +0200 Subject: [PATCH] Fix upgrade action --- src/game/actions.js | 14 ++++++++++---- src/ui/game-screen.js | 11 +++++++---- src/ui/map.js | 2 +- tests/actions.js | 9 +++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/game/actions.js b/src/game/actions.js index afee5dfd..c9b5836d 100644 --- a/src/game/actions.js +++ b/src/game/actions.js @@ -162,7 +162,13 @@ function discardHand(state) { }) } -// Discard a single card from your hand. +/** + * Discard a single card from your hand. + * @param {State} state + * @param {object} props + * @param {CARD} props.card + * @returns {State} + */ function removeCard(state, {card}) { return produce(state, (draft) => { draft.deck = state.deck.filter((c) => c.id !== card.id) @@ -176,9 +182,9 @@ function removeCard(state, {card}) { * @returns {State} */ function upgradeCard(state, {card}) { - return produce(state, () => { - const upgraded = createCard(card.name, true) - card = upgraded + return produce(state, (draft) => { + const index = draft.deck.findIndex((c) => c.id === card.id) + draft.deck[index] = createCard(card.name, true) }) } diff --git a/src/ui/game-screen.js b/src/ui/game-screen.js index d97bb32e..4fcec521 100644 --- a/src/ui/game-screen.js +++ b/src/ui/game-screen.js @@ -75,10 +75,6 @@ export default class App extends Component { } enableConsole() { // Enable a "console" in the browser. - console.log(`Welcome to the Slay The Web Console. Some examples: -stw.game.enqueue({type: 'drawCards', amount: 2}) -stw.update() -stw.dealCards()`) // @ts-ignore window.stw = { game: this.game, @@ -96,7 +92,14 @@ stw.dealCards()`) submitGame() { backend.postRun(this.game) }, + help() { + console.log(`Welcome to the Slay The Web Console. Some examples: +stw.game.enqueue({type: 'drawCards', amount: 2}) +stw.update() +stw.dealCards()`) + } } + stw.help() } update(callback) { this.game.dequeue() diff --git a/src/ui/map.js b/src/ui/map.js index c1bc5af2..bff02500 100644 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -136,7 +136,7 @@ export class SlayMap extends Component { if (!dungeon.graph) throw new Error('No graph to render. This should not happen?', dungeon) const edgesFromCurrentNode = dungeon.graph[y][x].edges - console.log('edges from current map node', edgesFromCurrentNode) + // console.log('edges from current map node', edgesFromCurrentNode) return html` diff --git a/tests/actions.js b/tests/actions.js index 019ae0f9..82c94d09 100644 --- a/tests/actions.js +++ b/tests/actions.js @@ -497,5 +497,14 @@ test('Succube card applies regen', (t) => { t.is(newstate.player.powers.regen, 2) }) +test('upgraded cards are really upgraded', (t) => { + let state = a.createNewState() + state = a.addStarterDeck(state) + t.is(state.deck[9].name, 'Bash') + state = a.upgradeCard(state, {card: state.deck[9]}) + t.is(state.deck[9].name, 'Bash+') +}) + test.todo('playing defend on an enemy ?') test.todo('can apply a power to a specific monster') +