Merge pull request #2864 from SagePtr/corp-material-fix

Don't hide irrelevant materials if their stock is not empty and hide irrelevant divisions from Export
This commit is contained in:
hydroflame 2022-03-10 21:46:13 -05:00 committed by GitHub
commit f5ca700476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 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;

@ -95,8 +95,10 @@ function WarehouseRoot(props: IProps): React.ReactElement {
const mats = []; const mats = [];
for (const matName of Object.keys(props.warehouse.materials)) { for (const matName of Object.keys(props.warehouse.materials)) {
if (!(props.warehouse.materials[matName] instanceof Material)) continue; if (!(props.warehouse.materials[matName] instanceof Material)) continue;
// Only create UI for materials that are relevant for the industry // Only create UI for materials that are relevant for the industry or in stock
if (!isRelevantMaterial(matName, division)) continue; const isInStock = props.warehouse.materials[matName].qty > 0;
const isRelevant = isRelevantMaterial(matName, division);
if (!isInStock && !isRelevant) continue;
mats.push( mats.push(
<MaterialElem <MaterialElem
rerender={props.rerender} rerender={props.rerender}