bitburner-src/src/DevMenu/ui/SourceFiles.tsx

112 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-09-14 02:37:35 +02:00
import React from "react";
2021-09-17 01:23:03 +02:00
import Accordion from "@mui/material/Accordion";
import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
2021-09-14 02:37:35 +02:00
2021-10-01 02:06:40 +02:00
import Typography from "@mui/material/Typography";
2021-09-17 01:23:03 +02:00
import Button from "@mui/material/Button";
2021-09-14 02:37:35 +02:00
import { PlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
import { IPlayer } from "../../PersonObjects/IPlayer";
2021-09-17 01:23:03 +02:00
import ButtonGroup from "@mui/material/ButtonGroup";
2021-09-14 02:37:35 +02:00
// Update as additional BitNodes get implemented
const validSFN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
interface IProps {
player: IPlayer;
}
export function SourceFiles(props: IProps): React.ReactElement {
function setSF(sfN: number, sfLvl: number) {
return function () {
if (sfLvl === 0) {
props.player.sourceFiles = props.player.sourceFiles.filter((sf) => sf.n !== sfN);
return;
}
if (!props.player.sourceFiles.some((sf) => sf.n === sfN)) {
props.player.sourceFiles.push(new PlayerOwnedSourceFile(sfN, sfLvl));
return;
}
for (let i = 0; i < props.player.sourceFiles.length; i++) {
if (props.player.sourceFiles[i].n === sfN) {
props.player.sourceFiles[i].lvl = sfLvl;
}
}
};
}
function setAllSF(sfLvl: number) {
return () => {
for (let i = 0; i < validSFN.length; i++) {
setSF(validSFN[i], sfLvl)();
}
};
}
function clearExploits(): void {
props.player.exploits = [];
}
return (
2021-09-18 03:30:02 +02:00
<Accordion TransitionProps={{ unmountOnExit: true }}>
2021-09-14 02:37:35 +02:00
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<h2>Source-Files</h2>
</AccordionSummary>
<AccordionDetails>
<table>
<tbody>
<tr>
<td>
2021-10-01 02:06:40 +02:00
<Typography>Exploits:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<Button onClick={clearExploits}>Clear</Button>
</td>
</tr>
<tr key={"sf-all"}>
<td>
2021-10-01 02:06:40 +02:00
<Typography>All:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<ButtonGroup>
2021-09-20 23:10:44 +02:00
<Button aria-label="all-sf-0" onClick={setAllSF(0)}>
0
</Button>
<Button aria-label="all-sf-1" onClick={setAllSF(1)}>
1
</Button>
<Button aria-label="all-sf-2" onClick={setAllSF(2)}>
2
</Button>
<Button aria-label="all-sf-3" onClick={setAllSF(3)}>
3
</Button>
2021-09-14 02:37:35 +02:00
</ButtonGroup>
</td>
</tr>
{validSFN.map((i) => (
<tr key={"sf-" + i}>
<td>
2021-10-01 02:06:40 +02:00
<Typography>SF-{i}:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<ButtonGroup>
<Button onClick={setSF(i, 0)}>0</Button>
<Button onClick={setSF(i, 1)}>1</Button>
<Button onClick={setSF(i, 2)}>2</Button>
<Button onClick={setSF(i, 3)}>3</Button>
</ButtonGroup>
</td>
</tr>
))}
</tbody>
</table>
</AccordionDetails>
</Accordion>
);
}