Skip to content

Commit

Permalink
Fix upgrade action
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Jul 22, 2023
1 parent 06cf2f3 commit 07c93d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/game/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
}

Expand Down
11 changes: 7 additions & 4 deletions src/ui/game-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<slay-map>
Expand Down
9 changes: 9 additions & 0 deletions tests/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 07c93d2

Please sign in to comment.