-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shift plus moving moves character as far as it can #1071
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,28 +335,28 @@ export default function Game({ | |
onNext(); | ||
} | ||
|
||
return; | ||
return false; | ||
} | ||
|
||
if (code === 'KeyP') { | ||
if (onPrev) { | ||
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')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic should be moved to within the Need a condition around this section of code:
to check if the shift key is pressed, and if so call makeMove in a loop until it fails Would need to double check that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I was doing this first but then realized that undo may not work as expected. I can try it and see but I think that we wouldn't be storing the intermediate state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting... I wonder what would be best there. Maybe it's nice if a single undo removes all the moves at once? Since the shift + move is kind of like one "move" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it is less confusing if you can undo one at a time and not be in a batch... |
||
// @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) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need to return a boolean here, or if we do it should be more clear what the boolean means