Little dependency array fix

This commit is contained in:
aronmal 2023-02-04 00:29:45 +01:00
parent 0507309ab1
commit ddb393be50
Signed by: aronmal
GPG key ID: 816B7707426FC612

View file

@ -47,6 +47,10 @@ function useGameEvent(count: number) {
.reduce((prev, curr) => [...prev, ...curr], [])
}, [mode])
const isHit = useCallback((x: number, y: number) => {
return hits.filter(h => h.x === x && h.y === y)
}, [hits])
const settingTarget = useCallback((isGameTile: boolean, x: number, y: number) => {
if (!isGameTile || isHit(x, y).length)
return
@ -64,16 +68,12 @@ function useGameEvent(count: number) {
}
})
}, [count, hits, targetList])
}, [count, isHit, targetList])
const isSet = useCallback((x: number, y: number) => {
return !!targetList(target).filter(field => x === field.x && y === field.y).length && target.show
}, [target, targetList])
const isHit = useCallback((x: number, y: number) => {
return hits.filter(h => h.x === x && h.y === y)
}, [hits])
const composeTargetTiles = useCallback((target: Target): PointerProps[] => {
const { preview, show } = target
const result = targetList(target).map(({ x, y, type, edges }) => {
@ -88,7 +88,7 @@ function useGameEvent(count: number) {
}
})
return result
}, [hits, isSet, targetList])
}, [isHit, isSet, targetList])
// handle visibility and position change of targetPreview
useEffect(() => {
@ -101,7 +101,7 @@ function useGameEvent(count: number) {
setTargetPreview(e => ({ ...e, show: false }))
if (!show && mouseCursor.shouldShow && eventReady && appearOK && !isHit(x, y).length && !isSet && !hasLeft)
setTargetPreview(e => ({ ...e, show: true }))
}, [targetPreview, mouseCursor.shouldShow, hits, eventReady, appearOK, lastLeftTile, target])
}, [targetPreview, mouseCursor.shouldShow, isHit, eventReady, appearOK, lastLeftTile, target])
// enable targetPreview event again after 200 ms.
useEffect(() => {