Skip to content

Commit 99fdcaa

Browse files
committed
add wasJustShoveled to plotContents when mined
1 parent 33d7d91 commit 99fdcaa

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

src/components/Plot/Plot.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react'
1+
import React from 'react'
22
import { bool, func, number, object, string } from 'prop-types'
33
import Tooltip from '@material-ui/core/Tooltip'
44
import Typography from '@material-ui/core/Typography'
@@ -86,24 +86,11 @@ export const Plot = ({
8686
const isCrop =
8787
plotContent && getPlotContentType(plotContent) === itemType.CROP
8888
const isScarecow = itemsMap[plotContent?.itemId]?.type === itemType.SCARECROW
89-
const [wasJustShoveled, setWasJustShoveled] = useState(false)
90-
const [initialIsShoveledState, setInitialIsShoveledState] = useState(
91-
Boolean(plotContent?.isShoveled)
92-
)
93-
94-
useEffect(() => {
95-
if (
96-
!initialIsShoveledState &&
97-
plotContent?.isShoveled &&
98-
plotContent?.oreId
99-
) {
100-
setWasJustShoveled(true)
101-
}
102-
}, [initialIsShoveledState, plotContent])
10389

104-
useEffect(() => {
105-
if (plotContent === null) setInitialIsShoveledState(false)
106-
}, [plotContent])
90+
let wasJustShoveled = false
91+
if (plotContent && plotContent.wasJustShoveled) {
92+
wasJustShoveled = true
93+
}
10794

10895
const showPlotImage = Boolean(
10996
image &&
@@ -145,14 +132,9 @@ export const Plot = ({
145132
<img
146133
{...{
147134
className: classNames('square', {
148-
...(isCrop && {
149-
animated: isRipe,
150-
heartBeat: isRipe,
151-
}),
152-
...(wasJustShoveled && {
153-
animated: true,
154-
'was-just-shoveled': true,
155-
}),
135+
animated: wasJustShoveled || (isCrop && isRipe),
136+
heartBeat: isCrop && isRipe,
137+
'was-just-shoveled': wasJustShoveled,
156138
}),
157139
style: {
158140
backgroundImage: showPlotImage ? `url(${image})` : undefined,

src/game-logic/reducers/minePlot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const minePlot = (state, x, y) => {
5353
state = modifyFieldPlotAt(state, x, y, () => {
5454
return {
5555
isShoveled: true,
56+
wasJustShoveled: true,
5657
daysUntilClear,
5758
oreId: spawnedOre ? spawnedOre.id : null,
5859
}

src/game-logic/reducers/resetWasShoveled.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const resetWasShoveled = plotContent => {
77
return {
88
...plotContent,
99
daysUntilClear: plotContent.daysUntilClear - 1,
10+
wasJustShoveled: false,
1011
}
1112
}
1213

0 commit comments

Comments
 (0)