Skip to content

Commit

Permalink
Fix errors after upgrading immer v8
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Dec 24, 2020
1 parent 830a815 commit 7911800
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
15 changes: 11 additions & 4 deletions public/game/actions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import produce from '../web_modules/immer.js'
import produce, {setAutoFreeze} from '../web_modules/immer.js'
import {createCard} from './cards.js'
import {shuffle, getTargets, getCurrRoom, clamp} from './utils.js'
import powers from './powers.js'
import {createSimpleDungeon} from '../content/dungeon-encounters.js'

// The idea is that we have one big object with game state. Whenever we want to change something, we call an "action" from this file. Each action takes two arguments: 1) the current state, 2) an object of arguments.
// Without this, immer.js will throw an error if our `state` is modified outside of an action.
// While in theory a good idea, we're not there yet. It is a useful way to spot modifications
// of the game state that should not be there.
setAutoFreeze(false)

// This is the big object of game state. Everything should start here.
// In Slay the Web, we have one big object with game state.
// Whenever we want to change something, call an "action" from this file.
// Each action takes two arguments: 1) the current state, 2) an object of arguments.

// This is the big object of game state. Everything starts here.
function createNewGame() {
return {
turn: 1,
Expand Down Expand Up @@ -316,8 +323,8 @@ function rewardPlayer(state, {card}) {

function goToNextRoom(state) {
let nextState = reshuffleAndDraw(state)
nextState.player.powers = {} // Clear temporary powers.
return produce(nextState, (draft) => {
draft.player.powers = {} // Clear temporary powers.
const number = state.dungeon.index
if (number === state.dungeon.rooms.length - 1) {
throw new Error('You have reached the end of the dungeon. Congratulations.')
Expand Down
2 changes: 1 addition & 1 deletion public/web_modules/immer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/web_modules/immer.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion tests/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ test('Summer of sam card gains 1 life', (t) => {
test('vulnerable is working', (t) => {
const {state} = t.context
state.player.powers.vulnerable = 1
state.player.powers.vulnerable = 1
state.dungeon.rooms[0].monsters[0].intents = [{damage: 10}]
let newState = a.endTurn(state)
t.is(newState.player.currentHealth, 72 - 15)
Expand Down

0 comments on commit 7911800

Please sign in to comment.