diff --git a/src/Locations/ui/GenericLocation.tsx b/src/Locations/ui/GenericLocation.tsx
index 82b680429..b25d06638 100644
--- a/src/Locations/ui/GenericLocation.tsx
+++ b/src/Locations/ui/GenericLocation.tsx
@@ -20,7 +20,6 @@ import { Location } from "../Location";
import { LocationType } from "../LocationTypeEnum";
import { CityName } from "../data/CityNames";
-import { IEngine } from "../../IEngine";
import { IRouter } from "../../ui/Router";
import { Settings } from "../../Settings/Settings";
diff --git a/src/Locations/ui/SpecialLocation.tsx b/src/Locations/ui/SpecialLocation.tsx
index 5e83d27e3..455da8dca 100644
--- a/src/Locations/ui/SpecialLocation.tsx
+++ b/src/Locations/ui/SpecialLocation.tsx
@@ -17,7 +17,6 @@ import { CreateCorporationPopup } from "../../Corporation/ui/CreateCorporationPo
import { createPopup } from "../../ui/React/createPopup";
import { LocationName } from "../data/LocationNames";
-import { IEngine } from "../../IEngine";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { use } from "../../ui/Context";
diff --git a/src/engine.d.ts b/src/engine.d.ts
new file mode 100644
index 000000000..ce2819933
--- /dev/null
+++ b/src/engine.d.ts
@@ -0,0 +1,2 @@
+export declare function load(cb: () => void): void;
+export declare const Engine: any;
diff --git a/src/engine.jsx b/src/engine.jsx
index 66a141eed..e272dbc4f 100644
--- a/src/engine.jsx
+++ b/src/engine.jsx
@@ -36,6 +36,7 @@ import { Terminal } from "./Terminal";
import { Sleeve } from "./PersonObjects/Sleeve/Sleeve";
import { Locations } from "./Locations/Locations";
import { LocationName } from "./Locations/data/LocationNames";
+import { LoadingScreen } from "./ui/LoadingScreen";
import { Money } from "./ui/React/Money";
import { Hashes } from "./ui/React/Hashes";
@@ -399,14 +400,6 @@ const Engine = {
// Start interactive tutorial
iTutorialStart();
}
-
- ReactDOM.render(
-
-
- ,
- document.getElementById("mainmenu-container"),
- );
- Router.toTerminal();
},
start: function () {
@@ -429,8 +422,7 @@ const Engine = {
},
};
-var indexedDbRequest;
-window.onload = function () {
+function load(cb) {
if (!window.indexedDB) {
return Engine.load(null); // Will try to load from localstorage
}
@@ -445,7 +437,8 @@ window.onload = function () {
indexedDbRequest.onerror = function (e) {
console.error("Error opening indexedDB: ");
console.error(e);
- return Engine.load(null); // Try to load from localstorage
+ Engine.load(null); // Try to load from localstorage
+ cb();
};
indexedDbRequest.onsuccess = function (e) {
@@ -455,11 +448,13 @@ window.onload = function () {
var request = objectStore.get("save");
request.onerror = function (e) {
console.error("Error in Database request to get savestring: " + e);
- return Engine.load(null); // Try to load from localstorage
+ Engine.load(null); // Try to load from localstorage
+ cb();
};
request.onsuccess = function () {
Engine.load(request.result);
+ cb();
};
};
@@ -467,6 +462,15 @@ window.onload = function () {
const db = e.target.result;
db.createObjectStore("savestring");
};
-};
+}
-export { Engine };
+var indexedDbRequest;
+
+ReactDOM.render(
+
+
+ ,
+ document.getElementById("mainmenu-container"),
+);
+
+export { Engine, load };
diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx
index 55f1a1273..98d5026fb 100644
--- a/src/ui/GameRoot.tsx
+++ b/src/ui/GameRoot.tsx
@@ -63,7 +63,6 @@ import { TravelAgencyRoot } from "../Locations/ui/TravelAgencyRoot";
import { StockMarketRoot } from "../StockMarket/ui/StockMarketRoot";
import { BitverseRoot } from "../BitNode/ui/BitverseRoot";
import { CharacterOverview } from "./React/CharacterOverview";
-import { LoadingScreen } from "./LoadingScreen";
import { BladeburnerCinematic } from "../Bladeburner/ui/BladeburnerCinematic";
import { workerScripts } from "../Netscript/WorkerScripts";
@@ -186,7 +185,7 @@ function determineStartPage(player: IPlayer): Page {
export function GameRoot({ player, engine, terminal }: IProps): React.ReactElement {
const classes = useStyles();
- const [page, setPage] = useState(/*determineStartPage(player)*/ Page.Loading);
+ const [page, setPage] = useState(determineStartPage(player));
const setRerender = useState(0)[1];
const [faction, setFaction] = useState(
player.currentWorkFactionName ? Factions[player.currentWorkFactionName] : (undefined as unknown as Faction),
@@ -288,9 +287,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
)}
- {page === Page.Loading ? (
-
- ) : page === Page.BitVerse ? (
+ {page === Page.BitVerse ? (
) : page === Page.Infiltration ? (
diff --git a/src/ui/LoadingScreen.tsx b/src/ui/LoadingScreen.tsx
index e8ffc920e..bc9a70abd 100644
--- a/src/ui/LoadingScreen.tsx
+++ b/src/ui/LoadingScreen.tsx
@@ -7,8 +7,15 @@ import { Theme } from "@mui/material";
import makeStyles from "@mui/styles/makeStyles";
import createStyles from "@mui/styles/createStyles";
+import { Terminal } from "../Terminal";
+import { Engine } from "../engine";
+import { Player } from "../Player";
+import { GameRoot } from "./GameRoot";
+
import { CONSTANTS } from "../Constants";
+import { load } from "../engine";
+
const useStyles = makeStyles((theme: Theme) =>
createStyles({
center: {
@@ -22,13 +29,26 @@ const useStyles = makeStyles((theme: Theme) =>
export function LoadingScreen(): React.ReactElement {
const classes = useStyles();
const [show, setShow] = useState(false);
+ const [loaded, setLoaded] = useState(false);
+ console.log("renredering");
useEffect(() => {
const id = setTimeout(() => {
- setShow(true);
+ if (!loaded) setShow(true);
}, 2000);
return () => clearTimeout(id);
+ });
+
+ useEffect(() => {
+ load(() => {
+ setLoaded(true);
+ });
}, []);
+
+ if (loaded) {
+ return ;
+ }
+
return (
diff --git a/src/ui/Router.ts b/src/ui/Router.ts
index 58b11e704..206377b42 100644
--- a/src/ui/Router.ts
+++ b/src/ui/Router.ts
@@ -1,5 +1,4 @@
import { Faction } from "../Faction/Faction";
-import { LocationName } from "../Locations/data/LocationNames";
import { Location } from "../Locations/Location";
/**
diff --git a/src/utils/EventEmitter.ts b/src/utils/EventEmitter.ts
index fd36880e0..4907bd3cc 100644
--- a/src/utils/EventEmitter.ts
+++ b/src/utils/EventEmitter.ts
@@ -1,7 +1,6 @@
/**
* Generic Event Emitter class following a subscribe/publish paradigm.
*/
-import { IMap } from "../types";
type cbFn = (...args: any[]) => any;
@@ -19,7 +18,7 @@ export interface ISubscriber {
function uuidv4(): string {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
- var r = (Math.random() * 16) | 0,
+ const r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});