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,152 +152,162 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
const classes = useStyles(); const classes = useStyles();
return ( return (
<Table sx={{ display: "block", m: 1 }}> <>
<TableBody> <Table sx={{ display: "block", m: 1 }}>
<TableRow> <TableBody>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}> <TableRow>
<Typography classes={{ root: classes.hp }}>HP&nbsp;</Typography> <TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
</TableCell> <Typography classes={{ root: classes.hp }}>HP&nbsp;</Typography>
<TableCell align="right" classes={{ root: classes.cellNone }}> </TableCell>
<Typography classes={{ root: classes.hp }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
{numeralWrapper.formatHp(player.hp)}&nbsp;/&nbsp;{numeralWrapper.formatHp(player.max_hp)} <Typography classes={{ root: classes.hp }}>
</Typography> {numeralWrapper.formatHp(player.hp)}&nbsp;/&nbsp;{numeralWrapper.formatHp(player.max_hp)}
</TableCell> </Typography>
<TableCell align="right" classes={{ root: classes.cellNone }}> </TableCell>
<Typography id="overview-hp-hook" classes={{ root: classes.hp }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
{/*Hook for player scripts*/} <Typography id="overview-hp-hook" classes={{ root: classes.hp }}>
</Typography> {/*Hook for player scripts*/}
</TableCell> </Typography>
</TableRow> </TableCell>
</TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}> <TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.money }}>Money&nbsp;</Typography> <Typography classes={{ root: classes.money }}>Money&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.money }}> <Typography classes={{ root: classes.money }}>
{numeralWrapper.formatMoney(player.money.toNumber())} {numeralWrapper.formatMoney(player.money.toNumber())}
</Typography> </Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-money-hook" classes={{ root: classes.money }}> <Typography id="overview-money-hook" classes={{ root: classes.money }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cell }}> <TableCell component="th" scope="row" classes={{ root: classes.cell }}>
<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 }}>
</TableCell> {numeralWrapper.formatSkill(player.hacking_skill)}
<TableCell align="right" classes={{ root: classes.cell }}> </Typography>
<Typography id="overview-hack-hook" classes={{ root: classes.hack }}> </TableCell>
{/*Hook for player scripts*/} <TableCell align="right" classes={{ root: classes.cell }}>
</Typography> <Typography id="overview-hack-hook" classes={{ root: classes.hack }}>
</TableCell> {/*Hook for player scripts*/}
</TableRow> </Typography>
</TableCell>
</TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}> <TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.combat }}>Str&nbsp;</Typography> <Typography classes={{ root: classes.combat }}>Str&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.strength)}</Typography> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.strength)}</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-str-hook" classes={{ root: classes.combat }}> <Typography id="overview-str-hook" classes={{ root: classes.combat }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}> <TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.combat }}>Def&nbsp;</Typography> <Typography classes={{ root: classes.combat }}>Def&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.defense)}</Typography> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.defense)}</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-def-hook" classes={{ root: classes.combat }}> <Typography id="overview-def-hook" classes={{ root: classes.combat }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}> <TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.combat }}>Dex&nbsp;</Typography> <Typography classes={{ root: classes.combat }}>Dex&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.dexterity)}</Typography> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.dexterity)}</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-dex-hook" classes={{ root: classes.combat }}> <Typography id="overview-dex-hook" classes={{ root: classes.combat }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cell }}> <TableCell component="th" scope="row" classes={{ root: classes.cell }}>
<Typography classes={{ root: classes.combat }}>Agi&nbsp;</Typography> <Typography classes={{ root: classes.combat }}>Agi&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cell }}> <TableCell align="right" classes={{ root: classes.cell }}>
<Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.agility)}</Typography> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.agility)}</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cell }}> <TableCell align="right" classes={{ root: classes.cell }}>
<Typography id="overview-agi-hook" classes={{ root: classes.combat }}> <Typography id="overview-agi-hook" classes={{ root: classes.combat }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}> <TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.cha }}>Cha&nbsp;</Typography> <Typography classes={{ root: classes.cha }}>Cha&nbsp;</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography classes={{ root: classes.cha }}>{numeralWrapper.formatSkill(player.charisma)}</Typography> <Typography classes={{ root: classes.cha }}>{numeralWrapper.formatSkill(player.charisma)}</Typography>
</TableCell> </TableCell>
<TableCell align="right" classes={{ root: classes.cellNone }}> <TableCell align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-cha-hook" classes={{ root: classes.cha }}> <Typography id="overview-cha-hook" classes={{ root: classes.cha }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<Intelligence /> <Intelligence />
<TableRow> <TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cell }}> <TableCell component="th" scope="row" classes={{ root: classes.cell }}>
<Typography id="overview-extra-hook-0" classes={{ root: classes.hack }}> <Typography id="overview-extra-hook-0" classes={{ root: classes.hack }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
<TableCell component="th" scope="row" align="right" classes={{ root: classes.cell }}> <TableCell component="th" scope="row" align="right" classes={{ root: classes.cell }}>
<Typography id="overview-extra-hook-1" classes={{ root: classes.hack }}> <Typography id="overview-extra-hook-1" classes={{ root: classes.hack }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
<TableCell component="th" scope="row" align="right" classes={{ root: classes.cell }}> <TableCell component="th" scope="row" align="right" classes={{ root: classes.cell }}>
<Typography id="overview-extra-hook-2" classes={{ root: classes.hack }}> <Typography id="overview-extra-hook-2" classes={{ root: classes.hack }}>
{/*Hook for player scripts*/} {/*Hook for player scripts*/}
</Typography> </Typography>
</TableCell> </TableCell>
</TableRow> </TableRow>
<Work /> <Work />
<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>
</TableRow> <TableCell align="center" classes={{ root: classes.cellNone }}>
</TableBody> <IconButton onClick={() => setKillOpen(true)}>
</Table> <ClearAllIcon color="error" />
</IconButton>
</TableCell>
</TableRow>
</TableBody>
</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>
);
}