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

149 lines
4.5 KiB
TypeScript
Raw Normal View History

2021-09-14 02:37:35 +02:00
import React, { useState } 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";
import Select, { SelectChangeEvent } from "@mui/material/Select";
2021-09-14 02:37:35 +02:00
import { Companies as AllCompanies } from "../../Company/Companies";
2021-09-17 01:23:03 +02:00
import MenuItem from "@mui/material/MenuItem";
2021-09-14 02:37:35 +02:00
import { Adjuster } from "./Adjuster";
import { FactionNames } from "../../Faction/data/FactionNames";
2021-09-14 02:37:35 +02:00
const bigNumber = 1e12;
2021-09-14 04:27:43 +02:00
export function Companies(): React.ReactElement {
const [company, setCompany] = useState(FactionNames.ECorp as string);
function setCompanyDropdown(event: SelectChangeEvent): void {
setCompany(event.target.value);
2021-09-14 02:37:35 +02:00
}
function resetCompanyRep(): void {
AllCompanies[company].playerReputation = 0;
}
function modifyCompanyRep(modifier: number): (x: number) => void {
return function (reputation: number): void {
const c = AllCompanies[company];
if (c != null && !isNaN(reputation)) {
c.playerReputation += reputation * modifier;
}
};
}
function modifyCompanyFavor(modifier: number): (x: number) => void {
return function (favor: number): void {
const c = AllCompanies[company];
if (c != null && !isNaN(favor)) {
c.favor += favor * modifier;
}
};
}
function resetCompanyFavor(): void {
AllCompanies[company].favor = 0;
}
function tonsOfRepCompanies(): void {
2022-01-16 01:45:03 +01:00
for (const c of Object.keys(AllCompanies)) {
2021-09-14 02:37:35 +02:00
AllCompanies[c].playerReputation = bigNumber;
}
}
function resetAllRepCompanies(): void {
2022-01-16 01:45:03 +01:00
for (const c of Object.keys(AllCompanies)) {
2021-09-14 02:37:35 +02:00
AllCompanies[c].playerReputation = 0;
}
}
function tonsOfFavorCompanies(): void {
2022-01-16 01:45:03 +01:00
for (const c of Object.keys(AllCompanies)) {
2021-09-14 02:37:35 +02:00
AllCompanies[c].favor = bigNumber;
}
}
function resetAllFavorCompanies(): void {
2022-01-16 01:45:03 +01:00
for (const c of Object.keys(AllCompanies)) {
2021-09-14 02:37:35 +02:00
AllCompanies[c].favor = 0;
}
}
return (
2021-09-18 03:30:02 +02:00
<Accordion TransitionProps={{ unmountOnExit: true }}>
2021-09-14 02:37:35 +02:00
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
2021-10-01 22:22:33 +02:00
<Typography>Companies</Typography>
2021-09-14 02:37:35 +02:00
</AccordionSummary>
<AccordionDetails>
<table>
<tbody>
<tr>
<td>
2021-10-01 02:06:40 +02:00
<Typography>Company:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td colSpan={3}>
2021-09-29 07:49:22 +02:00
<Select id="dev-companies-dropdown" onChange={setCompanyDropdown} value={company}>
2021-09-14 02:37:35 +02:00
{Object.values(AllCompanies).map((company) => (
<MenuItem key={company.name} value={company.name}>
{company.name}
</MenuItem>
))}
</Select>
</td>
</tr>
<tr>
<td>
2021-10-01 02:06:40 +02:00
<Typography>Reputation:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<Adjuster
label="reputation"
placeholder="amt"
tons={() => modifyCompanyRep(1)(bigNumber)}
add={modifyCompanyRep(1)}
subtract={modifyCompanyRep(-1)}
reset={resetCompanyRep}
/>
</td>
</tr>
<tr>
<td>
2021-10-01 02:06:40 +02:00
<Typography>Favor:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<Adjuster
label="favor"
placeholder="amt"
tons={() => modifyCompanyFavor(1)(2000)}
add={modifyCompanyFavor(1)}
subtract={modifyCompanyFavor(-1)}
reset={resetCompanyFavor}
/>
</td>
</tr>
<tr>
<td>
2021-10-01 02:06:40 +02:00
<Typography>All Reputation:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<Button onClick={tonsOfRepCompanies}>Tons</Button>
<Button onClick={resetAllRepCompanies}>Reset</Button>
</td>
</tr>
<tr>
<td>
2021-10-01 02:06:40 +02:00
<Typography>All Favor:</Typography>
2021-09-14 02:37:35 +02:00
</td>
<td>
<Button onClick={tonsOfFavorCompanies}>Tons</Button>
<Button onClick={resetAllFavorCompanies}>Reset</Button>
</td>
</tr>
</tbody>
</table>
</AccordionDetails>
</Accordion>
);
}