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> = {};
(function () {
// General Actions
let actionName;
actionName = "Training";
GeneralActions[actionName] = new Action({
name: actionName,
});
let actionNames : Array<string> = [
"Training",
"Field Analysis",
"Recruitment",
"Diplomacy",
"Hyperbolic Regeneration Chamber",
"Incite Violence"
];
actionName = "Field Analysis";
for (let actionName of actionNames){
GeneralActions[actionName] = new Action({
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 {
const division = useDivision();
if (!division.hasResearch("Market-TA.II")) return <></>;
props.mat.marketTa2 = false;
const [newCost, setNewCost] = useState<number>(props.mat.bCost);
const setRerender = useState(false)[1];
function rerender(): void {
@ -88,7 +87,6 @@ interface IProps {
// Create a popup that lets the player use the Market TA research for Materials
export function MaterialMarketTaModal(props: IProps): React.ReactElement {
const division = useDivision();
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
@ -102,13 +100,12 @@ export function MaterialMarketTaModal(props: IProps): React.ReactElement {
return (
<Modal open={props.open} onClose={props.onClose}>
{!division.hasResearch("Market-TA.II") && (
<>
<Typography variant="h4">Market-TA.I</Typography>
<Typography>
The maximum sale price you can mark this up to is{" "}
{numeralWrapper.formatMoney(props.mat.bCost + markupLimit)}. This means that if you set the sale price
higher than this, you will begin to experience a loss in number of sales
The maximum sale price you can mark this up to is {numeralWrapper.formatMoney(props.mat.bCost + markupLimit)}.
This means that if you set the sale price higher than this, you will begin to experience a loss in number of
sales
</Typography>
<FormControlLabel
@ -127,7 +124,7 @@ export function MaterialMarketTaModal(props: IProps): React.ReactElement {
}
/>
</>
)}
<MarketTA2 mat={props.mat} />
</Modal>
);

@ -16,7 +16,6 @@ interface ITa2Props {
function MarketTA2(props: ITa2Props): React.ReactElement {
const division = useDivision();
if (!division.hasResearch("Market-TA.II")) return <></>;
props.product.marketTa1 = false;
const markupLimit = props.product.rat / props.product.mku;
const [value, setValue] = useState(props.product.pCost);
const setRerender = useState(false)[1];
@ -93,7 +92,6 @@ export function ProductMarketTaModal(props: IProps): React.ReactElement {
return (
<Modal open={props.open} onClose={props.onClose}>
{!division.hasResearch("Market-TA.II") && (
<>
<Typography variant="h4">Market-TA.I</Typography>
<Typography>
@ -118,7 +116,7 @@ export function ProductMarketTaModal(props: IProps): React.ReactElement {
}
/>
</>
)}
<MarketTA2 product={props.product} />
</Modal>
);

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

@ -265,7 +265,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
content: (
<>
<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>
</>
@ -296,7 +296,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
content: (
<>
<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>
</>
@ -468,7 +468,7 @@ export function InteractiveTutorialRoot(): React.ReactElement {
[iTutorialSteps.HacknetNodesIntroduction as number]: {
content: (
<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>
),
canNext: true,

@ -11,8 +11,6 @@ import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
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 Button from "@mui/material/Button";
import IconButton from "@mui/material/IconButton";
@ -150,9 +148,7 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
const classes = useStyles();
return (
<Paper square>
<Box m={1}>
<Table size="small">
<Table sx={{ display: "block", m: 1 }}>
<TableBody>
<TableRow>
<TableCell component="th" scope="row" classes={{ root: classes.cellNone }}>
@ -191,9 +187,7 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
<Typography classes={{ root: classes.hack }}>Hack&nbsp;</Typography>
</TableCell>
<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 align="right" classes={{ root: classes.cell }}>
<Typography id="overview-hack-hook" classes={{ root: classes.hack }}>
@ -207,9 +201,7 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
<Typography classes={{ root: classes.combat }}>Str&nbsp;</Typography>
</TableCell>
<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 align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-str-hook" classes={{ root: classes.combat }}>
@ -237,9 +229,7 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
<Typography classes={{ root: classes.combat }}>Dex&nbsp;</Typography>
</TableCell>
<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 align="right" classes={{ root: classes.cellNone }}>
<Typography id="overview-dex-hook" classes={{ root: classes.combat }}>
@ -305,7 +295,5 @@ export function CharacterOverview({ save }: IProps): React.ReactElement {
</TableRow>
</TableBody>
</Table>
</Box>
</Paper>
);
}

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