Merge pull request #3156 from Master-Guy/issues/2308

Changed .keyCode to .key for files in "src"
This commit is contained in:
hydroflame 2022-03-20 14:22:38 -04:00 committed by GitHub
commit 1a339a9611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 119 additions and 98 deletions

@ -1,5 +1,6 @@
import React, { useState, useRef, useEffect } from "react";
import { IBladeburner } from "../IBladeburner";
import { KEY } from "../../utils/helpers/keyCodes";
import { IPlayer } from "../../PersonObjects/IPlayer";
import Paper from "@mui/material/Paper";
@ -76,7 +77,7 @@ export function Console(props: IProps): React.ReactElement {
}, []);
function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) {
if (event.key === KEY.ENTER) {
event.preventDefault();
if (command.length > 0) {
props.bladeburner.postToConsole("> " + command);
@ -88,7 +89,7 @@ export function Console(props: IProps): React.ReactElement {
const consoleHistory = props.bladeburner.consoleHistory;
if (event.keyCode === 38) {
if (event.key === KEY.S) {
// up
let i = consoleHistoryIndex;
const len = consoleHistory.length;
@ -108,7 +109,7 @@ export function Console(props: IProps): React.ReactElement {
setCommand(prevCommand);
}
if (event.keyCode === 40) {
if (event.key === KEY.DOWNARROW) {
const i = consoleHistoryIndex;
const len = consoleHistory.length;

@ -8,6 +8,7 @@ import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import { BuyBackShares } from '../Actions';
import { dialogBoxCreate } from '../../ui/React/DialogBox';
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
@ -69,7 +70,7 @@ export function BuybackSharesModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) buy();
if (event.key === KEY.ENTER) buy();
}
return (

@ -11,6 +11,7 @@ import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import Box from "@mui/material/Box";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
setDivisionName: (name: string) => void;
@ -53,7 +54,7 @@ export function ExpandIndustryTab(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) newIndustry();
if (event.key === KEY.ENTER) newIndustry();
}
function onIndustryChange(event: SelectChangeEvent<string>): void {

@ -7,6 +7,7 @@ import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
@ -45,7 +46,7 @@ export function GoPublicModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) goPublic();
if (event.key === KEY.ENTER) goPublic();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -7,6 +7,7 @@ import { useCorporation } from "./Context";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
onClose: () => void;
@ -32,7 +33,7 @@ export function IssueDividendsModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) issueDividends();
if (event.key === KEY.ENTER) issueDividends();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -8,6 +8,7 @@ import { useCorporation } from "./Context";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IEffectTextProps {
shares: number | null;
@ -93,7 +94,7 @@ export function IssueNewSharesModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) issueNewShares();
if (event.key === KEY.ENTER) issueNewShares();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -5,6 +5,7 @@ import { Modal } from "../../ui/React/Modal";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
@ -25,7 +26,7 @@ export function LimitProductProductionModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) limitProductProduction();
if (event.key === KEY.ENTER) limitProductProduction();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -9,6 +9,7 @@ import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import MenuItem from "@mui/material/MenuItem";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
@ -165,7 +166,7 @@ export function MakeProductModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) makeProduct();
if (event.key === KEY.ENTER) makeProduct();
}
return (

@ -10,6 +10,7 @@ import { useCorporation, useDivision } from "./Context";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IBulkPurchaseTextProps {
warehouse: Warehouse;
@ -68,7 +69,7 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) bulkPurchase();
if (event.key === KEY.ENTER) bulkPurchase();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
@ -123,7 +124,7 @@ export function PurchaseMaterialModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) purchaseMaterial();
if (event.key === KEY.ENTER) purchaseMaterial();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -6,6 +6,7 @@ import { Modal } from "../../ui/React/Modal";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
function initialPrice(mat: Material): string {
let val = mat.sCost ? mat.sCost + "" : "";
@ -46,7 +47,7 @@ export function SellMaterialModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) sellMaterial();
if (event.key === KEY.ENTER) sellMaterial();
}
return (

@ -9,6 +9,7 @@ import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import { KEY } from "../../utils/helpers/keyCodes";
function initialPrice(product: Product): string {
let val = product.sCost ? product.sCost + "" : "";
@ -58,7 +59,7 @@ export function SellProductModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) sellProduct();
if (event.key === KEY.ENTER) sellProduct();
}
return (

@ -10,6 +10,7 @@ import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { Money } from "../../ui/React/Money";
import { SellShares } from "../Actions";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
onClose: () => void;
@ -68,7 +69,7 @@ export function SellSharesModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) sell();
if (event.key === KEY.ENTER) sell();
}
return (

@ -10,6 +10,7 @@ import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
@ -57,7 +58,7 @@ export function ThrowPartyModal(props: IProps): React.ReactElement {
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) throwParty();
if (event.key === KEY.ENTER) throwParty();
}
return (

@ -6,6 +6,7 @@ import { Modal } from "../../ui/React/Modal";
import { use } from "../../ui/Context";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
import { FactionNames } from "../data/FactionNames";
interface IProps {
@ -38,7 +39,7 @@ export function CreateGangModal(props: IProps): React.ReactElement {
}
function onKeyUp(event: React.KeyboardEvent): void {
if (event.keyCode === 13) createGang();
if (event.key === KEY.ENTER) createGang();
}
return (

@ -8,6 +8,7 @@ import { useGang } from "./Context";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IRecruitPopupProps {
open: boolean;
@ -34,7 +35,7 @@ export function RecruitModal(props: IRecruitPopupProps): React.ReactElement {
}
function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) recruit();
if (event.key === KEY.ENTER) recruit();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -10,6 +10,7 @@ import { use } from "../../ui/Context";
import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes";
interface IProps {
open: boolean;
@ -29,7 +30,7 @@ export function PurchaseServerModal(props: IProps): React.ReactElement {
}
function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.keyCode === 13) tryToPurchaseServer();
if (event.key === KEY.ENTER) tryToPurchaseServer();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { KEY } from "../../utils/helpers/keyCodes";
import clsx from "clsx";
import { styled, Theme, CSSObject } from "@mui/material/styles";
import createStyles from "@mui/styles/createStyles";
@ -53,7 +54,6 @@ import { Settings } from "../../Settings/Settings";
import { redPillFlag } from "../../RedPill";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { KEY } from "../../utils/helpers/keyCodes";
import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot";
import { InvitationsSeen } from "../../Faction/ui/FactionsRoot";
import { hash } from "../../hash/hash";
@ -276,54 +276,54 @@ export function SidebarRoot(props: IProps): React.ReactElement {
function handleShortcuts(this: Document, event: KeyboardEvent): any {
if (Settings.DisableHotkeys) return;
if ((props.player.isWorking && props.player.focus) || redPillFlag) return;
if (event.keyCode == KEY.T && event.altKey) {
if (event.key === "t" && event.altKey) {
event.preventDefault();
clickTerminal();
} else if (event.keyCode === KEY.C && event.altKey) {
} else if (event.key === KEY.C && event.altKey) {
event.preventDefault();
clickStats();
} else if (event.keyCode === KEY.E && event.altKey) {
} else if (event.key === KEY.E && event.altKey) {
event.preventDefault();
clickScriptEditor();
} else if (event.keyCode === KEY.S && event.altKey) {
} else if (event.key === KEY.S && event.altKey) {
event.preventDefault();
clickActiveScripts();
} else if (event.keyCode === KEY.H && event.altKey) {
} else if (event.key === KEY.H && event.altKey) {
event.preventDefault();
clickHacknet();
} else if (event.keyCode === KEY.W && event.altKey) {
} else if (event.key === KEY.W && event.altKey) {
event.preventDefault();
clickCity();
} else if (event.keyCode === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey && canJob) {
} else if (event.key === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey && canJob) {
// ctrl/cmd + alt + j is shortcut to open Chrome dev tools
event.preventDefault();
clickJob();
} else if (event.keyCode === KEY.R && event.altKey) {
} else if (event.key === KEY.R && event.altKey) {
event.preventDefault();
clickTravel();
} else if (event.keyCode === KEY.P && event.altKey) {
} else if (event.key === KEY.P && event.altKey) {
event.preventDefault();
clickCreateProgram();
} else if (event.keyCode === KEY.F && event.altKey) {
} else if (event.key === KEY.F && event.altKey) {
if (props.page == Page.Terminal && Settings.EnableBashHotkeys) {
return;
}
event.preventDefault();
clickFactions();
} else if (event.keyCode === KEY.A && event.altKey) {
} else if (event.key === KEY.A && event.altKey) {
event.preventDefault();
clickAugmentations();
} else if (event.keyCode === KEY.U && event.altKey) {
} else if (event.key === KEY.U && event.altKey) {
event.preventDefault();
clickTutorial();
} else if (event.keyCode === KEY.B && event.altKey && props.player.bladeburner) {
} else if (event.key === KEY.B && event.altKey && props.player.bladeburner) {
event.preventDefault();
clickBladeburner();
} else if (event.keyCode === KEY.G && event.altKey && props.player.gang) {
} else if (event.key === KEY.G && event.altKey && props.player.gang) {
event.preventDefault();
clickGang();
}
// if (event.keyCode === KEY.O && event.altKey) {
// if (event.key === KEY.O && event.altKey) {
// event.preventDefault();
// gameOptionsBoxOpen();
// }

@ -180,13 +180,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
useEffect(() => {
function keyDown(this: Document, event: KeyboardEvent): void {
if (terminal.contractOpen) return;
if (terminal.action !== null && event.keyCode === KEY.C && event.ctrlKey) {
if (terminal.action !== null && event.key === KEY.c && event.ctrlKey) {
terminal.finishAction(router, player, true);
return;
}
const ref = terminalInput.current;
if (event.ctrlKey || event.metaKey) return;
if (event.keyCode === KEY.C && (event.ctrlKey || event.metaKey)) return; // trying to copy
if (event.key === KEY.C && (event.ctrlKey || event.metaKey)) return; // trying to copy
if (ref) ref.focus();
}
@ -196,7 +196,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
async function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): Promise<void> {
// Run command.
if (event.keyCode === KEY.ENTER && value !== "") {
if (event.key === KEY.ENTER && value !== "") {
event.preventDefault();
terminal.print(`[${player.getCurrentServer().hostname} ~${terminal.cwd()}]> ${value}`);
terminal.executeCommands(router, player, value);
@ -205,7 +205,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
}
// Autocomplete
if (event.keyCode === KEY.TAB && value !== "") {
if (event.key === KEY.Tab && value !== "") {
event.preventDefault();
let copy = value;
@ -256,13 +256,13 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
}
// Clear screen.
if (event.keyCode === KEY.L && event.ctrlKey) {
if (event.key === KEY.L && event.ctrlKey) {
event.preventDefault();
terminal.clear();
}
// Select previous command.
if (event.keyCode === KEY.UPARROW || (Settings.EnableBashHotkeys && event.keyCode === KEY.P && event.ctrlKey)) {
if (event.key === KEY.UPARROW || (Settings.EnableBashHotkeys && event.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.keyCode === KEY.DOWNARROW || (Settings.EnableBashHotkeys && event.keyCode === KEY.M && event.ctrlKey)) {
if (event.key === KEY.DOWNARROW || (Settings.EnableBashHotkeys && event.key === "m" && event.ctrlKey)) {
if (Settings.EnableBashHotkeys) {
event.preventDefault();
}
@ -317,57 +317,57 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
// Extra Bash Emulation Hotkeys, must be enabled through options
if (Settings.EnableBashHotkeys) {
if (event.keyCode === KEY.A && event.ctrlKey) {
if (event.key === KEY.A && event.ctrlKey) {
event.preventDefault();
moveTextCursor("home");
}
if (event.keyCode === KEY.E && event.ctrlKey) {
if (event.key === KEY.E && event.ctrlKey) {
event.preventDefault();
moveTextCursor("end");
}
if (event.keyCode === KEY.B && event.ctrlKey) {
if (event.key === KEY.B && event.ctrlKey) {
event.preventDefault();
moveTextCursor("prevchar");
}
if (event.keyCode === KEY.B && event.altKey) {
if (event.key === KEY.B && event.altKey) {
event.preventDefault();
moveTextCursor("prevword");
}
if (event.keyCode === KEY.F && event.ctrlKey) {
if (event.key === KEY.F && event.ctrlKey) {
event.preventDefault();
moveTextCursor("nextchar");
}
if (event.keyCode === KEY.F && event.altKey) {
if (event.key === KEY.F && event.altKey) {
event.preventDefault();
moveTextCursor("nextword");
}
if ((event.keyCode === KEY.H || event.keyCode === KEY.D) && event.ctrlKey) {
if ((event.key === KEY.H || event.key === KEY.D) && event.ctrlKey) {
modifyInput("backspace");
event.preventDefault();
}
if (event.keyCode === KEY.W && event.ctrlKey) {
if (event.key === KEY.W && event.ctrlKey) {
event.preventDefault();
modifyInput("deletewordbefore");
}
if (event.keyCode === KEY.D && event.altKey) {
if (event.key === KEY.D && event.altKey) {
event.preventDefault();
modifyInput("deletewordafter");
}
if (event.keyCode === KEY.U && event.ctrlKey) {
if (event.key === KEY.U && event.ctrlKey) {
event.preventDefault();
modifyInput("clearbefore");
}
if (event.keyCode === KEY.K && event.ctrlKey) {
if (event.key === KEY.K && event.ctrlKey) {
event.preventDefault();
modifyInput("clearafter");
}

@ -37,7 +37,7 @@ export function CodingContractModal(): React.ReactElement {
// whatever ...
const value = (event.target as any).value;
if (event.keyCode === KEY.ENTER && value !== "") {
if (event.key === KEY.ENTER && value !== "") {
event.preventDefault();
props.onAttempt(answer);
setAnswer("");

@ -6,6 +6,7 @@ import Button from "@mui/material/Button";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import { KEY } from "../../utils/helpers/keyCodes";
export const PromptEvent = new EventEmitter<[Prompt]>();
@ -93,7 +94,7 @@ function PromptMenuText({ resolve }: IContentProps): React.ReactElement {
const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
event.stopPropagation();
if (event.key === "Enter") {
if (event.key === KEY.ENTER) {
event.preventDefault();
submit();
}

@ -3,49 +3,53 @@ import { IMap } from "../../types";
/**
* Keyboard key codes
*/
export const KEY: IMap<number> = {
CTRL: 17,
DOWNARROW: 40,
ENTER: 13,
ESC: 27,
TAB: 9,
UPARROW: 38,
export const KEY: IMap<string> = {
//SHIFT: 16, // Check by `&& event.shiftKey`
//CTRL: 17, // Check by `&& event.ctrlKey`
//ALT: 18, // Check by `&& event.altKey`
ENTER: "Enter",
ESC: "Escape",
TAB: "Tab",
UPARROW: "ArrowUp",
DOWNARROW: "ArrowDown",
LEFTARROW: "ArrowLeft",
RIGHTARROW: "ArrowRight",
"0": 48,
"1": 49,
"2": 50,
"3": 51,
"4": 52,
"5": 53,
"6": 54,
"7": 55,
"8": 56,
"9": 57,
"0": "0",
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"9": "9",
A: 65,
B: 66,
C: 67,
D: 68,
E: 69,
F: 70,
G: 71,
H: 72,
I: 73,
J: 74,
K: 75,
L: 76,
M: 77,
N: 78,
O: 79,
P: 80,
Q: 81,
R: 82,
S: 83,
T: 84,
U: 85,
V: 86,
W: 87,
X: 88,
Y: 89,
Z: 90,
A: "a",
B: "b",
C: "c",
D: "d",
E: "e",
F: "f",
G: "g",
H: "h",
I: "i",
J: "j",
K: "k",
L: "l",
M: "m",
N: "n",
O: "o",
P: "p",
Q: "q",
R: "r",
S: "s",
T: "t",
U: "u",
V: "v",
W: "w",
X: "x",
Y: "y",
Z: "z",
};