From a21b1029d7c32fc79b9512339b4c2a1edb74e1a0 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Mon, 12 Sep 2022 18:00:09 -0400 Subject: [PATCH] No more player/router context --- src/Arcade/ui/ArcadeRoot.tsx | 5 +- src/Arcade/ui/BBCabinet.tsx | 5 +- src/Augmentation/ui/AugmentationsRoot.tsx | 11 +- .../ui/InstalledAugmentations.tsx | 5 +- .../ui/PurchaseAugmentationModal.tsx | 6 +- src/BitNode/ui/BitFlumeModal.tsx | 5 +- .../ui/BitnodeMultipliersDescription.tsx | 17 +- src/BitNode/ui/BitverseRoot.tsx | 26 +-- src/BitNode/ui/PortalModal.tsx | 7 +- src/Bladeburner/ui/ActionLevel.tsx | 3 - src/Bladeburner/ui/BlackOpPage.tsx | 5 +- src/Bladeburner/ui/BladeburnerCinematic.tsx | 5 +- src/Bladeburner/ui/BladeburnerRoot.tsx | 8 +- src/Bladeburner/ui/StartButton.tsx | 5 +- src/Company/ui/QuitJobModal.tsx | 5 +- src/Corporation/ICorporation.ts | 5 +- src/Corporation/ui/CorporationRoot.tsx | 5 +- src/Corporation/ui/Industry.tsx | 2 - src/Corporation/ui/Overview.tsx | 8 +- .../ui/modals/BribeFactionModal.tsx | 9 +- .../ui/modals/BuybackSharesModal.tsx | 5 +- .../ui/modals/CreateCorporationModal.tsx | 23 ++- src/Corporation/ui/modals/SellSharesModal.tsx | 2 - src/Crime/Crime.ts | 6 +- src/Exploits/Unclickable.tsx | 5 +- src/Faction/FactionInfo.tsx | 8 +- src/Faction/ui/CreateGangModal.tsx | 9 +- src/Faction/ui/GangButton.tsx | 19 +- src/Faction/ui/InvitationModal.tsx | 5 +- src/GameOptions/ui/GameplayPage.tsx | 5 +- src/Gang/GangMember.ts | 10 +- src/Gang/ui/EquipmentsSubpage.tsx | 11 +- src/Gang/ui/GangRoot.tsx | 7 +- src/Infiltration/ui/Game.tsx | 15 +- src/Infiltration/ui/GameTimer.tsx | 5 +- src/Infiltration/ui/InfiltrationRoot.tsx | 11 +- src/Infiltration/ui/Victory.tsx | 19 +- src/Locations/ui/ApplyToJobButton.tsx | 6 +- src/Locations/ui/City.tsx | 21 +-- src/Locations/ui/CompanyLocation.tsx | 39 ++--- src/Locations/ui/PurchaseServerModal.tsx | 5 +- src/Locations/ui/SlumsLocation.tsx | 101 ++++++----- src/Locations/ui/SpecialLocation.tsx | 86 +++++---- src/Locations/ui/TravelConfirmationModal.tsx | 2 - src/Locations/ui/UniversityLocation.tsx | 12 +- src/NetscriptFunctions/Gang.ts | 2 +- src/NetscriptFunctions/Singularity.ts | 6 +- .../Sleeve/ui/CovenantPurchasesRoot.tsx | 25 ++- src/PersonObjects/Sleeve/ui/SleeveRoot.tsx | 5 +- src/RedPill.tsx | 8 +- src/ui/ActiveScripts/ScriptProduction.tsx | 7 +- src/ui/CharacterStats.tsx | 165 +++++++++--------- src/ui/Context.ts | 19 -- src/ui/GameRoot.tsx | 4 +- src/ui/React/CharacterOverview.tsx | 115 ++++++------ src/ui/React/Overview.tsx | 5 +- 56 files changed, 418 insertions(+), 527 deletions(-) delete mode 100644 src/ui/Context.ts diff --git a/src/Arcade/ui/ArcadeRoot.tsx b/src/Arcade/ui/ArcadeRoot.tsx index efb1f92d9..ff353313e 100644 --- a/src/Arcade/ui/ArcadeRoot.tsx +++ b/src/Arcade/ui/ArcadeRoot.tsx @@ -2,7 +2,7 @@ import React, { useState } from "react"; import { BBCabinetRoot } from "./BBCabinet"; import Button from "@mui/material/Button"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { AlertEvents } from "../../ui/React/AlertManager"; enum Page { @@ -11,11 +11,10 @@ enum Page { } export function ArcadeRoot(): React.ReactElement { - const player = use.Player(); const [page, setPage] = useState(Page.None); function mbBurner2000(): void { - if (player.sourceFileLvl(1) === 0) { + if (Player.sourceFileLvl(1) === 0) { AlertEvents.emit("This machine is broken."); } else { setPage(Page.Megabyteburner2000); diff --git a/src/Arcade/ui/BBCabinet.tsx b/src/Arcade/ui/BBCabinet.tsx index b0627b2f0..1b3c95a85 100644 --- a/src/Arcade/ui/BBCabinet.tsx +++ b/src/Arcade/ui/BBCabinet.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from "react"; import Typography from "@mui/material/Typography"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { Exploit } from "../../Exploits/Exploit"; const metaBB = "https://bitburner-official.github.io/bitburner-legacy/"; @@ -12,11 +12,10 @@ const style = { }; export function BBCabinetRoot(): React.ReactElement { - const player = use.Player(); useEffect(() => { window.addEventListener("message", function (this: Window, ev: MessageEvent) { if (ev.isTrusted && ev.origin == "https://bitburner-official.github.io" && ev.data) { - player.giveExploit(Exploit.TrueRecursion); + Player.giveExploit(Exploit.TrueRecursion); } }); }); diff --git a/src/Augmentation/ui/AugmentationsRoot.tsx b/src/Augmentation/ui/AugmentationsRoot.tsx index f5d024c86..912ebf540 100644 --- a/src/Augmentation/ui/AugmentationsRoot.tsx +++ b/src/Augmentation/ui/AugmentationsRoot.tsx @@ -10,8 +10,6 @@ import { PurchasedAugmentations } from "./PurchasedAugmentations"; import { SourceFilesElement } from "./SourceFiles"; import { canGetBonus } from "../../ExportBonus"; -import { use } from "../../ui/Context"; - import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import Tooltip from "@mui/material/Tooltip"; @@ -86,7 +84,6 @@ interface IProps { export function AugmentationsRoot(props: IProps): React.ReactElement { const [installOpen, setInstallOpen] = useState(false); - const player = use.Player(); const setRerender = useState(false)[1]; function rerender(): void { setRerender((o) => !o); @@ -179,7 +176,7 @@ export function AugmentationsRoot(props: IProps): React.ReactElement { 'I never asked for this'}> - @@ -191,7 +188,7 @@ export function AugmentationsRoot(props: IProps): React.ReactElement { - {player.queuedAugmentations.length > 0 ? ( + {Player.queuedAugmentations.length > 0 ? ( @@ -208,8 +205,8 @@ export function AugmentationsRoot(props: IProps): React.ReactElement { my: 1, display: "grid", gridTemplateColumns: `repeat(${ - +!!((player.augmentations.find((e) => e.name === AugmentationNames.NeuroFluxGovernor)?.level ?? 0) > 0) + - +!!(player.entropy > 0) + +!!((Player.augmentations.find((e) => e.name === AugmentationNames.NeuroFluxGovernor)?.level ?? 0) > 0) + + +!!(Player.entropy > 0) }, 1fr)`, gap: 1, }} diff --git a/src/Augmentation/ui/InstalledAugmentations.tsx b/src/Augmentation/ui/InstalledAugmentations.tsx index 1ec34391f..3c06a68a4 100644 --- a/src/Augmentation/ui/InstalledAugmentations.tsx +++ b/src/Augmentation/ui/InstalledAugmentations.tsx @@ -12,14 +12,13 @@ import Tooltip from "@mui/material/Tooltip"; import React, { useState } from "react"; import { OwnedAugmentationsOrderSetting } from "../../Settings/SettingEnums"; import { Settings } from "../../Settings/Settings"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { StaticAugmentations } from "../StaticAugmentations"; import { AugmentationNames } from "../data/AugmentationNames"; export function InstalledAugmentations(): React.ReactElement { const setRerender = useState(true)[1]; - const player = use.Player(); - const sourceAugs = player.augmentations.slice().filter((aug) => aug.name !== AugmentationNames.NeuroFluxGovernor); + const sourceAugs = Player.augmentations.slice().filter((aug) => aug.name !== AugmentationNames.NeuroFluxGovernor); const [selectedAug, setSelectedAug] = useState(sourceAugs[0]); diff --git a/src/Augmentation/ui/PurchaseAugmentationModal.tsx b/src/Augmentation/ui/PurchaseAugmentationModal.tsx index bf3157a18..20990efb7 100644 --- a/src/Augmentation/ui/PurchaseAugmentationModal.tsx +++ b/src/Augmentation/ui/PurchaseAugmentationModal.tsx @@ -6,7 +6,7 @@ import { purchaseAugmentation } from "../../Faction/FactionHelpers"; import { isRepeatableAug } from "../AugmentationHelpers"; import { Money } from "../../ui/React/Money"; import { Modal } from "../../ui/React/Modal"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -22,10 +22,8 @@ export function PurchaseAugmentationModal(props: IProps): React.ReactElement { return <>; } - const player = use.Player(); - function buy(): void { - if (!isRepeatableAug(props.aug as Augmentation) && player.hasAugmentation(props.aug as Augmentation)) { + if (!isRepeatableAug(props.aug as Augmentation) && Player.hasAugmentation(props.aug as Augmentation)) { return; } diff --git a/src/BitNode/ui/BitFlumeModal.tsx b/src/BitNode/ui/BitFlumeModal.tsx index 8fdd3e1fe..b55038b57 100644 --- a/src/BitNode/ui/BitFlumeModal.tsx +++ b/src/BitNode/ui/BitFlumeModal.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from "react"; import { Modal } from "../../ui/React/Modal"; -import { use } from "../../ui/Context"; +import { Router } from "../../ui/GameRoot"; import { EventEmitter } from "../../utils/EventEmitter"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -8,10 +8,9 @@ import Button from "@mui/material/Button"; export const BitFlumeEvent = new EventEmitter<[]>(); export function BitFlumeModal(): React.ReactElement { - const router = use.Router(); const [open, setOpen] = useState(false); function flume(): void { - router.toBitVerse(true, false); + Router.toBitVerse(true, false); setOpen(false); } diff --git a/src/BitNode/ui/BitnodeMultipliersDescription.tsx b/src/BitNode/ui/BitnodeMultipliersDescription.tsx index 51516aaf9..21225d995 100644 --- a/src/BitNode/ui/BitnodeMultipliersDescription.tsx +++ b/src/BitNode/ui/BitnodeMultipliersDescription.tsx @@ -5,7 +5,7 @@ import { uniqueId } from "lodash"; import React from "react"; import { SpecialServers } from "../../Server/data/SpecialServers"; import { Settings } from "../../Settings/Settings"; -import { use } from "../../ui/Context"; +import { Player } from "../../ui/Player"; import { StatsRow } from "../../ui/React/StatsRow"; import { defaultMultipliers, getBitNodeMultipliers } from "../BitNode"; import { IBitNodeMultipliers } from "../BitNodeMultipliers"; @@ -33,13 +33,12 @@ export function BitnodeMultiplierDescription({ n, level }: IProps): React.ReactE } export const BitNodeMultipliersDisplay = ({ n, level }: IProps): React.ReactElement => { - const player = use.Player(); // If a level argument has been provided, use that as the multiplier level // If not, then we have to assume that we want the next level up from the // current node's source file, so we get the min of that, the SF's max level, // or if it's BN12, ∞ const maxSfLevel = n === 12 ? Infinity : 3; - const mults = getBitNodeMultipliers(n, level ?? Math.min(player.sourceFileLvl(n) + 1, maxSfLevel)); + const mults = getBitNodeMultipliers(n, level ?? Math.min(Player.sourceFileLvl(n) + 1, maxSfLevel)); return ( @@ -277,8 +276,7 @@ function InfiltrationMults({ mults }: IMultsProps): React.ReactElement { } function BladeburnerMults({ mults }: IMultsProps): React.ReactElement { - const player = use.Player(); - if (!player.canAccessBladeburner()) return <>; + if (!Player.canAccessBladeburner()) return <>; if (mults.BladeburnerRank === 0) { const rows: IBNMultRows = { @@ -297,8 +295,7 @@ function BladeburnerMults({ mults }: IMultsProps): React.ReactElement { } function StanekMults({ mults }: IMultsProps): React.ReactElement { - const player = use.Player(); - if (!player.canAccessCotMG()) return <>; + if (!Player.canAccessCotMG()) return <>; const extraSize = mults.StaneksGiftExtraSize.toFixed(3); const rows: IBNMultRows = { @@ -313,8 +310,7 @@ function StanekMults({ mults }: IMultsProps): React.ReactElement { } function GangMults({ mults }: IMultsProps): React.ReactElement { - const player = use.Player(); - if (player.bitNodeN !== 2 && player.sourceFileLvl(2) <= 0) return <>; + if (Player.bitNodeN !== 2 && Player.sourceFileLvl(2) <= 0) return <>; const rows: IBNMultRows = { GangSoftcap: { @@ -328,8 +324,7 @@ function GangMults({ mults }: IMultsProps): React.ReactElement { } function CorporationMults({ mults }: IMultsProps): React.ReactElement { - const player = use.Player(); - if (!player.canAccessCorporation()) return <>; + if (!Player.canAccessCorporation()) return <>; if (mults.CorporationSoftcap < 0.15) { const rows: IBNMultRows = { diff --git a/src/BitNode/ui/BitverseRoot.tsx b/src/BitNode/ui/BitverseRoot.tsx index 280e72bb0..a3483f832 100644 --- a/src/BitNode/ui/BitverseRoot.tsx +++ b/src/BitNode/ui/BitverseRoot.tsx @@ -1,10 +1,8 @@ import React, { useState } from "react"; -import { IRouter } from "../../ui/Router"; import { BitNodes } from "../BitNode"; -import { enterBitNode } from "../../RedPill"; import { PortalModal } from "./PortalModal"; import { CinematicText } from "../../ui/React/CinematicText"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import makeStyles from "@mui/styles/makeStyles"; import createStyles from "@mui/styles/createStyles"; import IconButton from "@mui/material/IconButton"; @@ -46,7 +44,6 @@ interface IPortalProps { level: number; destroyedBitNode: number; flume: boolean; - enter: (router: IRouter, flume: boolean, destroyedBitNode: number, newBitNode: number) => void; } function BitNodePortal(props: IPortalProps): React.ReactElement { const [portalOpen, setPortalOpen] = useState(false); @@ -105,7 +102,6 @@ function BitNodePortal(props: IPortalProps): React.ReactElement { onClose={() => setPortalOpen(false)} n={props.n} level={props.level} - enter={props.enter} destroyedBitNode={props.destroyedBitNode} flume={props.flume} /> @@ -118,13 +114,10 @@ function BitNodePortal(props: IPortalProps): React.ReactElement { interface IProps { flume: boolean; quick: boolean; - enter: (router: IRouter, flume: boolean, destroyedBitNode: number, newBitNode: number) => void; } export function BitverseRoot(props: IProps): React.ReactElement { - const player = use.Player(); - const enter = enterBitNode; - const destroyed = player.bitNodeN; + const destroyed = Player.bitNodeN; const [destroySequence, setDestroySequence] = useState(!props.quick); if (destroySequence) { @@ -158,7 +151,7 @@ export function BitverseRoot(props: IProps): React.ReactElement { } const nextSourceFileLvl = (n: number): number => { - const lvl = player.sourceFileLvl(n); + const lvl = Player.sourceFileLvl(n); if (n !== destroyed) { return lvl; } @@ -181,7 +174,6 @@ export function BitverseRoot(props: IProps): React.ReactElement { key={node.number} n={node.number} level={nextSourceFileLvl(node.number)} - enter={enter} flume={props.flume} destroyedBitNode={destroyed} /> @@ -234,19 +226,19 @@ export function BitverseRoot(props: IProps): React.ReactElement { O | | | \| | O / _/ | / O | |/ | | | O | | | |O / | | O / | O O | | \ O| | | | | | |/ \/ / __| | |/ \ | \ | |__ \ \/ \| | | - \| O | |_/ |\| \ \__| \_| | O |/ + \| O | |_/ |\| \ \__| \_| | O |/ | | |_/ | | \| / | \_| | | \| / \| | / / \ |/ - | | | / | | - | | | | | | | + | | | / | | + | | | | | | | | | | / / \ \ | | | - \| | / / \ \ | |/ + \| | / / \ \ | |/ \ | / / | | \ \ | / - \ \JUMP 3R | | | | | | R3 PMUJ/ / + \ \JUMP 3R | | | | | | R3 PMUJ/ / \|| | | | | | | | | ||/ \| \_ | | | | | | _/ |/ \ \| / \ / \ |/ / - |/ | | \| + |/ | | \| | | | | | | | | \JUMP3R|JUMP|3R| |R3|PMUJ|R3PMUJ/
diff --git a/src/BitNode/ui/PortalModal.tsx b/src/BitNode/ui/PortalModal.tsx index 9b5cd560a..9bfaaa589 100644 --- a/src/BitNode/ui/PortalModal.tsx +++ b/src/BitNode/ui/PortalModal.tsx @@ -1,8 +1,7 @@ import React from "react"; +import { enterBitNode } from "../../RedPill"; import { BitNodes } from "../BitNode"; -import { IRouter } from "../../ui/Router"; -import { use } from "../../ui/Context"; import { Modal } from "../../ui/React/Modal"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -15,11 +14,9 @@ interface IProps { level: number; destroyedBitNode: number; flume: boolean; - enter: (router: IRouter, flume: boolean, destroyedBitNode: number, newBitNode: number) => void; } export function PortalModal(props: IProps): React.ReactElement { - const router = use.Router(); const bitNodeKey = "BitNode" + props.n; const bitNode = BitNodes[bitNodeKey]; if (bitNode == null) throw new Error(`Could not find BitNode object for number: ${props.n}`); @@ -48,7 +45,7 @@ export function PortalModal(props: IProps): React.ReactElement { aria-label={`enter-bitnode-${bitNode.number.toString()}`} autoFocus={true} onClick={() => { - props.enter(router, props.flume, props.destroyedBitNode, props.n); + enterBitNode(props.flume, props.destroyedBitNode, props.n); props.onClose(); }} > diff --git a/src/Bladeburner/ui/ActionLevel.tsx b/src/Bladeburner/ui/ActionLevel.tsx index 2f4d1ae30..e87a466fe 100644 --- a/src/Bladeburner/ui/ActionLevel.tsx +++ b/src/Bladeburner/ui/ActionLevel.tsx @@ -2,7 +2,6 @@ import React from "react"; import { IAction } from "../IAction"; import { IBladeburner } from "../IBladeburner"; import { BladeburnerConstants } from "../data/Constants"; -import { use } from "../../ui/Context"; import Typography from "@mui/material/Typography"; import Tooltip from "@mui/material/Tooltip"; @@ -19,8 +18,6 @@ interface IProps { } export function ActionLevel({ action, isActive, bladeburner, rerender }: IProps): React.ReactElement { - const player = use.Player(); - const canIncrease = action.level < action.maxLevel; const canDecrease = action.level > 1; diff --git a/src/Bladeburner/ui/BlackOpPage.tsx b/src/Bladeburner/ui/BlackOpPage.tsx index 86061bafc..ecfede4c9 100644 --- a/src/Bladeburner/ui/BlackOpPage.tsx +++ b/src/Bladeburner/ui/BlackOpPage.tsx @@ -3,7 +3,7 @@ import { BlackOpList } from "./BlackOpList"; import { IBladeburner } from "../IBladeburner"; import Typography from "@mui/material/Typography"; import { FactionNames } from "../../Faction/data/FactionNames"; -import { use } from "../../ui/Context"; +import { Router } from "../../ui/GameRoot"; import { BlackOperationNames } from "../data/BlackOperationNames"; import { Button } from "@mui/material"; import { CorruptableText } from "../../ui/React/CorruptableText"; @@ -13,7 +13,6 @@ interface IProps { } export function BlackOpPage(props: IProps): React.ReactElement { - const router = use.Router(); return ( <> @@ -31,7 +30,7 @@ export function BlackOpPage(props: IProps): React.ReactElement { losses. {props.bladeburner.blackops[BlackOperationNames.OperationDaedalus] ? ( - ) : ( diff --git a/src/Bladeburner/ui/BladeburnerCinematic.tsx b/src/Bladeburner/ui/BladeburnerCinematic.tsx index 5be3e1030..8ce17ea5c 100644 --- a/src/Bladeburner/ui/BladeburnerCinematic.tsx +++ b/src/Bladeburner/ui/BladeburnerCinematic.tsx @@ -1,11 +1,10 @@ import React from "react"; import { FactionNames } from "../../Faction/data/FactionNames"; -import { use } from "../../ui/Context"; +import { Router } from "../../ui/GameRoot"; import { CinematicText } from "../../ui/React/CinematicText"; import { dialogBoxCreate } from "../../ui/React/DialogBox"; export function BladeburnerCinematic(): React.ReactElement { - const router = use.Router(); return ( { - router.toTerminal(); + Router.toTerminal(); dialogBoxCreate( `Visit the National Security Agency (NSA) to apply for their ${FactionNames.Bladeburners} ` + "division! You will need 100 of each combat stat before doing this.", diff --git a/src/Bladeburner/ui/BladeburnerRoot.tsx b/src/Bladeburner/ui/BladeburnerRoot.tsx index ca19f4c93..4d9103939 100644 --- a/src/Bladeburner/ui/BladeburnerRoot.tsx +++ b/src/Bladeburner/ui/BladeburnerRoot.tsx @@ -3,12 +3,10 @@ import { Stats } from "./Stats"; import { Console } from "./Console"; import { AllPages } from "./AllPages"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import Box from "@mui/material/Box"; export function BladeburnerRoot(): React.ReactElement { - const player = use.Player(); - const router = use.Router(); const setRerender = useState(false)[1]; function rerender(): void { setRerender((old) => !old); @@ -19,8 +17,8 @@ export function BladeburnerRoot(): React.ReactElement { return () => clearInterval(id); }, []); - const bladeburner = player.bladeburner; - if (bladeburner === null) return <>; + const bladeburner = Player.bladeburner; + if (!bladeburner) return <>; return ( diff --git a/src/Bladeburner/ui/StartButton.tsx b/src/Bladeburner/ui/StartButton.tsx index 2bbedb947..ce03674f3 100644 --- a/src/Bladeburner/ui/StartButton.tsx +++ b/src/Bladeburner/ui/StartButton.tsx @@ -2,7 +2,7 @@ import React from "react"; import { IBladeburner } from "../IBladeburner"; import { BlackOperation } from "../BlackOperation"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import Button from "@mui/material/Button"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; @@ -13,7 +13,6 @@ interface IProps { rerender: () => void; } export function StartButton(props: IProps): React.ReactElement { - const player = use.Player(); const action = props.bladeburner.getActionObject({ name: props.name, type: props.type }); if (action == null) { throw new Error("Failed to get Operation Object for: " + props.name); @@ -33,7 +32,7 @@ export function StartButton(props: IProps): React.ReactElement { if (disabled) return; props.bladeburner.action.type = props.type; props.bladeburner.action.name = props.name; - if (!player.hasAugmentation(AugmentationNames.BladesSimulacrum, true)) player.finishWork(true); + if (!Player.hasAugmentation(AugmentationNames.BladesSimulacrum, true)) Player.finishWork(true); props.bladeburner.startAction(props.bladeburner.action); props.rerender(); } diff --git a/src/Company/ui/QuitJobModal.tsx b/src/Company/ui/QuitJobModal.tsx index 7ee05b506..0b766c28a 100644 --- a/src/Company/ui/QuitJobModal.tsx +++ b/src/Company/ui/QuitJobModal.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Company } from "../Company"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { Modal } from "../../ui/React/Modal"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -14,9 +14,8 @@ interface IProps { } export function QuitJobModal(props: IProps): React.ReactElement { - const player = use.Player(); function quit(): void { - player.quitJob(props.locName); + Player.quitJob(props.locName); props.onQuit(); props.onClose(); } diff --git a/src/Corporation/ICorporation.ts b/src/Corporation/ICorporation.ts index 4165d48a8..ea71c6cf5 100644 --- a/src/Corporation/ICorporation.ts +++ b/src/Corporation/ICorporation.ts @@ -1,5 +1,4 @@ import { Industry } from "./Industry"; -import { IPlayer } from "../PersonObjects/IPlayer"; import { CorporationUnlockUpgrade } from "./data/CorporationUnlockUpgrades"; import { CorporationUpgrade } from "./data/CorporationUpgrades"; import { CorporationState } from "./CorporationState"; @@ -36,7 +35,7 @@ export interface ICorporation { addFunds(amt: number): void; getState(): string; storeCycles(numCycles: number): void; - process(player: IPlayer): void; + process(): void; determineValuation(): void; determineCycleValuation(): number; getTargetSharePrice(): number; @@ -56,7 +55,7 @@ export interface ICorporation { getEmployeeEffMultiplier(): number; getSalesMultiplier(): number; getScientificResearchMultiplier(): number; - getStarterGuide(player: IPlayer): void; + getStarterGuide(): void; updateDividendTax(): void; getCycleDividends(): number; toJSON(): IReviverValue; diff --git a/src/Corporation/ui/CorporationRoot.tsx b/src/Corporation/ui/CorporationRoot.tsx index bf4766cf0..ba24dbae8 100644 --- a/src/Corporation/ui/CorporationRoot.tsx +++ b/src/Corporation/ui/CorporationRoot.tsx @@ -6,7 +6,7 @@ import { IIndustry } from "../IIndustry"; import { MainPanel } from "./MainPanel"; import { Industries } from "../IndustryData"; import { ExpandIndustryTab } from "./ExpandIndustryTab"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { Context } from "./Context"; import { Overview } from "./Overview"; @@ -14,8 +14,7 @@ import Tabs from "@mui/material/Tabs"; import Tab from "@mui/material/Tab"; export function CorporationRoot(): React.ReactElement { - const player = use.Player(); - const corporation = player.corporation; + const corporation = Player.corporation; if (corporation === null) return <>; const setRerender = useState(false)[1]; function rerender(): void { diff --git a/src/Corporation/ui/Industry.tsx b/src/Corporation/ui/Industry.tsx index c02643db8..447e3ccbe 100644 --- a/src/Corporation/ui/Industry.tsx +++ b/src/Corporation/ui/Industry.tsx @@ -7,7 +7,6 @@ import { IndustryOverview } from "./IndustryOverview"; import { IndustryWarehouse } from "./IndustryWarehouse"; import { Warehouse } from "../Warehouse"; import { OfficeSpace } from "../OfficeSpace"; -import { use } from "../../ui/Context"; import { useCorporation, useDivision } from "./Context"; import Box from "@mui/material/Box"; @@ -19,7 +18,6 @@ interface IProps { } export function Industry(props: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const division = useDivision(); return ( diff --git a/src/Corporation/ui/Overview.tsx b/src/Corporation/ui/Overview.tsx index 1dc811f0c..10fb2f7b3 100644 --- a/src/Corporation/ui/Overview.tsx +++ b/src/Corporation/ui/Overview.tsx @@ -21,7 +21,7 @@ import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFuncti import { Money } from "../../ui/React/Money"; import { MoneyRate } from "../../ui/React/MoneyRate"; import { StatsTable } from "../../ui/React/StatsTable"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { useCorporation } from "./Context"; import Typography from "@mui/material/Typography"; import Tooltip from "@mui/material/Tooltip"; @@ -34,7 +34,6 @@ interface IProps { rerender: () => void; } export function Overview({ rerender }: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const profit: number = corp.revenue - corp.expenses; @@ -100,7 +99,7 @@ export function Overview({ rerender }: IProps): React.ReactElement { } > - + {corp.public ? : } @@ -240,12 +239,11 @@ function PublicButtons({ rerender }: IPublicButtonsProps): React.ReactElement { } function BribeButton(): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const [open, setOpen] = useState(false); const canBribe = corp.valuation >= CorporationConstants.BribeThreshold && - player.factions.filter((f) => Factions[f].getInfo().offersWork()).length > 0; + Player.factions.filter((f) => Factions[f].getInfo().offersWork()).length > 0; function openBribe(): void { if (!canBribe) return; diff --git a/src/Corporation/ui/modals/BribeFactionModal.tsx b/src/Corporation/ui/modals/BribeFactionModal.tsx index 341c56772..7c5668934 100644 --- a/src/Corporation/ui/modals/BribeFactionModal.tsx +++ b/src/Corporation/ui/modals/BribeFactionModal.tsx @@ -4,7 +4,7 @@ import { CorporationConstants } from "../../data/Constants"; import { numeralWrapper } from "../../../ui/numeralFormat"; import { dialogBoxCreate } from "../../../ui/React/DialogBox"; import { Modal } from "../../../ui/React/Modal"; -import { use } from "../../../ui/Context"; +import { Player } from "../../../Player"; import { useCorporation } from "../Context"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -19,11 +19,10 @@ interface IProps { } export function BribeFactionModal(props: IProps): React.ReactElement { - const player = use.Player(); - const factions = player.factions.filter((name: string) => { + const factions = Player.factions.filter((name: string) => { const info = Factions[name].getInfo(); if (!info.offersWork()) return false; - if (player.hasGangWith(name)) return false; + if (Player.hasGangWith(name)) return false; return true; }); const corp = useCorporation(); @@ -77,7 +76,7 @@ export function BribeFactionModal(props: IProps): React.ReactElement { {factions.map((name: string) => { const info = Factions[name].getInfo(); if (!info.offersWork()) return; - if (player.hasGangWith(name)) return; + if (Player.hasGangWith(name)) return; return ( {name} diff --git a/src/Corporation/ui/modals/BuybackSharesModal.tsx b/src/Corporation/ui/modals/BuybackSharesModal.tsx index 2e92cdcd9..6083015e7 100644 --- a/src/Corporation/ui/modals/BuybackSharesModal.tsx +++ b/src/Corporation/ui/modals/BuybackSharesModal.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { Modal } from "../../../ui/React/Modal"; import { numeralWrapper } from "../../../ui/numeralFormat"; -import { use } from "../../../ui/Context"; +import { Player } from "../../../Player"; import { useCorporation } from "../Context"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -19,7 +19,6 @@ interface IProps { // Create a popup that lets the player buyback shares // This is created when the player clicks the "Buyback Shares" button in the overview panel export function BuybackSharesModal(props: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const [shares, setShares] = useState(NaN); @@ -30,7 +29,7 @@ export function BuybackSharesModal(props: IProps): React.ReactElement { isNaN(shares) || shares <= 0 || shares > corp.issuedShares || - shares * buybackPrice > player.money; + shares * buybackPrice > Player.money; function buy(): void { if (disabled) return; diff --git a/src/Corporation/ui/modals/CreateCorporationModal.tsx b/src/Corporation/ui/modals/CreateCorporationModal.tsx index 9e77fcc14..1b2b1b7a6 100644 --- a/src/Corporation/ui/modals/CreateCorporationModal.tsx +++ b/src/Corporation/ui/modals/CreateCorporationModal.tsx @@ -2,7 +2,8 @@ import React, { useState } from "react"; import { Money } from "../../../ui/React/Money"; import { Modal } from "../../../ui/React/Modal"; -import { use } from "../../../ui/Context"; +import { Router } from "../../../ui/GameRoot"; +import { Player } from "../../../Player"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; @@ -13,10 +14,8 @@ interface IProps { } export function CreateCorporationModal(props: IProps): React.ReactElement { - const player = use.Player(); - const router = use.Router(); - const canSelfFund = player.canAfford(150e9); - if (!player.canAccessCorporation() || player.hasCorporation()) { + const canSelfFund = Player.canAfford(150e9); + if (!Player.canAccessCorporation() || Player.hasCorporation()) { props.onClose(); return <>; } @@ -35,11 +34,11 @@ export function CreateCorporationModal(props: IProps): React.ReactElement { return; } - player.startCorporation(name); - player.loseMoney(150e9, "corporation"); + Player.startCorporation(name); + Player.loseMoney(150e9, "corporation"); props.onClose(); - router.toCorporation(); + Router.toCorporation(); } function seed(): void { @@ -47,17 +46,17 @@ export function CreateCorporationModal(props: IProps): React.ReactElement { return; } - player.startCorporation(name, 500e6); + Player.startCorporation(name, 500e6); props.onClose(); - router.toCorporation(); + Router.toCorporation(); } return ( Would you like to start a corporation? This will require $150b for registration and initial funding.{" "} - {player.bitNodeN === 3 && + {Player.bitNodeN === 3 && `This $150b can either be self-funded, or you can obtain the seed money from the government in exchange for 500 million shares`} @@ -66,7 +65,7 @@ export function CreateCorporationModal(props: IProps): React.ReactElement { If you would like to start one, please enter a name for your corporation below: - {player.bitNodeN === 3 && ( + {Player.bitNodeN === 3 && ( diff --git a/src/Corporation/ui/modals/SellSharesModal.tsx b/src/Corporation/ui/modals/SellSharesModal.tsx index fdb178029..455e6efcd 100644 --- a/src/Corporation/ui/modals/SellSharesModal.tsx +++ b/src/Corporation/ui/modals/SellSharesModal.tsx @@ -2,7 +2,6 @@ import React, { useState } from "react"; import { numeralWrapper } from "../../../ui/numeralFormat"; import { dialogBoxCreate } from "../../../ui/React/DialogBox"; import { Modal } from "../../../ui/React/Modal"; -import { use } from "../../../ui/Context"; import { useCorporation } from "../Context"; import { ICorporation } from "../../ICorporation"; import Typography from "@mui/material/Typography"; @@ -20,7 +19,6 @@ interface IProps { // Create a popup that lets the player sell Corporation shares // This is created when the player clicks the "Sell Shares" button in the overview panel export function SellSharesModal(props: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const [shares, setShares] = useState(NaN); diff --git a/src/Crime/Crime.ts b/src/Crime/Crime.ts index 8100d9c0e..8edf124f8 100644 --- a/src/Crime/Crime.ts +++ b/src/Crime/Crime.ts @@ -1,5 +1,5 @@ import { CONSTANTS } from "../Constants"; -import { IPlayer } from "../PersonObjects/IPlayer"; +import { Player } from "../Player"; import { IPerson } from "../PersonObjects/IPerson"; import { WorkerScript } from "../Netscript/WorkerScript"; import { CrimeType } from "../utils/WorkType"; @@ -101,11 +101,11 @@ export class Crime { this.kills = params.kills ? params.kills : 0; } - commit(p: IPlayer, div = 1, workerScript: WorkerScript | null = null): number { + commit(div = 1, workerScript: WorkerScript | null = null): number { if (div <= 0) { div = 1; } - p.startWork( + Player.startWork( new CrimeWork({ crimeType: this.type, singularity: workerScript !== null, diff --git a/src/Exploits/Unclickable.tsx b/src/Exploits/Unclickable.tsx index 1ab524d9e..8e6c5fe9c 100644 --- a/src/Exploits/Unclickable.tsx +++ b/src/Exploits/Unclickable.tsx @@ -1,16 +1,15 @@ import React from "react"; -import { use } from "../ui/Context"; +import { Player } from "../Player"; import { Exploit } from "./Exploit"; const getComputedStyle = window.getComputedStyle; export function Unclickable(): React.ReactElement { - const player = use.Player(); function unclickable(event: React.MouseEvent): void { if (!event.target || !(event.target instanceof Element)) return; const display = getComputedStyle(event.target).display; const visibility = getComputedStyle(event.target).visibility; - if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable); + if (display === "none" && visibility === "hidden" && event.isTrusted) Player.giveExploit(Exploit.Unclickable); } return ( diff --git a/src/Faction/FactionInfo.tsx b/src/Faction/FactionInfo.tsx index 96c252fc3..0a63d868d 100644 --- a/src/Faction/FactionInfo.tsx +++ b/src/Faction/FactionInfo.tsx @@ -1,7 +1,7 @@ import React from "react"; import { IMap } from "../types"; import { FactionNames } from "./data/FactionNames"; -import { use } from "../ui/Context"; +import { Router } from "../ui/GameRoot"; import { Option } from "./ui/Option"; import { Typography } from "@mui/material"; @@ -449,12 +449,11 @@ export const FactionInfos: IMap = { special: true, assignment: (): React.ReactElement => { - const router = use.Router(); return (