diff --git a/src/Augmentation/AugmentationCreator.tsx b/src/Augmentation/AugmentationCreator.tsx index 82116653b..13511b0cc 100644 --- a/src/Augmentation/AugmentationCreator.tsx +++ b/src/Augmentation/AugmentationCreator.tsx @@ -131,7 +131,7 @@ export const infiltratorsAugmentations = [ factions: [FactionNames.Infiltrators], }), new Augmentation({ - name: AugmentationNames.AmuletOfPersuasian, + name: AugmentationNames.AmuletOfPersuasion, repCost: 1e2, moneyCost: 1e6, info: diff --git a/src/Augmentation/data/AugmentationNames.ts b/src/Augmentation/data/AugmentationNames.ts index 87049c37c..f494bee54 100644 --- a/src/Augmentation/data/AugmentationNames.ts +++ b/src/Augmentation/data/AugmentationNames.ts @@ -114,7 +114,7 @@ export const AugmentationNames: { BagOfSand: string; IntellisenseModule: string; ReverseDictionary: string; - AmuletOfPersuasian: string; + AmuletOfPersuasion: string; LameSharkRepository: string; CyberDecoder: string; MineDetector: string; @@ -237,7 +237,7 @@ export const AugmentationNames: { BagOfSand: "A Bag of Sand", IntellisenseModule: "Intellisense Module", ReverseDictionary: "Reverse Dictionary", - AmuletOfPersuasian: "Amulet of Persuasian", + AmuletOfPersuasion: "Amulet of Persuasian", LameSharkRepository: "Lame Shark Repository", CyberDecoder: "Cyber Decoder", MineDetector: "Mine Detector", diff --git a/src/BitNode/ui/BitverseRoot.tsx b/src/BitNode/ui/BitverseRoot.tsx index 434841c60..33a710d7a 100644 --- a/src/BitNode/ui/BitverseRoot.tsx +++ b/src/BitNode/ui/BitverseRoot.tsx @@ -170,7 +170,6 @@ export function BitverseRoot(props: IProps): React.ReactElement { <> {Object.values(BitNodes) .filter((node) => { - console.log(node.desc); return node.desc !== "COMING SOON"; }) .map((node) => { diff --git a/src/Bladeburner/ui/Console.tsx b/src/Bladeburner/ui/Console.tsx index f4144d24f..495c28a15 100644 --- a/src/Bladeburner/ui/Console.tsx +++ b/src/Bladeburner/ui/Console.tsx @@ -109,7 +109,7 @@ export function Console(props: IProps): React.ReactElement { setCommand(prevCommand); } - if (event.key === KEY.DOWNARROW) { + if (event.key === KEY.DOWN_ARROW) { const i = consoleHistoryIndex; const len = consoleHistory.length; @@ -140,14 +140,16 @@ export function Console(props: IProps): React.ReactElement { return ( - + @@ -195,9 +197,7 @@ function Logs({ entries }: ILogProps): React.ReactElement { return ( - {entries && entries.map((log: any, i: number) => ( - - ))} + {entries && entries.map((log: any, i: number) => )} ); } diff --git a/src/Infiltration/ui/BackwardGame.tsx b/src/Infiltration/ui/BackwardGame.tsx index 6202aefcb..6081fcac6 100644 --- a/src/Infiltration/ui/BackwardGame.tsx +++ b/src/Infiltration/ui/BackwardGame.tsx @@ -7,6 +7,9 @@ import { random } from "../utils"; import { interpolate } from "./Difficulty"; import { BlinkingCursor } from "./BlinkingCursor"; import Typography from "@mui/material/Typography"; +import { KEY } from "../../utils/helpers/keyCodes"; +import { Player } from "../../Player"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; interface Difficulty { [key: string]: number; @@ -33,16 +36,26 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement { const timer = difficulty.timer; const [answer] = useState(makeAnswer(difficulty)); const [guess, setGuess] = useState(""); + const hasAugment = Player.hasAugmentation(AugmentationNames.ReverseDictionary, true); function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); - if (event.key === "Backspace") return; + if (event.key === KEY.BACKSPACE) return; const nextGuess = guess + event.key.toUpperCase(); if (!answer.startsWith(nextGuess)) props.onFailure(); else if (answer === nextGuess) props.onSuccess(); else setGuess(nextGuess); } + interface AnswerStyle { + transform?: string; + } + + const answerStyle: AnswerStyle = { transform: "scaleX(-1)" }; + if (hasAugment) { + delete answerStyle.transform; + } + return ( @@ -51,7 +64,7 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement { - {answer} + {answer} diff --git a/src/Infiltration/ui/BracketGame.tsx b/src/Infiltration/ui/BracketGame.tsx index 9bad60379..72b3ecad4 100644 --- a/src/Infiltration/ui/BracketGame.tsx +++ b/src/Infiltration/ui/BracketGame.tsx @@ -7,6 +7,9 @@ import { random } from "../utils"; import { interpolate } from "./Difficulty"; import { BlinkingCursor } from "./BlinkingCursor"; import Typography from "@mui/material/Typography"; +import { Player } from "../../Player"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { KEY } from "../../utils/helpers/keyCodes"; interface Difficulty { [key: string]: number; @@ -29,28 +32,32 @@ const difficulties: { function generateLeftSide(difficulty: Difficulty): string { let str = ""; + const options = [KEY.OPEN_BRACKET, KEY.LESS_THAN, KEY.OPEN_PARENTHESIS, KEY.OPEN_BRACE]; + if (Player.hasAugmentation(AugmentationNames.IntellisenseModule, true)) { + options.splice(0, 1); + } const length = random(difficulty.min, difficulty.max); for (let i = 0; i < length; i++) { - str += ["[", "<", "(", "{"][Math.floor(Math.random() * 4)]; + str += options[Math.floor(Math.random() * 4)]; } return str; } function getChar(event: KeyboardEvent): string { - if (event.key === ")") return ")"; - if (event.key === "]") return "]"; - if (event.key === "}") return "}"; - if (event.key === ">") return ">"; + if (event.key === KEY.CLOSE_PARENTHESIS) return KEY.CLOSE_PARENTHESIS; + if (event.key === KEY.CLOSE_BRACKET) return KEY.CLOSE_BRACKET; + if (event.key === KEY.CLOSE_BRACE) return KEY.CLOSE_BRACE; + if (event.key === KEY.GREATER_THAN) return KEY.GREATER_THAN; return ""; } function match(left: string, right: string): boolean { return ( - (left === "[" && right === "]") || - (left === "<" && right === ">") || - (left === "(" && right === ")") || - (left === "{" && right === "}") + (left === KEY.OPEN_BRACKET && right === KEY.CLOSE_BRACKET) || + (left === KEY.LESS_THAN && right === KEY.GREATER_THAN) || + (left === KEY.OPEN_PARENTHESIS && right === KEY.CLOSE_PARENTHESIS) || + (left === KEY.OPEN_BRACE && right === KEY.CLOSE_BRACE) ); } diff --git a/src/Infiltration/ui/BribeGame.tsx b/src/Infiltration/ui/BribeGame.tsx index e5fa424df..9a91e8cf4 100644 --- a/src/Infiltration/ui/BribeGame.tsx +++ b/src/Infiltration/ui/BribeGame.tsx @@ -1,10 +1,15 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import Grid from "@mui/material/Grid"; import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; import { GameTimer } from "./GameTimer"; import { interpolate } from "./Difficulty"; import Typography from "@mui/material/Typography"; +import { KEY } from "../../utils/helpers/keyCodes"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { Player } from "../../Player"; +import { Settings } from "../../Settings/Settings"; +import { downArrowSymbol, upArrowSymbol } from "../utils"; interface Difficulty { [key: string]: number; @@ -29,20 +34,40 @@ export function BribeGame(props: IMinigameProps): React.ReactElement { interpolate(difficulties, props.difficulty, difficulty); const timer = difficulty.timer; const [choices] = useState(makeChoices(difficulty)); + const [correctIndex, setCorrectIndex] = useState(0); const [index, setIndex] = useState(0); + const currentChoice = choices[index]; + + useEffect(() => { + setCorrectIndex(choices.findIndex((choice) => positive.includes(choice))); + }, [choices]); + + const defaultColor = Settings.theme.primary; + const disabledColor = Settings.theme.disabled; + let upColor = defaultColor; + let downColor = defaultColor; + let choiceColor = defaultColor; + const hasAugment = Player.hasAugmentation(AugmentationNames.AmuletOfPersuasion, true); + + if (hasAugment) { + upColor = correctIndex < index ? upColor : disabledColor; + downColor = correctIndex > index ? upColor : disabledColor; + choiceColor = correctIndex == index ? Settings.theme.success : disabledColor; + } function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); + const k = event.key; - if (k === " ") { - if (positive.includes(choices[index])) props.onSuccess(); + if (k === KEY.SPACE) { + if (positive.includes(currentChoice)) props.onSuccess(); else props.onFailure(); return; } let newIndex = index; - if (["ArrowUp", "w", "ArrowRight", "d"].includes(k)) newIndex++; - if (["ArrowDown", "s", "ArrowLeft", "a"].includes(k)) newIndex--; + if ([KEY.UP_ARROW, KEY.W, KEY.RIGHT_ARROW, KEY.D].map((k) => k as string).includes(k)) newIndex++; + if ([KEY.DOWN_ARROW, KEY.S, KEY.LEFT_ARROW, KEY.A].map((k) => k as string).includes(k)) newIndex--; while (newIndex < 0) newIndex += choices.length; while (newIndex > choices.length - 1) newIndex -= choices.length; setIndex(newIndex); @@ -56,14 +81,14 @@ export function BribeGame(props: IMinigameProps): React.ReactElement { - - ↑ + + {upArrowSymbol} - - {choices[index]} + + {currentChoice} - - ↓ + + {downArrowSymbol} diff --git a/src/Infiltration/ui/CheatCodeGame.tsx b/src/Infiltration/ui/CheatCodeGame.tsx index 68fd61329..d1f20c784 100644 --- a/src/Infiltration/ui/CheatCodeGame.tsx +++ b/src/Infiltration/ui/CheatCodeGame.tsx @@ -3,9 +3,19 @@ import Grid from "@mui/material/Grid"; import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; import { GameTimer } from "./GameTimer"; -import { random, getArrow } from "../utils"; +import { + random, + getArrow, + getInverseArrow, + leftArrowSymbol, + rightArrowSymbol, + upArrowSymbol, + downArrowSymbol, +} from "../utils"; import { interpolate } from "./Difficulty"; import Typography from "@mui/material/Typography"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { Player } from "../../Player"; interface Difficulty { [key: string]: number; @@ -32,10 +42,11 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement { const timer = difficulty.timer; const [code] = useState(generateCode(difficulty)); const [index, setIndex] = useState(0); + const hasAugment = Player.hasAugmentation(AugmentationNames.LameSharkRepository, true); function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); - if (code[index] !== getArrow(event)) { + if (code[index] !== getArrow(event) || (hasAugment && getInverseArrow(event))) { props.onFailure(); return; } @@ -56,7 +67,7 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement { } function generateCode(difficulty: Difficulty): string { - const arrows = ["←", "→", "↑", "↓"]; + const arrows = [leftArrowSymbol, rightArrowSymbol, upArrowSymbol, downArrowSymbol]; let code = ""; for (let i = 0; i < random(difficulty.min, difficulty.max); i++) { let arrow = arrows[Math.floor(4 * Math.random())]; diff --git a/src/Infiltration/ui/Cyberpunk2077Game.tsx b/src/Infiltration/ui/Cyberpunk2077Game.tsx index d0c8736b6..d86211e24 100644 --- a/src/Infiltration/ui/Cyberpunk2077Game.tsx +++ b/src/Infiltration/ui/Cyberpunk2077Game.tsx @@ -4,8 +4,12 @@ import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; import { GameTimer } from "./GameTimer"; import { interpolate } from "./Difficulty"; -import { getArrow } from "../utils"; +import { downArrowSymbol, getArrow, leftArrowSymbol, rightArrowSymbol, upArrowSymbol } from "../utils"; import Typography from "@mui/material/Typography"; +import { KEY } from "../../utils/helpers/keyCodes"; +import { Settings } from "../../Settings/Settings"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { Player } from "../../Player"; interface Difficulty { [key: string]: number; @@ -32,25 +36,26 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement { interpolate(difficulties, props.difficulty, difficulty); const timer = difficulty.timer; const [grid] = useState(generatePuzzle(difficulty)); - const [answer] = useState(generateAnswer(grid, difficulty)); - const [index, setIndex] = useState(0); + const [answers] = useState(generateAnswers(grid, difficulty)); + const [currentAnswerIndex, setCurrentAnswerIndex] = useState(0); const [pos, setPos] = useState([0, 0]); + const hasAugment = Player.hasAugmentation(AugmentationNames.CyberDecoder, true); function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); const move = [0, 0]; const arrow = getArrow(event); switch (arrow) { - case "↑": + case upArrowSymbol: move[1]--; break; - case "←": + case leftArrowSymbol: move[0]--; break; - case "↓": + case downArrowSymbol: move[1]++; break; - case "→": + case rightArrowSymbol: move[0]++; break; } @@ -59,15 +64,15 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement { next[1] = (next[1] + grid.length) % grid.length; setPos(next); - if (event.key === " ") { + if (event.key === KEY.SPACE) { const selected = grid[pos[1]][pos[0]]; - const expected = answer[index]; + const expected = answers[currentAnswerIndex]; if (selected !== expected) { props.onFailure(); return; } - setIndex(index + 1); - if (answer.length === index + 1) props.onSuccess(); + setCurrentAnswerIndex(currentAnswerIndex + 1); + if (answers.length === currentAnswerIndex + 1) props.onSuccess(); } } @@ -77,17 +82,17 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement { Match the symbols! - + Targets:{" "} - {answer.map((a, i) => { - if (i == index) + {answers.map((a, i) => { + if (i == currentAnswerIndex) return ( {a}  ); return ( - + {a}  ); @@ -98,14 +103,20 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement {
{line.map((cell, x) => { - if (x == pos[0] && y == pos[1]) + const isCorrectAnswer = cell === answers[currentAnswerIndex]; + + if (x == pos[0] && y == pos[1]) { + const selectOptionColor = hasAugment && isCorrectAnswer ? Settings.theme.success : "blue"; return ( - + {cell}  ); + } + + const optionColor = hasAugment && isCorrectAnswer ? Settings.theme.success : Settings.theme.primary; return ( - + {cell}  ); @@ -120,12 +131,12 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement { ); } -function generateAnswer(grid: string[][], difficulty: Difficulty): string[] { - const answer = []; +function generateAnswers(grid: string[][], difficulty: Difficulty): string[] { + const answers = []; for (let i = 0; i < Math.round(difficulty.symbols); i++) { - answer.push(grid[Math.floor(Math.random() * grid.length)][Math.floor(Math.random() * grid[0].length)]); + answers.push(grid[Math.floor(Math.random() * grid.length)][Math.floor(Math.random() * grid[0].length)]); } - return answer; + return answers; } function randChar(): string { diff --git a/src/Infiltration/ui/InfiltrationRoot.tsx b/src/Infiltration/ui/InfiltrationRoot.tsx index 54c78c019..ec1b3c0b7 100644 --- a/src/Infiltration/ui/InfiltrationRoot.tsx +++ b/src/Infiltration/ui/InfiltrationRoot.tsx @@ -42,7 +42,6 @@ export function InfiltrationRoot(props: IProps): React.ReactElement { const startingDifficulty = props.location.infiltrationData.startingSecurityLevel; const difficulty = calcDifficulty(player, startingDifficulty); const reward = calcReward(player, startingDifficulty); - console.log(`${difficulty} ${reward}`); function cancel(): void { router.toCity(); diff --git a/src/Infiltration/ui/MinesweeperGame.tsx b/src/Infiltration/ui/MinesweeperGame.tsx index 532c654ee..18a87d996 100644 --- a/src/Infiltration/ui/MinesweeperGame.tsx +++ b/src/Infiltration/ui/MinesweeperGame.tsx @@ -4,8 +4,11 @@ import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; import { GameTimer } from "./GameTimer"; import { interpolate } from "./Difficulty"; -import { getArrow } from "../utils"; +import { downArrowSymbol, getArrow, leftArrowSymbol, rightArrowSymbol, upArrowSymbol } from "../utils"; import Typography from "@mui/material/Typography"; +import { KEY } from "../../utils/helpers/keyCodes"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { Player } from "../../Player"; interface Difficulty { [key: string]: number; @@ -35,23 +38,23 @@ export function MinesweeperGame(props: IMinigameProps): React.ReactElement { const [answer, setAnswer] = useState(generateEmptyField(difficulty)); const [pos, setPos] = useState([0, 0]); const [memoryPhase, setMemoryPhase] = useState(true); - + const hasAugment = Player.hasAugmentation(AugmentationNames.MineDetector, true); function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); if (memoryPhase) return; const move = [0, 0]; const arrow = getArrow(event); switch (arrow) { - case "↑": + case upArrowSymbol: move[1]--; break; - case "←": + case leftArrowSymbol: move[0]--; break; - case "↓": + case downArrowSymbol: move[1]++; break; - case "→": + case rightArrowSymbol: move[0]++; break; } @@ -60,7 +63,7 @@ export function MinesweeperGame(props: IMinigameProps): React.ReactElement { next[1] = (next[1] + minefield.length) % minefield.length; setPos(next); - if (event.key == " ") { + if (event.key == KEY.SPACE) { if (!minefield[pos[1]][pos[0]]) { props.onFailure(); return; @@ -93,6 +96,7 @@ export function MinesweeperGame(props: IMinigameProps): React.ReactElement { } else { if (x == pos[0] && y == pos[1]) return [X] ; if (answer[y][x]) return [.] ; + if (hasAugment && minefield[y][x]) return [?] ; return [ ] ; } })} diff --git a/src/Infiltration/ui/SlashGame.tsx b/src/Infiltration/ui/SlashGame.tsx index 5aa633f78..a0044151d 100644 --- a/src/Infiltration/ui/SlashGame.tsx +++ b/src/Infiltration/ui/SlashGame.tsx @@ -5,6 +5,9 @@ import { KeyHandler } from "./KeyHandler"; import { GameTimer } from "./GameTimer"; import { interpolate } from "./Difficulty"; import Typography from "@mui/material/Typography"; +import { KEY } from "../../utils/helpers/keyCodes"; +import { Player } from "../../Player"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; interface Difficulty { [key: string]: number; @@ -30,13 +33,17 @@ export function SlashGame(props: IMinigameProps): React.ReactElement { function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); - if (event.key !== " ") return; + if (event.key !== KEY.SPACE) return; if (phase !== 2) { props.onFailure(); } else { props.onSuccess(); } } + const hasAugment = Player.hasAugmentation(AugmentationNames.BagOfSand, true); + const phaseZeroTime = Math.random() * 3250 + 1500 - (250 + difficulty.window); + const phaseOneTime = 250; + const timeUntilAttacking = phaseZeroTime + phaseOneTime; useEffect(() => { let id = window.setTimeout(() => { @@ -44,8 +51,8 @@ export function SlashGame(props: IMinigameProps): React.ReactElement { id = window.setTimeout(() => { setPhase(2); id = window.setTimeout(() => setPhase(0), difficulty.window); - }, 250); - }, Math.random() * 3250 + 1500 - (250 + difficulty.window)); + }, phaseOneTime); + }, phaseZeroTime); return () => { clearInterval(id); }; @@ -56,6 +63,14 @@ export function SlashGame(props: IMinigameProps): React.ReactElement { Slash when his guard is down! + {hasAugment ? ( + <> + Guard will drop in... + + + ) : ( + <> + )} {phase === 0 && Guarding ...} {phase === 1 && Preparing?} {phase === 2 && ATTACKING!} diff --git a/src/Infiltration/ui/WireCuttingGame.tsx b/src/Infiltration/ui/WireCuttingGame.tsx index 875f42641..a0327fec2 100644 --- a/src/Infiltration/ui/WireCuttingGame.tsx +++ b/src/Infiltration/ui/WireCuttingGame.tsx @@ -6,6 +6,10 @@ import { KeyHandler } from "./KeyHandler"; import { GameTimer } from "./GameTimer"; import { random } from "../utils"; import { interpolate } from "./Difficulty"; +import { KEY } from "../../utils/helpers/keyCodes"; +import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { Player } from "../../Player"; +import { Settings } from "../../Settings/Settings"; interface Difficulty { [key: string]: number; @@ -27,7 +31,7 @@ const difficulties: { Impossible: { timer: 4000, wiresmin: 9, wiresmax: 9, rules: 4 }, }; -const types = ["|", ".", "/", "-", "█", "#"]; +const types = [KEY.PIPE, KEY.DOT, KEY.FORWARD_SLASH, KEY.HYPHEN, "█", KEY.HASH]; const colors = ["red", "#FFC107", "blue", "white"]; @@ -56,10 +60,15 @@ export function WireCuttingGame(props: IMinigameProps): React.ReactElement { rules: 0, }; interpolate(difficulties, props.difficulty, difficulty); - const timer = difficulty.timer; + const timer = 99999; const [wires] = useState(generateWires(difficulty)); const [cutWires, setCutWires] = useState(new Array(wires.length).fill(false)); const [questions] = useState(generateQuestion(wires, difficulty)); + const hasAugment = Player.hasAugmentation(AugmentationNames.WireCuttingManual, true); + + function checkWire(wireNum: number): boolean { + return questions.some((q) => q.shouldCut(wires[wireNum - 1], wireNum - 1)); + } function press(this: Document, event: KeyboardEvent): void { event.preventDefault(); @@ -69,7 +78,7 @@ export function WireCuttingGame(props: IMinigameProps): React.ReactElement { setCutWires((old) => { const next = [...old]; next[wireNum - 1] = true; - if (!questions.some((q) => q.shouldCut(wires[wireNum - 1], wireNum - 1))) { + if (!checkWire(wireNum)) { props.onFailure(); } @@ -107,10 +116,14 @@ export function WireCuttingGame(props: IMinigameProps): React.ReactElement {
{wires.map((wire, j) => { - if ((i === 3 || i === 4) && cutWires[j]) + if ((i === 3 || i === 4) && cutWires[j]) { return       ; + } + const isCorrectWire = checkWire(j); + const wireColor = + hasAugment && !isCorrectWire ? Settings.theme.disabled : wire.colors[i % wire.colors.length]; return ( - + |{wire.tpe}|    ); diff --git a/src/Infiltration/utils.ts b/src/Infiltration/utils.ts index cdbce68d9..d338423d5 100644 --- a/src/Infiltration/utils.ts +++ b/src/Infiltration/utils.ts @@ -1,21 +1,46 @@ +import { KEY } from "../utils/helpers/keyCodes"; + export function random(min: number, max: number): number { return Math.random() * (max - min) + min; } +export const upArrowSymbol = "↑"; +export const downArrowSymbol = "↑"; +export const leftArrowSymbol = "↑"; +export const rightArrowSymbol = "↑"; + export function getArrow(event: KeyboardEvent): string { switch (event.key) { - case "ArrowUp": - case "w": - return "↑"; - case "ArrowLeft": - case "a": - return "←"; - case "ArrowDown": - case "s": - return "↓"; - case "ArrowRight": - case "d": - return "→"; + case KEY.UP_ARROW: + case KEY.W: + return upArrowSymbol; + case KEY.LEFT_ARROW: + case KEY.A: + return leftArrowSymbol; + case KEY.DOWN_ARROW: + case KEY.S: + return downArrowSymbol; + case KEY.RIGHT_ARROW: + case KEY.D: + return rightArrowSymbol; + } + return ""; +} + +export function getInverseArrow(event: KeyboardEvent): string { + switch (event.key) { + case KEY.DOWN_ARROW: + case KEY.S: + return upArrowSymbol; + case KEY.RIGHT_ARROW: + case KEY.D: + return leftArrowSymbol; + case KEY.UP_ARROW: + case KEY.W: + return downArrowSymbol; + case KEY.LEFT_ARROW: + case KEY.A: + return rightArrowSymbol; } return ""; } diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index f84623535..35d2dd93a 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -262,7 +262,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Select previous command. - if (event.key === KEY.UPARROW || (Settings.EnableBashHotkeys && event.key === "p" && event.ctrlKey)) { + if (event.key === KEY.UP_ARROW || (Settings.EnableBashHotkeys && event.key === KEY.P && event.ctrlKey)) { if (Settings.EnableBashHotkeys) { event.preventDefault(); } @@ -290,7 +290,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Select next command - if (event.key === KEY.DOWNARROW || (Settings.EnableBashHotkeys && event.key === "m" && event.ctrlKey)) { + if (event.key === KEY.DOWN_ARROW || (Settings.EnableBashHotkeys && event.key === KEY.M && event.ctrlKey)) { if (Settings.EnableBashHotkeys) { event.preventDefault(); } diff --git a/src/utils/helpers/keyCodes.ts b/src/utils/helpers/keyCodes.ts index a03290a26..942ce80b0 100644 --- a/src/utils/helpers/keyCodes.ts +++ b/src/utils/helpers/keyCodes.ts @@ -8,10 +8,27 @@ export enum KEY { ENTER = "Enter", ESC = "Escape", TAB = "Tab", - UPARROW = "ArrowUp", - DOWNARROW = "ArrowDown", - LEFTARROW = "ArrowLeft", - RIGHTARROW = "ArrowRight", + SPACE = " ", + BACKSPACE = "Backspace", + UP_ARROW = "ArrowUp", + DOWN_ARROW = "ArrowDown", + LEFT_ARROW = "ArrowLeft", + RIGHT_ARROW = "ArrowRight", + + OPEN_BRACKET = "[", + CLOSE_BRACKET = "]", + LESS_THAN = "<", + GREATER_THAN = ">", + OPEN_PARENTHESIS = "(", + CLOSE_PARENTHESIS = ")", + OPEN_BRACE = "{", + CLOSE_BRACE = "}", + + PIPE = "|", + DOT = ".", + FORWARD_SLASH = "/", + HYPHEN = "-", + HASH = "#", k0 = "0", k1 = "1",