Merge pull request #1550 from danielyxie/dev

Throw error when trying to pass non-string/number to other scripts
This commit is contained in:
hydroflame 2021-10-18 14:30:04 -04:00 committed by GitHub
commit 2ffb435598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 242 additions and 268 deletions

26
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

@ -3,35 +3,17 @@ import { IMap } from "../types";
export const GeneralActions: IMap<Action> = {}; export const GeneralActions: IMap<Action> = {};
(function () { let actionNames : Array<string> = [
// General Actions "Training",
let actionName; "Field Analysis",
actionName = "Training"; "Recruitment",
GeneralActions[actionName] = new Action({ "Diplomacy",
name: actionName, "Hyperbolic Regeneration Chamber",
}); "Incite Violence"
];
actionName = "Field Analysis"; for (let actionName of actionNames){
GeneralActions[actionName] = new Action({ GeneralActions[actionName] = new Action({
name: actionName, name: actionName,
}); });
}
actionName = "Recruitment";
GeneralActions[actionName] = new Action({
name: actionName,
});
actionName = "Diplomacy";
GeneralActions[actionName] = new Action({
name: actionName,
});
actionName = "Hyperbolic Regeneration Chamber";
GeneralActions[actionName] = new Action({
name: actionName,
});
actionName = "Incite Violence";
GeneralActions[actionName] = new Action({
name: actionName,
});
})();

@ -16,7 +16,6 @@ interface IMarketTA2Props {
function MarketTA2(props: IMarketTA2Props): React.ReactElement { function MarketTA2(props: IMarketTA2Props): React.ReactElement {
const division = useDivision(); const division = useDivision();
if (!division.hasResearch("Market-TA.II")) return <></>; if (!division.hasResearch("Market-TA.II")) return <></>;
props.mat.marketTa2 = false;
const [newCost, setNewCost] = useState<number>(props.mat.bCost); const [newCost, setNewCost] = useState<number>(props.mat.bCost);
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
function rerender(): void { function rerender(): void {
@ -88,7 +87,6 @@ interface IProps {
// Create a popup that lets the player use the Market TA research for Materials // Create a popup that lets the player use the Market TA research for Materials
export function MaterialMarketTaModal(props: IProps): React.ReactElement { export function MaterialMarketTaModal(props: IProps): React.ReactElement {
const division = useDivision();
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
function rerender(): void { function rerender(): void {
setRerender((old) => !old); setRerender((old) => !old);
@ -102,32 +100,31 @@ export function MaterialMarketTaModal(props: IProps): React.ReactElement {
return ( return (
<Modal open={props.open} onClose={props.onClose}> <Modal open={props.open} onClose={props.onClose}>
{!division.hasResearch("Market-TA.II") && ( <>
<> <Typography variant="h4">Market-TA.I</Typography>
<Typography variant="h4">Market-TA.I</Typography> <Typography>
<Typography> The maximum sale price you can mark this up to is {numeralWrapper.formatMoney(props.mat.bCost + markupLimit)}.
The maximum sale price you can mark this up to is{" "} This means that if you set the sale price higher than this, you will begin to experience a loss in number of
{numeralWrapper.formatMoney(props.mat.bCost + markupLimit)}. This means that if you set the sale price sales
higher than this, you will begin to experience a loss in number of sales </Typography>
</Typography>
<FormControlLabel
control={<Switch checked={props.mat.marketTa1} onChange={onMarketTA1} />}
label={
<Tooltip
title={
<Typography>
If this is enabled, then this Material will automatically be sold at the price identified by
Market-TA.I (i.e. the price shown above)
</Typography>
}
>
<Typography>Use Market-TA.I for Auto-Sale Price</Typography>
</Tooltip>
}
/>
</>
<FormControlLabel
control={<Switch checked={props.mat.marketTa1} onChange={onMarketTA1} />}
label={
<Tooltip
title={
<Typography>
If this is enabled, then this Material will automatically be sold at the price identified by
Market-TA.I (i.e. the price shown above)
</Typography>
}
>
<Typography>Use Market-TA.I for Auto-Sale Price</Typography>
</Tooltip>
}
/>
</>
)}
<MarketTA2 mat={props.mat} /> <MarketTA2 mat={props.mat} />
</Modal> </Modal>
); );

@ -16,7 +16,6 @@ interface ITa2Props {
function MarketTA2(props: ITa2Props): React.ReactElement { function MarketTA2(props: ITa2Props): React.ReactElement {
const division = useDivision(); const division = useDivision();
if (!division.hasResearch("Market-TA.II")) return <></>; if (!division.hasResearch("Market-TA.II")) return <></>;
props.product.marketTa1 = false;
const markupLimit = props.product.rat / props.product.mku; const markupLimit = props.product.rat / props.product.mku;
const [value, setValue] = useState(props.product.pCost); const [value, setValue] = useState(props.product.pCost);
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
@ -93,32 +92,31 @@ export function ProductMarketTaModal(props: IProps): React.ReactElement {
return ( return (
<Modal open={props.open} onClose={props.onClose}> <Modal open={props.open} onClose={props.onClose}>
{!division.hasResearch("Market-TA.II") && ( <>
<> <Typography variant="h4">Market-TA.I</Typography>
<Typography variant="h4">Market-TA.I</Typography> <Typography>
<Typography> The maximum sale price you can mark this up to is{" "}
The maximum sale price you can mark this up to is{" "} {numeralWrapper.formatMoney(props.product.pCost + markupLimit)}. This means that if you set the sale price
{numeralWrapper.formatMoney(props.product.pCost + markupLimit)}. This means that if you set the sale price higher than this, you will begin to experience a loss in number of sales
higher than this, you will begin to experience a loss in number of sales </Typography>
</Typography>
<FormControlLabel
control={<Switch checked={props.product.marketTa1} onChange={onChange} />}
label={
<Tooltip
title={
<Typography>
If this is enabled, then this Material will automatically be sold at the price identified by
Market-TA.I (i.e. the price shown above)
</Typography>
}
>
<Typography>Use Market-TA.I for Auto-Sale Price</Typography>
</Tooltip>
}
/>
</>
<FormControlLabel
control={<Switch checked={props.product.marketTa1} onChange={onChange} />}
label={
<Tooltip
title={
<Typography>
If this is enabled, then this Material will automatically be sold at the price identified by
Market-TA.I (i.e. the price shown above)
</Typography>
}
>
<Typography>Use Market-TA.I for Auto-Sale Price</Typography>
</Tooltip>
}
/>
</>
)}
<MarketTA2 product={props.product} /> <MarketTA2 product={props.product} />
</Modal> </Modal>
); );

@ -646,9 +646,9 @@ export function runScriptFromScript(
return 0; return 0;
} }
args = args.map((arg) => { args.forEach((arg) => {
if (typeof arg === "number") return arg; if (typeof arg !== "string" && typeof arg !== "number")
return arg + ""; // force cast to string throw new Error("Only strings and numbers can be passed as arguments to otherscripts.");
}); });
// Check if the script is already running // Check if the script is already running

@ -265,7 +265,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
content: ( content: (
<> <>
<Typography>You now have root access! You can hack the server using </Typography> <Typography>You now have root access! You can hack the server using </Typography>
<Typography classes={{ root: classes.textfield }}>{"[home ~/]> hack"}</Typography> <Typography classes={{ root: classes.textfield }}>{"[n00dles ~/]> hack"}</Typography>
<Typography> Try doing that now.</Typography> <Typography> Try doing that now.</Typography>
</> </>
@ -296,7 +296,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
content: ( content: (
<> <>
<Typography>From any server you can get back home using</Typography> <Typography>From any server you can get back home using</Typography>
<Typography classes={{ root: classes.textfield }}>{"[home ~/]> home"}</Typography> <Typography classes={{ root: classes.textfield }}>{"[n00dles ~/]> home"}</Typography>
<Typography>Let's head home before creating our first script!</Typography> <Typography>Let's head home before creating our first script!</Typography>
</> </>
@ -468,7 +468,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
[iTutorialSteps.HacknetNodesIntroduction as number]: { [iTutorialSteps.HacknetNodesIntroduction as number]: {
content: ( content: (
<Typography> <Typography>
here you can purchase new Hacknet Nodes and upgrade your existing ones. Let's purchase a new one now. Here you can purchase new Hacknet Nodes and upgrade your existing ones. Let's purchase a new one now.
</Typography> </Typography>
), ),
canNext: true, canNext: true,

@ -11,8 +11,6 @@ import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody"; import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell"; import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow"; import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography"; 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";
@ -150,162 +148,152 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
const classes = useStyles(); const classes = useStyles();
return ( return (
<Paper square> <Table sx={{ display: "block", m: 1 }}>
<Box m={1}> <TableBody>
<Table size="small"> <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 }}> <Typography classes={{ root: classes.hack }}>{numeralWrapper.formatSkill(player.hacking_skill)}</Typography>
{numeralWrapper.formatSkill(player.hacking_skill)} </TableCell>
</Typography> <TableCell align="right" classes={{ root: classes.cell }}>
</TableCell> <Typography id="overview-hack-hook" classes={{ root: classes.hack }}>
<TableCell align="right" classes={{ root: classes.cell }}> {/*Hook for player scripts*/}
<Typography id="overview-hack-hook" classes={{ root: classes.hack }}> </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.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 }}> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.strength)}</Typography>
{numeralWrapper.formatSkill(player.strength)} </TableCell>
</Typography> <TableCell align="right" classes={{ root: classes.cellNone }}>
</TableCell> <Typography id="overview-str-hook" classes={{ root: classes.combat }}>
<TableCell align="right" classes={{ root: classes.cellNone }}> {/*Hook for player scripts*/}
<Typography id="overview-str-hook" classes={{ root: classes.combat }}> </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.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 }}> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.dexterity)}</Typography>
{numeralWrapper.formatSkill(player.dexterity)} </TableCell>
</Typography> <TableCell align="right" classes={{ root: classes.cellNone }}>
</TableCell> <Typography id="overview-dex-hook" classes={{ root: classes.combat }}>
<TableCell align="right" classes={{ root: classes.cellNone }}> {/*Hook for player scripts*/}
<Typography id="overview-dex-hook" classes={{ root: classes.combat }}> </Typography>
{/*Hook for player scripts*/} </TableCell>
</Typography> </TableRow>
</TableCell> <TableRow>
</TableRow> <TableCell component="th" scope="row" classes={{ root: classes.cell }}>
<TableRow> <Typography classes={{ root: classes.combat }}>Agi&nbsp;</Typography>
<TableCell component="th" scope="row" classes={{ root: classes.cell }}> </TableCell>
<Typography classes={{ root: classes.combat }}>Agi&nbsp;</Typography> <TableCell align="right" classes={{ root: classes.cell }}>
</TableCell> <Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.agility)}</Typography>
<TableCell align="right" classes={{ root: classes.cell }}> </TableCell>
<Typography classes={{ root: classes.combat }}>{numeralWrapper.formatSkill(player.agility)}</Typography> <TableCell align="right" classes={{ root: classes.cell }}>
</TableCell> <Typography id="overview-agi-hook" classes={{ root: classes.combat }}>
<TableCell align="right" classes={{ root: classes.cell }}> {/*Hook for player scripts*/}
<Typography id="overview-agi-hook" classes={{ root: classes.combat }}> </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.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" colSpan={2} 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> </TableRow>
</TableBody> </TableBody>
</Table> </Table>
</Box>
</Paper>
); );
} }

@ -1,17 +1,29 @@
import React, { useState } from "react"; import React, { useState } from "react";
import makeStyles from "@mui/styles/makeStyles"; import makeStyles from "@mui/styles/makeStyles";
import Box from "@mui/material/Box";
import Collapse from "@mui/material/Collapse"; import Collapse from "@mui/material/Collapse";
import Fab from "@mui/material/Fab"; import Fab from "@mui/material/Fab";
import Paper from "@mui/material/Paper";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff"; import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import VisibilityIcon from "@mui/icons-material/Visibility"; import VisibilityIcon from "@mui/icons-material/Visibility";
import { use } from "../Context"; import { use } from "../Context";
import { Page } from "../Router"; import { Page } from "../Router";
const useStyles = makeStyles({ const useStyles = makeStyles({
nobackground: { visibilityToggle: {
backgroundColor: "#0000", backgroundColor: "transparent",
position: "absolute",
top: "100%",
right: 0,
},
overviewContainer: {
position: "fixed",
top: 0,
right: 0,
zIndex: 1500,
display: "flex",
justifyContent: "flex-end",
flexDirection: "column",
}, },
}); });
@ -30,16 +42,13 @@ export function Overview({ children }: IProps): React.ReactElement {
} else { } else {
icon = <VisibilityIcon color="primary" />; icon = <VisibilityIcon color="primary" />;
} }
return ( return (
<div style={{ position: "fixed", top: 0, right: 0, zIndex: 1500 }}> <Paper square classes={{ root: classes.overviewContainer }}>
<Box display="flex" justifyContent="flex-end" flexDirection={"column"}> <Collapse in={open}>{children}</Collapse>
<Collapse in={open}>{children}</Collapse> <Fab size="small" classes={{ root: classes.visibilityToggle }} onClick={() => setOpen((old) => !old)}>
<Box display="flex" justifyContent="flex-end"> {icon}
<Fab classes={{ root: classes.nobackground }} onClick={() => setOpen((old) => !old)}> </Fab>
{icon} </Paper>
</Fab>
</Box>
</Box>
</div>
); );
} }