mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
add new function to detect key presses that can be ignored
This commit is contained in:
parent
b46718d188
commit
86b29237eb
@ -37,9 +37,13 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement {
|
|||||||
const [guess, setGuess] = useState("");
|
const [guess, setGuess] = useState("");
|
||||||
const hasAugment = Player.hasAugmentation(AugmentationNames.ChaosOfDionysus, true);
|
const hasAugment = Player.hasAugmentation(AugmentationNames.ChaosOfDionysus, true);
|
||||||
|
|
||||||
|
function ignorableKeyboardEvent(event: KeyboardEvent): boolean {
|
||||||
|
return event.key === KEY.BACKSPACE || (event.shiftKey && event.key === "Shift");
|
||||||
|
}
|
||||||
|
|
||||||
function press(this: Document, event: KeyboardEvent): void {
|
function press(this: Document, event: KeyboardEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (event.key === KEY.BACKSPACE) return;
|
if (ignorableKeyboardEvent(event)) return;
|
||||||
const nextGuess = guess + event.key.toUpperCase();
|
const nextGuess = guess + event.key.toUpperCase();
|
||||||
if (!answer.startsWith(nextGuess)) props.onFailure();
|
if (!answer.startsWith(nextGuess)) props.onFailure();
|
||||||
else if (answer === nextGuess) props.onSuccess();
|
else if (answer === nextGuess) props.onSuccess();
|
||||||
|
Loading…
Reference in New Issue
Block a user