Added kill all scripts button

This commit is contained in:
Olivier Gagnon 2021-10-26 15:50:55 -04:00
parent f915ba61a9
commit ba72fd7fb5
6 changed files with 210 additions and 167 deletions

34
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -74,6 +74,8 @@ import { InvitationModal } from "../Faction/ui/InvitationModal";
import { enterBitNode } from "../RedPill"; import { enterBitNode } from "../RedPill";
import { Context } from "./Context"; import { Context } from "./Context";
const htmlLocation = location;
interface IProps { interface IProps {
terminal: ITerminal; terminal: ITerminal;
player: IPlayer; player: IPlayer;
@ -210,6 +212,14 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
return ITutorialEvents.subscribe(rerender); return ITutorialEvents.subscribe(rerender);
}, []); }, []);
function killAllScripts(): void {
for (const server of GetAllServers()) {
server.runningScripts = [];
}
saveObject.saveGame();
setTimeout(() => htmlLocation.reload(), 2000);
}
Router = { Router = {
page: () => page, page: () => page,
toActiveScripts: () => setPage(Page.ActiveScripts), toActiveScripts: () => setPage(Page.ActiveScripts),
@ -280,7 +290,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
<Context.Router.Provider value={Router}> <Context.Router.Provider value={Router}>
<Overview> <Overview>
{!ITutorial.isRunning ? ( {!ITutorial.isRunning ? (
<CharacterOverview save={() => saveObject.saveGame()} /> <CharacterOverview save={() => saveObject.saveGame()} killScripts={killAllScripts} />
) : ( ) : (
<InteractiveTutorialRoot /> <InteractiveTutorialRoot />
)} )}
@ -362,12 +372,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
player={player} player={player}
save={() => saveObject.saveGame()} save={() => saveObject.saveGame()}
export={() => saveObject.exportGame()} export={() => saveObject.exportGame()}
forceKill={() => { forceKill={killAllScripts}
for (const server of GetAllServers()) {
server.runningScripts = [];
}
dialogBoxCreate("Forcefully deleted all running scripts. Please save and refresh page.");
}}
softReset={() => { softReset={() => {
dialogBoxCreate("Soft Reset!"); dialogBoxCreate("Soft Reset!");
prestigeAugmentation(); prestigeAugmentation();

@ -6,6 +6,7 @@ import makeStyles from "@mui/styles/makeStyles";
import createStyles from "@mui/styles/createStyles"; import createStyles from "@mui/styles/createStyles";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
import { Reputation } from "./Reputation"; import { Reputation } from "./Reputation";
import { KillScriptsModal } from "./KillScriptsModal";
import Table from "@mui/material/Table"; import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody"; import TableBody from "@mui/material/TableBody";
@ -15,12 +16,14 @@ import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import SaveIcon from "@mui/icons-material/Save"; import SaveIcon from "@mui/icons-material/Save";
import ClearAllIcon from "@mui/icons-material/ClearAll";
import { Settings } from "../../Settings/Settings"; import { Settings } from "../../Settings/Settings";
import { use } from "../Context"; import { use } from "../Context";
interface IProps { interface IProps {
save: () => void; save: () => void;
killScripts: () => void;
} }
function Intelligence(): React.ReactElement { function Intelligence(): React.ReactElement {
@ -136,7 +139,8 @@ const useStyles = makeStyles((theme: Theme) =>
}), }),
); );
export function CharacterOverview({ save }: IProps): React.ReactElement { export function CharacterOverview({ save, killScripts }: IProps): React.ReactElement {
const [killOpen, setKillOpen] = useState(false);
const player = use.Player(); const player = use.Player();
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
@ -148,6 +152,7 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
const classes = useStyles(); const classes = useStyles();
return ( return (
<>
<Table sx={{ display: "block", m: 1 }}> <Table sx={{ display: "block", m: 1 }}>
<TableBody> <TableBody>
<TableRow> <TableRow>
@ -187,7 +192,9 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
<Typography classes={{ root: classes.hack }}>Hack&nbsp;</Typography> <Typography classes={{ root: classes.hack }}>Hack&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cell }}> <TableCell align="right" classes={{ root: classes.cell }}>
<Typography classes={{ root: classes.hack }}>{numeralWrapper.formatSkill(player.hacking_skill)}</Typography> <Typography classes={{ root: classes.hack }}>
{numeralWrapper.formatSkill(player.hacking_skill)}
</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cell }}> <TableCell align="right" classes={{ root: classes.cell }}>
<Typography id="overview-hack-hook" classes={{ root: classes.hack }}> <Typography id="overview-hack-hook" classes={{ root: classes.hack }}>
@ -287,13 +294,20 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
<Bladeburner /> <Bladeburner />
<TableRow> <TableRow>
<TableCell align="center" colSpan={2} classes={{ root: classes.cellNone }}> <TableCell align="center" classes={{ root: classes.cellNone }}>
<IconButton onClick={save}> <IconButton onClick={save}>
<SaveIcon color={Settings.AutosaveInterval !== 0 ? "primary" : "error"} /> <SaveIcon color={Settings.AutosaveInterval !== 0 ? "primary" : "error"} />
</IconButton> </IconButton>
</TableCell> </TableCell>
<TableCell align="center" classes={{ root: classes.cellNone }}>
<IconButton onClick={() => setKillOpen(true)}>
<ClearAllIcon color="error" />
</IconButton>
</TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>
</Table> </Table>
<KillScriptsModal open={killOpen} onClose={() => setKillOpen(false)} killScripts={killScripts} />
</>
); );
} }

@ -0,0 +1,24 @@
import React from "react";
import { Modal } from "./Modal";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
interface IProps {
open: boolean;
onClose: () => void;
killScripts: () => void;
}
export function KillScriptsModal(props: IProps): React.ReactElement {
function onClick(): void {
props.killScripts();
props.onClose();
}
return (
<Modal open={props.open} onClose={props.onClose}>
<Typography>Forcefully kill all running scripts? This will also save your game and reload the game.</Typography>
<Button onClick={onClick}>KILL</Button>
</Modal>
);
}