bitburner-src/src/ui/LoadingScreen.tsx

63 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-09-20 00:04:12 +02:00
import React, { useState, useEffect } from "react";
import CircularProgress from "@mui/material/CircularProgress";
import Typography from "@mui/material/Typography";
import Grid from "@mui/material/Grid";
import { Terminal } from "../Terminal";
2021-09-21 22:49:38 +02:00
import { load } from "../db";
import { Player } from "../Player";
2021-09-21 22:49:38 +02:00
import { Engine } from "../engine";
import { GameRoot } from "./GameRoot";
2021-09-20 00:04:12 +02:00
import { CONSTANTS } from "../Constants";
export function LoadingScreen(): React.ReactElement {
const [show, setShow] = useState(false);
const [loaded, setLoaded] = useState(false);
2021-09-20 00:04:12 +02:00
useEffect(() => {
const id = setTimeout(() => {
if (!loaded) setShow(true);
2021-09-20 00:04:12 +02:00
}, 2000);
return () => clearTimeout(id);
});
useEffect(() => {
2021-09-25 07:26:03 +02:00
async function doLoad(): Promise<void> {
2021-09-21 22:49:38 +02:00
await load()
.then((saveString) => {
Engine.load(saveString);
setLoaded(true);
})
.catch((reason) => {
console.error(reason);
Engine.load("");
setLoaded(true);
});
}
doLoad();
2021-09-20 00:04:12 +02:00
}, []);
if (loaded) {
return <GameRoot terminal={Terminal} engine={Engine} player={Player} />;
}
2021-09-20 00:04:12 +02:00
return (
<Grid container direction="column" justifyContent="center" alignItems="center" style={{ minHeight: "100vh" }}>
<Grid item>
<CircularProgress size={150} color="primary" />
</Grid>
<Grid item>
<Typography variant="h3">Loading Bitburner v{CONSTANTS.Version}</Typography>
</Grid>
{show && (
<Grid item>
<Typography>
If the game fails to load, consider <a href="?noScripts">killing all scripts</a>
</Typography>
</Grid>
)}
</Grid>
);
}