Hide irrelevant divisions in Export modal

This commit is contained in:
SagePtr 2022-01-29 20:02:07 +02:00
parent a5f82e96ed
commit f22f0ed50a
2 changed files with 14 additions and 9 deletions

@ -6,6 +6,7 @@ import { IIndustry } from "../IIndustry";
import { ExportMaterial } from "../Actions"; import { ExportMaterial } from "../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../ui/React/Modal";
import { useCorporation } from "./Context"; import { useCorporation } from "./Context";
import { isRelevantMaterial } from "./Helpers";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
@ -22,11 +23,13 @@ interface IProps {
// Create a popup that lets the player manage exports // Create a popup that lets the player manage exports
export function ExportModal(props: IProps): React.ReactElement { export function ExportModal(props: IProps): React.ReactElement {
const corp = useCorporation(); const corp = useCorporation();
if (corp.divisions.length === 0) throw new Error("Export popup created with no divisions."); const possibleDivisions = corp.divisions.filter((division: IIndustry) => isRelevantMaterial(props.mat.name, division));
if (Object.keys(corp.divisions[0].warehouses).length === 0) if (possibleDivisions.length === 0) throw new Error("Export popup created with no divisions.");
const defaultDivision = possibleDivisions[0];
if (Object.keys(defaultDivision.warehouses).length === 0)
throw new Error("Export popup created in a division with no warehouses."); throw new Error("Export popup created in a division with no warehouses.");
const [industry, setIndustry] = useState<string>(corp.divisions[0].name); const [industry, setIndustry] = useState<string>(defaultDivision.name);
const [city, setCity] = useState<string>(Object.keys(corp.divisions[0].warehouses)[0]); const [city, setCity] = useState<string>(Object.keys(defaultDivision.warehouses)[0]);
const [amt, setAmt] = useState(""); const [amt, setAmt] = useState("");
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
@ -84,7 +87,9 @@ export function ExportModal(props: IProps): React.ReactElement {
second. You can set the export amount to 'MAX' to export all of the materials in this warehouse. second. You can set the export amount to 'MAX' to export all of the materials in this warehouse.
</Typography> </Typography>
<Select onChange={onIndustryChange} value={industry}> <Select onChange={onIndustryChange} value={industry}>
{corp.divisions.map((division: IIndustry) => ( {corp.divisions
.filter((division: IIndustry) => isRelevantMaterial(props.mat.name, division))
.map((division: IIndustry) => (
<MenuItem key={division.name} value={division.name}> <MenuItem key={division.name} value={division.name}>
{division.name} {division.name}
</MenuItem> </MenuItem>

@ -4,7 +4,7 @@ import { IIndustry } from "../IIndustry";
// current industry. // current industry.
export function isRelevantMaterial(matName: string, division: IIndustry): boolean { export function isRelevantMaterial(matName: string, division: IIndustry): boolean {
// Materials that affect Production multiplier // Materials that affect Production multiplier
const prodMultiplierMats = ["Hardware", "Robots", "AICores", "RealEstate"]; const prodMultiplierMats = ["Hardware", "Robots", "AICores", "RealEstate", "AI Cores", "Real Estate"];
if (Object.keys(division.reqMats).includes(matName)) { if (Object.keys(division.reqMats).includes(matName)) {
return true; return true;