convert infiltration to use key instead of keyCode

This commit is contained in:
Olivier Gagnon
2021-10-27 20:52:16 -04:00
parent 6835cbaa26
commit b1328b02ce
9 changed files with 24 additions and 24 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement {
function press(this: Document, event: KeyboardEvent): void {
event.preventDefault();
if (event.keyCode === 16) return;
if (event.key === "Backspace") return;
const nextGuess = guess + event.key.toUpperCase();
if (!answer.startsWith(nextGuess)) props.onFailure();
else if (answer === nextGuess) props.onSuccess();
+4 -4
View File
@@ -38,10 +38,10 @@ function generateLeftSide(difficulty: Difficulty): string {
}
function getChar(event: KeyboardEvent): string {
if (event.keyCode == 48 && event.shiftKey) return ")";
if (event.keyCode == 221 && !event.shiftKey) return "]";
if (event.keyCode == 221 && event.shiftKey) return "}";
if (event.keyCode == 190 && event.shiftKey) return ">";
if (event.key === ")") return ")";
if (event.key === "]") return "]";
if (event.key === "}") return "}";
if (event.key === ">") return ">";
return "";
}
+4 -4
View File
@@ -33,16 +33,16 @@ export function BribeGame(props: IMinigameProps): React.ReactElement {
function press(this: Document, event: KeyboardEvent): void {
event.preventDefault();
const k = event.keyCode;
if (k === 32) {
const k = event.key;
if (k === " ") {
if (positive.includes(choices[index])) props.onSuccess();
else props.onFailure();
return;
}
let newIndex = index;
if ([38, 87, 68, 39].includes(k)) newIndex++;
if ([65, 37, 83, 40].includes(k)) newIndex--;
if (["ArrowUp", "w", "ArrowRight", "d"].includes(k)) newIndex++;
if (["ArrowDown", "s", "ArrowLeft", "a"].includes(k)) newIndex--;
while (newIndex < 0) newIndex += choices.length;
while (newIndex > choices.length - 1) newIndex -= choices.length;
setIndex(newIndex);
+1 -1
View File
@@ -59,7 +59,7 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement {
next[1] = (next[1] + grid.length) % grid.length;
setPos(next);
if (event.keyCode == 32) {
if (event.key === " ") {
const selected = grid[pos[1]][pos[0]];
const expected = answer[index];
if (selected !== expected) {
+1 -1
View File
@@ -60,7 +60,7 @@ export function MinesweeperGame(props: IMinigameProps): React.ReactElement {
next[1] = (next[1] + minefield.length) % minefield.length;
setPos(next);
if (event.keyCode == 32) {
if (event.key == " ") {
if (!minefield[pos[1]][pos[0]]) {
props.onFailure();
return;
+1 -1
View File
@@ -30,7 +30,7 @@ export function SlashGame(props: IMinigameProps): React.ReactElement {
function press(this: Document, event: KeyboardEvent): void {
event.preventDefault();
if (event.keyCode !== 32) return;
if (event.key !== " ") return;
if (phase !== 2) {
props.onFailure();
} else {