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 { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { Programs as AllPrograms } from "../../Programs/Programs";
|
2021-09-17 01:23:03 +02:00
|
|
|
import MenuItem from "@mui/material/MenuItem";
|
2021-09-14 02:37:35 +02:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
player: IPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Programs(props: IProps): React.ReactElement {
|
|
|
|
const [program, setProgram] = useState("NUKE.exe");
|
2021-09-17 01:23:03 +02:00
|
|
|
function setProgramDropdown(event: SelectChangeEvent<string>): void {
|
2021-09-14 02:37:35 +02:00
|
|
|
setProgram(event.target.value as string);
|
|
|
|
}
|
|
|
|
function addProgram(): void {
|
|
|
|
if (!props.player.hasProgram(program)) {
|
|
|
|
props.player.getHomeComputer().programs.push(program);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAllPrograms(): void {
|
|
|
|
for (const i in AllPrograms) {
|
|
|
|
if (!props.player.hasProgram(AllPrograms[i].name)) {
|
|
|
|
props.player.getHomeComputer().programs.push(AllPrograms[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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>Programs</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</AccordionSummary>
|
|
|
|
<AccordionDetails>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2021-10-01 02:06:40 +02:00
|
|
|
<Typography>Program:</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Select onChange={setProgramDropdown} value={program}>
|
|
|
|
{Object.values(AllPrograms).map((program) => (
|
|
|
|
<MenuItem key={program.name} value={program.name}>
|
|
|
|
{program.name}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2021-10-01 02:06:40 +02:00
|
|
|
<Typography>Add:</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={addProgram}>One</Button>
|
|
|
|
<Button onClick={addAllPrograms}>All</Button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</AccordionDetails>
|
|
|
|
</Accordion>
|
|
|
|
);
|
|
|
|
}
|