mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-23 06:32:26 +01:00
convert infiltration to use key instead of keyCode
This commit is contained in:
parent
6835cbaa26
commit
b1328b02ce
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -36,7 +36,7 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement {
|
|||||||
|
|
||||||
function press(this: Document, event: KeyboardEvent): void {
|
function press(this: Document, event: KeyboardEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (event.keyCode === 16) return;
|
if (event.key === "Backspace") 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();
|
||||||
|
@ -38,10 +38,10 @@ function generateLeftSide(difficulty: Difficulty): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChar(event: KeyboardEvent): string {
|
function getChar(event: KeyboardEvent): string {
|
||||||
if (event.keyCode == 48 && event.shiftKey) return ")";
|
if (event.key === ")") return ")";
|
||||||
if (event.keyCode == 221 && !event.shiftKey) return "]";
|
if (event.key === "]") return "]";
|
||||||
if (event.keyCode == 221 && event.shiftKey) return "}";
|
if (event.key === "}") return "}";
|
||||||
if (event.keyCode == 190 && event.shiftKey) return ">";
|
if (event.key === ">") return ">";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,16 +33,16 @@ export function BribeGame(props: IMinigameProps): React.ReactElement {
|
|||||||
|
|
||||||
function press(this: Document, event: KeyboardEvent): void {
|
function press(this: Document, event: KeyboardEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const k = event.keyCode;
|
const k = event.key;
|
||||||
if (k === 32) {
|
if (k === " ") {
|
||||||
if (positive.includes(choices[index])) props.onSuccess();
|
if (positive.includes(choices[index])) props.onSuccess();
|
||||||
else props.onFailure();
|
else props.onFailure();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newIndex = index;
|
let newIndex = index;
|
||||||
if ([38, 87, 68, 39].includes(k)) newIndex++;
|
if (["ArrowUp", "w", "ArrowRight", "d"].includes(k)) newIndex++;
|
||||||
if ([65, 37, 83, 40].includes(k)) newIndex--;
|
if (["ArrowDown", "s", "ArrowLeft", "a"].includes(k)) newIndex--;
|
||||||
while (newIndex < 0) newIndex += choices.length;
|
while (newIndex < 0) newIndex += choices.length;
|
||||||
while (newIndex > choices.length - 1) newIndex -= choices.length;
|
while (newIndex > choices.length - 1) newIndex -= choices.length;
|
||||||
setIndex(newIndex);
|
setIndex(newIndex);
|
||||||
|
@ -59,7 +59,7 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement {
|
|||||||
next[1] = (next[1] + grid.length) % grid.length;
|
next[1] = (next[1] + grid.length) % grid.length;
|
||||||
setPos(next);
|
setPos(next);
|
||||||
|
|
||||||
if (event.keyCode == 32) {
|
if (event.key === " ") {
|
||||||
const selected = grid[pos[1]][pos[0]];
|
const selected = grid[pos[1]][pos[0]];
|
||||||
const expected = answer[index];
|
const expected = answer[index];
|
||||||
if (selected !== expected) {
|
if (selected !== expected) {
|
||||||
|
@ -60,7 +60,7 @@ export function MinesweeperGame(props: IMinigameProps): React.ReactElement {
|
|||||||
next[1] = (next[1] + minefield.length) % minefield.length;
|
next[1] = (next[1] + minefield.length) % minefield.length;
|
||||||
setPos(next);
|
setPos(next);
|
||||||
|
|
||||||
if (event.keyCode == 32) {
|
if (event.key == " ") {
|
||||||
if (!minefield[pos[1]][pos[0]]) {
|
if (!minefield[pos[1]][pos[0]]) {
|
||||||
props.onFailure();
|
props.onFailure();
|
||||||
return;
|
return;
|
||||||
|
@ -30,7 +30,7 @@ export function SlashGame(props: IMinigameProps): React.ReactElement {
|
|||||||
|
|
||||||
function press(this: Document, event: KeyboardEvent): void {
|
function press(this: Document, event: KeyboardEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (event.keyCode !== 32) return;
|
if (event.key !== " ") return;
|
||||||
if (phase !== 2) {
|
if (phase !== 2) {
|
||||||
props.onFailure();
|
props.onFailure();
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,18 +3,18 @@ export function random(min: number, max: number): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getArrow(event: KeyboardEvent): string {
|
export function getArrow(event: KeyboardEvent): string {
|
||||||
switch (event.keyCode) {
|
switch (event.key) {
|
||||||
case 38:
|
case "ArrowUp":
|
||||||
case 87:
|
case "w":
|
||||||
return "↑";
|
return "↑";
|
||||||
case 65:
|
case "ArrowLeft":
|
||||||
case 37:
|
case "a":
|
||||||
return "←";
|
return "←";
|
||||||
case 40:
|
case "ArrowDown":
|
||||||
case 83:
|
case "s":
|
||||||
return "↓";
|
return "↓";
|
||||||
case 39:
|
case "ArrowRight":
|
||||||
case 68:
|
case "d":
|
||||||
return "→";
|
return "→";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
Loading…
Reference in New Issue
Block a user