MISC: Added features to DevMenu (#353)

* More blade devmenu functions
* Custom money field, set money to 0 option
* Options for removing blade/gang/corp
* Better dev menu responsiveness (dev menu rerenders after adding or removing blade/gang/corp)
* Some general code style changes
This commit is contained in:
Zelow79 2023-02-02 10:09:38 -05:00 committed by GitHub
parent 35d590b25d
commit 37f41c89bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 150 additions and 87 deletions

@ -1,54 +1,52 @@
import React from "react"; import React from "react";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Accordion from "@mui/material/Accordion"; import Accordion from "@mui/material/Accordion";
import AccordionSummary from "@mui/material/AccordionSummary"; import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails"; import AccordionDetails from "@mui/material/AccordionDetails";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import Button from "@mui/material/Button";
import { Adjuster } from "./Adjuster"; import { Adjuster } from "./Adjuster";
import { Player } from "@player"; import { Player } from "@player";
import { CityName } from "../../Enums";
const bigNumber = 1e27; const bigNumber = 1e27;
export function Bladeburner(): React.ReactElement { export function Bladeburner(): React.ReactElement {
if (!Player.bladeburner) return <></>;
const bladeburner = Player.bladeburner; const bladeburner = Player.bladeburner;
if (bladeburner === null) return <></>;
function modifyBladeburnerRank(modify: number): (x: number) => void {
return function (rank: number): void {
if (!bladeburner) return;
bladeburner.changeRank(Player, rank * modify);
};
}
function resetBladeburnerRank(): void { // Rank functions
if (!bladeburner) return; const modifyBladeburnerRank = (modify: number) => (rank: number) => bladeburner.changeRank(Player, rank * modify);
const resetBladeburnerRank = () => {
bladeburner.rank = 0; bladeburner.rank = 0;
bladeburner.maxRank = 0; bladeburner.maxRank = 0;
}
function addTonsBladeburnerRank(): void {
if (!bladeburner) return;
bladeburner.changeRank(Player, bigNumber);
}
function modifyBladeburnerCycles(modify: number): (x: number) => void {
return function (cycles: number): void {
if (!bladeburner) return;
bladeburner.storedCycles += cycles * modify;
}; };
} const addTonsBladeburnerRank = () => bladeburner.changeRank(Player, bigNumber);
function resetBladeburnerCycles(): void { // Skill point functions
if (!bladeburner) return; const modifyBladeburnerSP = (modify: number) => (skillPoints: number) => {
bladeburner.storedCycles = 0; bladeburner.skillPoints += skillPoints * modify;
} };
const resetBladeburnerSP = () => {
bladeburner.skillPoints = 0;
bladeburner.totalSkillPoints = 0;
};
const addTonsBladeburnerSP = () => (bladeburner.skillPoints = bigNumber);
function addTonsBladeburnerCycles(): void { // Cycles functions
if (!bladeburner) return; const modifyBladeburnerCycles = (modify: number) => (cycles: number) => (bladeburner.storedCycles += cycles * modify);
bladeburner.storedCycles += bigNumber; const resetBladeburnerCycles = () => (bladeburner.storedCycles = 0);
} const addTonsBladeburnerCycles = () => (bladeburner.storedCycles += bigNumber);
// Chaos functions
const wipeAllChaos = () => Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos = 0));
const wipeActiveCityChaos = () => (bladeburner.cities[bladeburner.city].chaos = 0);
const addAllChaos = (modify: number) => (chaos: number) => {
Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos += chaos * modify));
};
const addTonsAllChaos = () => {
Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos += bigNumber));
};
return ( return (
<Accordion TransitionProps={{ unmountOnExit: true }}> <Accordion TransitionProps={{ unmountOnExit: true }}>
@ -73,6 +71,21 @@ export function Bladeburner(): React.ReactElement {
/> />
</td> </td>
</tr> </tr>
<tr>
<td>
<Typography>SP:</Typography>
</td>
<td>
<Adjuster
label="skill points"
placeholder="amt"
tons={addTonsBladeburnerSP}
add={modifyBladeburnerSP(1)}
subtract={modifyBladeburnerSP(-1)}
reset={resetBladeburnerSP}
/>
</td>
</tr>
<tr> <tr>
<td> <td>
<Typography>Cycles: </Typography> <Typography>Cycles: </Typography>
@ -88,9 +101,25 @@ export function Bladeburner(): React.ReactElement {
/> />
</td> </td>
</tr> </tr>
<tr>
<td>
<Typography title="This is for ALL cities">Chaos:</Typography>
</td>
<td>
<Adjuster
label="chaos in all cities"
placeholder="amt"
tons={addTonsAllChaos}
add={addAllChaos(1)}
subtract={addAllChaos(-1)}
reset={wipeAllChaos}
/>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</AccordionDetails> </AccordionDetails>
<Button onClick={wipeActiveCityChaos}>Clear Active City's Chaos</Button>
</Accordion> </Accordion>
); );
} }

@ -1,10 +1,8 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import Accordion from "@mui/material/Accordion"; import Accordion from "@mui/material/Accordion";
import AccordionSummary from "@mui/material/AccordionSummary"; import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails"; import AccordionDetails from "@mui/material/AccordionDetails";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
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 { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
@ -15,59 +13,68 @@ import { Bladeburner } from "../../Bladeburner/Bladeburner";
import { GangConstants } from "../../Gang/data/Constants"; import { GangConstants } from "../../Gang/data/Constants";
import { FactionNames } from "../../Faction/data/FactionNames"; import { FactionNames } from "../../Faction/data/FactionNames";
import { checkForMessagesToSend } from "../../Message/MessageHelpers"; import { checkForMessagesToSend } from "../../Message/MessageHelpers";
import { ThemeEvents } from "../../Themes/ui/Theme";
export function General(): React.ReactElement { export function General(): React.ReactElement {
const [error, setError] = useState(false); const [error, setError] = useState(false);
const [corporationName, setCorporationName] = useState(""); const [corporationName, setCorporationName] = useState("");
const [gangFaction, setGangFaction] = useState(""); const [gangFaction, setGangFaction] = useState("Slum Snakes");
const [devMoney, setDevMoney] = useState(0);
function addMoney(n: number) { // Money functions
return function () { const addCustomMoney = () => !Number.isNaN(devMoney) && Player.gainMoney(devMoney, "other");
Player.gainMoney(n, "other"); const addMoney = (n: number) => () => Player.gainMoney(n, "other");
}; const setMoney = (n: number) => () => (Player.money = Number(n));
}
function upgradeRam(): void { // Ram functions
Player.getHomeComputer().maxRam *= 2; const upgradeRam = () => (Player.getHomeComputer().maxRam *= 2);
}
function quickB1tFlum3(): void { // Node-clearing functions
Router.toBitVerse(true, true); const quickB1tFlum3 = () => Router.toBitVerse(true, true);
} const b1tflum3 = () => Router.toBitVerse(true, false);
const quickHackW0r1dD43m0n = () => Router.toBitVerse(false, true);
const hackW0r1dD43m0n = () => Router.toBitVerse(false, false);
function b1tflum3(): void { // Corp functions
Router.toBitVerse(true, false); const createCorporation = () => {
}
function quickHackW0r1dD43m0n(): void {
Router.toBitVerse(false, true);
}
function hackW0r1dD43m0n(): void {
Router.toBitVerse(false, false);
}
function createCorporation(): void {
Player.startCorporation(corporationName); Player.startCorporation(corporationName);
} // Rerender so the corp menu option will show up immediately on the devmenu page selection
ThemeEvents.emit();
};
const destroyCorporation = () => {
Player.corporation = null;
// Rerender so the corp menu option will be removed immediately on the devmenu page selection
ThemeEvents.emit();
};
function joinBladeburner(): void { // Blade functions
const joinBladeburner = () => {
Player.bladeburner = new Bladeburner(); Player.bladeburner = new Bladeburner();
} // Rerender so the blade menu option will show up immediately on the devmenu page selection
ThemeEvents.emit();
};
const leaveBladeburner = () => {
Player.bladeburner = null;
// Rerender so the blade menu option will be removed immediately on the devmenu page selection
ThemeEvents.emit();
};
function startGang(): void { // Gang functions
const startGang = () => {
const isHacking = gangFaction === FactionNames.NiteSec || gangFaction === FactionNames.TheBlackHand; const isHacking = gangFaction === FactionNames.NiteSec || gangFaction === FactionNames.TheBlackHand;
Player.startGang(gangFaction, isHacking); Player.startGang(gangFaction, isHacking);
} // Rerender so the gang menu option will show up immediately on the devmenu page selection
ThemeEvents.emit();
function setGangFactionDropdown(event: SelectChangeEvent<string>): void { };
setGangFaction(event.target.value); const stopGang = () => {
} Player.gang = null;
// Rerender so the gang menu option will be removed immediately on the devmenu page selection
function checkMessages(): void { ThemeEvents.emit();
checkForMessagesToSend(); };
} const setGangFactionDropdown = (event: SelectChangeEvent<string>) => setGangFaction(event.target.value);
// Misc functions
const checkMessages = () => checkForMessagesToSend();
useEffect(() => { useEffect(() => {
if (error) throw new ReferenceError("Manually thrown error"); if (error) throw new ReferenceError("Manually thrown error");
}, [error]); }, [error]);
@ -78,6 +85,14 @@ export function General(): React.ReactElement {
<Typography>General</Typography> <Typography>General</Typography>
</AccordionSummary> </AccordionSummary>
<AccordionDetails> <AccordionDetails>
<Button
onClick={setMoney(0)}
title="This sets your money to $0, this means the money you had will just vanish without being accounted for where it went and may offset some metrics."
>
<pre>
= <Money money={0} />
</pre>
</Button>
<Button onClick={addMoney(1e6)}> <Button onClick={addMoney(1e6)}>
<pre> <pre>
+ <Money money={1e6} /> + <Money money={1e6} />
@ -105,10 +120,24 @@ export function General(): React.ReactElement {
</Button> </Button>
<Button onClick={upgradeRam}>+ RAM</Button> <Button onClick={upgradeRam}>+ RAM</Button>
<br /> <br />
<Typography>Add Custom Money</Typography>
<TextField onChange={(x) => setDevMoney(parseFloat(x.target.value))} />
<Button onClick={addCustomMoney}>Give Money</Button>
<br />
{Player.corporation ? (
<Button onClick={destroyCorporation}>Destroy Corporation</Button>
) : (
<>
<Typography>Corporation Name:</Typography> <Typography>Corporation Name:</Typography>
<TextField value={corporationName} onChange={(x) => setCorporationName(x.target.value)} /> <TextField value={corporationName} onChange={(x) => setCorporationName(x.target.value)} />
<Button onClick={createCorporation}>Create Corporation</Button> <Button onClick={createCorporation}>Create Corporation</Button>
</>
)}
<br /> <br />
{Player.gang ? (
<Button onClick={stopGang}>Stop Gang</Button>
) : (
<>
<Typography>Gang Faction:</Typography> <Typography>Gang Faction:</Typography>
<Select value={gangFaction} onChange={setGangFactionDropdown}> <Select value={gangFaction} onChange={setGangFactionDropdown}>
{GangConstants.Names.map((factionName) => ( {GangConstants.Names.map((factionName) => (
@ -118,10 +147,15 @@ export function General(): React.ReactElement {
))} ))}
</Select> </Select>
<Button onClick={startGang}>Start Gang</Button> <Button onClick={startGang}>Start Gang</Button>
</>
)}
<br /> <br />
{Player.bladeburner ? (
<Button onClick={leaveBladeburner}>Leave BladeBurner</Button>
) : (
<Button onClick={joinBladeburner}>Join BladeBurner</Button> <Button onClick={joinBladeburner}>Join BladeBurner</Button>
)}
<br /> <br />
<Button onClick={quickB1tFlum3}>Quick b1t_flum3.exe</Button> <Button onClick={quickB1tFlum3}>Quick b1t_flum3.exe</Button>
<Button onClick={b1tflum3}>Run b1t_flum3.exe</Button> <Button onClick={b1tflum3}>Run b1t_flum3.exe</Button>
<Button onClick={quickHackW0r1dD43m0n}>Quick w0rld_d34m0n</Button> <Button onClick={quickHackW0r1dD43m0n}>Quick w0rld_d34m0n</Button>