diff --git a/src/Bladeburner/Bladeburner.ts b/src/Bladeburner/Bladeburner.ts index fa0d5b48d..f61d0ca6f 100644 --- a/src/Bladeburner/Bladeburner.ts +++ b/src/Bladeburner/Bladeburner.ts @@ -22,6 +22,7 @@ import { Skills } from "./data/Skills"; import { City } from "./City"; import { Player } from "@player"; import { Router } from "../ui/GameRoot"; +import { Page } from "../ui/Router"; import { ConsoleHelpText } from "./data/Help"; import { exceptionAlert } from "../utils/helpers/exceptionAlert"; import { getRandomIntInclusive } from "../utils/helpers/getRandomIntInclusive"; @@ -1307,7 +1308,7 @@ export class Bladeburner { process(): void { // Edge race condition when the engine checks the processing counters and attempts to route before the router is initialized. - if (!Router.isInitialized) return; + if (Router.page() === Page.LoadingScreen) return; // If the Player starts doing some other actions, set action to idle and alert if (!Player.hasAugmentation(AugmentationName.BladesSimulacrum, true) && Player.currentWork) { diff --git a/src/Message/MessageHelpers.tsx b/src/Message/MessageHelpers.tsx index 895fc36c8..9d761b1c6 100644 --- a/src/Message/MessageHelpers.tsx +++ b/src/Message/MessageHelpers.tsx @@ -3,7 +3,6 @@ import { Message } from "./Message"; import { AugmentationName, CompletedProgramName, FactionName, MessageFilename } from "@enums"; import { Router } from "../ui/GameRoot"; import { Player } from "@player"; -import { Page } from "../ui/Router"; import { GetServer } from "../Server/AllServers"; import { SpecialServers } from "../Server/data/SpecialServers"; import { Settings } from "../Settings/Settings"; @@ -53,7 +52,7 @@ function recvd(name: MessageFilename): boolean { //Checks if any of the 'timed' messages should be sent function checkForMessagesToSend(): void { - if (Router.page() === Page.BitVerse) return; + if (Router.hidingMessages()) return; if (Player.hasAugmentation(AugmentationName.TheRedPill, true)) { //Get the world daemon required hacking level diff --git a/src/engine.tsx b/src/engine.tsx index bb7378e8b..855d16269 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -8,7 +8,6 @@ import { Factions } from "./Faction/Factions"; import { staneksGift } from "./CotMG/Helper"; import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/FactionHelpers"; import { Router } from "./ui/GameRoot"; -import { Page } from "./ui/Router"; import "./utils/Protections"; // Side-effect: Protect against certain unrecoverable errors import "./PersonObjects/Player/PlayerObject"; // For side-effect of creating Player @@ -441,8 +440,7 @@ function warnAutosaveDisabled(): void { // We don't want this warning to show up on certain pages. // When in recovery or importing we want to keep autosave disabled. - const ignoredPages = [Page.Recovery as Page, Page.ImportSave]; - if (ignoredPages.includes(Router.page())) return; + if (Router.hidingMessages()) return; const warningToast = ( <> diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx index 5b14816b5..1f20c96d8 100644 --- a/src/ui/GameRoot.tsx +++ b/src/ui/GameRoot.tsx @@ -18,7 +18,8 @@ import { dialogBoxCreate } from "./React/DialogBox"; import { GetAllServers } from "../Server/AllServers"; import { StockMarket } from "../StockMarket/StockMarket"; -import { Page, PageWithContext, IRouter, ComplexPage, PageContext } from "./Router"; +import type { PageWithContext, IRouter, ComplexPage, PageContext } from "./Router"; +import { Page } from "./Router"; import { Overview } from "./React/Overview"; import { SidebarRoot } from "../Sidebar/ui/SidebarRoot"; import { AugmentationsRoot } from "../Augmentation/ui/AugmentationsRoot"; @@ -90,20 +91,18 @@ const useStyles = makeStyles()((theme: Theme) => ({ }, })); -const uninitialized = (): void => { - throw new Error("Router called before initialization - uninitialized"); -}; - const MAX_PAGES_IN_HISTORY = 10; export let Router: IRouter = { - isInitialized: false, page: () => { - throw new Error("Router called before initialization - page"); + return Page.LoadingScreen; }, - allowRouting: uninitialized, - toPage: () => { - throw new Error("Router called before initialization - toPage"); + allowRouting: () => { + throw new Error("Router called before initialization - allowRouting"); + }, + hidingMessages: () => true, + toPage: (page: Page) => { + throw new Error(`Router called before initialization - toPage(${page})`); }, back: () => { throw new Error("Router called before initialization - back"); @@ -163,10 +162,18 @@ export function GameRoot(): React.ReactElement { console.error(`Routing is currently disabled - Attempted router.${name}()`); } + const hiddenPages = new Set([ + Page.Recovery, + Page.ImportSave, + Page.BitVerse, + Page.Infiltration, + Page.BladeburnerCinematic, + ]); + Router = { - isInitialized: true, page: () => pageWithContext.page, allowRouting: (value: boolean) => setAllowRoutingCalls(value), + hidingMessages: () => hiddenPages.has(pageWithContext.page), toPage: (page: Page, context?: PageContext) => { if (!allowRoutingCalls) return attemptedForbiddenRouting("toPage"); switch (page) { @@ -199,32 +206,28 @@ export function GameRoot(): React.ReactElement { let mainPage = Cannot load; let withSidebar = true; - let withPopups = true; + const hidePopups = Router.hidingMessages(); let bypassGame = false; switch (pageWithContext.page) { case Page.Recovery: { mainPage = ; withSidebar = false; - withPopups = false; bypassGame = true; break; } case Page.BitVerse: { mainPage = ; withSidebar = false; - withPopups = false; break; } case Page.Infiltration: { mainPage = ; withSidebar = false; - withPopups = false; break; } case Page.BladeburnerCinematic: { mainPage = ; withSidebar = false; - withPopups = false; break; } case Page.Work: { @@ -377,7 +380,6 @@ export function GameRoot(): React.ReactElement { case Page.ImportSave: { mainPage = ; withSidebar = false; - withPopups = false; bypassGame = true; } } @@ -410,11 +412,11 @@ export function GameRoot(): React.ReactElement { {mainPage} )} -