From d5c700d9c739df2a78749ec0cc532166a1c4d392 Mon Sep 17 00:00:00 2001 From: Danny Miller Date: Sat, 20 Jan 2024 21:21:04 -0500 Subject: [PATCH 1/2] shift plus moving moves character as far as it can --- components/level/game.tsx | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/components/level/game.tsx b/components/level/game.tsx index d1f7f7cdf..4711e5c7b 100644 --- a/components/level/game.tsx +++ b/components/level/game.tsx @@ -335,7 +335,7 @@ export default function Game({ onNext(); } - return; + return false; } if (code === 'KeyP') { @@ -343,20 +343,20 @@ export default function Game({ onPrev(); } - return; + return false; } // check if code is the shift key if (code.startsWith('Shift')) { shiftKeyDown.current = true; - return; + return false; } // check if code starts with the words Digit if (code.startsWith('Digit') || code === 'KeyB') { if (disableCheckpoints) { - return; + return false; } if (!pro) { @@ -369,7 +369,7 @@ export default function Game({ } ); - return; + return false; } if (code.startsWith('Digit')) { @@ -384,7 +384,7 @@ export default function Game({ loadCheckpoint(BEST_CHECKPOINT_INDEX); } - return; + return false; } setGameState(prevGameState => { @@ -462,7 +462,9 @@ export default function Game({ return prevGameState; } - if (!makeMove(newGameState, direction, !disableAutoUndo)) { + const move = makeMove(newGameState, direction, !disableAutoUndo); + + if (!move) { return prevGameState; } @@ -484,6 +486,8 @@ export default function Game({ return onSuccessfulMove(newGameState); }); + + return true; }, [disableAutoUndo, disableCheckpoints, disablePlayAttempts, enableSessionCheckpoint, fetchPlayAttempt, game.displayName, isComplete, level._id, level.data, level.leastMoves, loadCheckpoint, onComplete, onMove, onNext, onPrev, onSolve, pro, saveCheckpoint, saveSessionToSessionStorage, trackStats]); useEffect(() => { @@ -526,7 +530,19 @@ export default function Game({ event.preventDefault(); } - handleKeyDown(code); + let timesToMove = 1; + + // if code starts with arrow + if (shiftKeyDown.current && code.startsWith('Arrow')) { + // @TODO: this 39 is based on the max width of grid being 40... + // ideally we just keep moving until handleKeyDown fails but based on how the code is written, + // it isn't straightforward how to have it return false if it fails + timesToMove = 39; + } + + for (let i = 0; i < timesToMove; i ++) { + handleKeyDown(code); + } }, [handleKeyDown, preventKeyDownEvent]); const handleKeyUpEvent = useCallback((event: KeyboardEvent) => { From c38aabcdb74e41b082d0f631a28f46a0be9dd521 Mon Sep 17 00:00:00 2001 From: Danny Miller Date: Thu, 25 Jan 2024 21:28:16 -0500 Subject: [PATCH 2/2] address code review. dont need to return boolean --- components/level/game.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/level/game.tsx b/components/level/game.tsx index 4711e5c7b..f0d2697e4 100644 --- a/components/level/game.tsx +++ b/components/level/game.tsx @@ -384,7 +384,7 @@ export default function Game({ loadCheckpoint(BEST_CHECKPOINT_INDEX); } - return false; + return; } setGameState(prevGameState => {