diff --git a/src/game-logic/reducers/processLevelUp.js b/src/game-logic/reducers/processLevelUp.js index be83b6664..169a5476f 100644 --- a/src/game-logic/reducers/processLevelUp.js +++ b/src/game-logic/reducers/processLevelUp.js @@ -37,7 +37,7 @@ export const processLevelUp = (state, oldLevel) => { true ) } else if (levelObject?.unlocksTool) { - state.toolLevels = unlockTool(state.toolLevels, levelObject.unlocksTool) + state = unlockTool(state, levelObject.unlocksTool) } else if (levelObject?.unlocksStageFocusType) { state = unlockStage(state, levelObject.unlocksStageFocusType) } diff --git a/src/utils/index.js b/src/utils/index.js index 54645d39e..f3e5aee50 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -974,14 +974,20 @@ export const computeMarketPositions = ( * @param {farmhand.toolType} toolType * @returns {farmhand.state} */ -export const unlockTool = (currentToolLevels, toolType) => { +export const unlockTool = (state, toolType) => { + const { currentToolLevels } = state + if (currentToolLevels[toolType] === toolLevel.UNAVAILABLE) { - return Object.assign({}, currentToolLevels, { - [toolType]: toolLevel.DEFAULT, - }) + return { + ...state, + currentToolLevels: { + ...currentToolLevels, + [toolType]: toolLevel.DEFAULT, + }, + } } - return currentToolLevels + return state } /* diff --git a/src/utils/index.test.js b/src/utils/index.test.js index 446fd48a1..367ae038e 100644 --- a/src/utils/index.test.js +++ b/src/utils/index.test.js @@ -1087,12 +1087,34 @@ describe('getGrowingPhase', () => { describe('unlockTool', () => { it('unlocks the specified tool', () => { - const tools = { - [toolType.SHOVEL]: toolLevel.UNAVAILABLE, + const state = { + currentToolLevels: { + [toolType.SHOVEL]: toolLevel.UNAVAILABLE, + }, + } + + const { currentToolLevels } = unlockTool(state, toolType.SHOVEL) + + expect(currentToolLevels[toolType.SHOVEL]).toEqual(toolLevel.DEFAULT) + }) + + it('does not alter the rest of the tools', () => { + const state = { + currentToolLevels: { + [toolType.SHOVEL]: toolLevel.UNAVAILABLE, + [toolType.HOE]: toolLevel.DEFAULT, + [toolType.SCYTHE]: toolLevel.GOLD, + }, } - const updatedTools = unlockTool(tools, toolType.SHOVEL) + const { currentToolLevels } = unlockTool(state, toolType.SHOVEL) - expect(updatedTools[toolType.SHOVEL]).toEqual(toolLevel.DEFAULT) + expect(currentToolLevels).toMatchInlineSnapshot(` + Object { + "HOE": "DEFAULT", + "SCYTHE": "GOLD", + "SHOVEL": "DEFAULT", + } + `) }) })