mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-02 13:57:05 +02:00
TYPESAFETY: CompanyName (#650)
This commit is contained in:
@@ -22,6 +22,7 @@ import { Player } from "@player";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
import { Server } from "../Server/Server";
|
||||
import { Companies } from "../Company/Companies";
|
||||
import { isMember } from "../utils/EnumHelper";
|
||||
|
||||
// Returns a boolean indicating whether the player has Hacknet Servers
|
||||
// (the upgraded form of Hacknet Nodes)
|
||||
@@ -564,7 +565,7 @@ export function purchaseHashUpgrade(upgName: string, upgTarget: string, count =
|
||||
break;
|
||||
}
|
||||
case "Company Favor": {
|
||||
if (!(upgTarget in Companies)) {
|
||||
if (!isMember("CompanyName", upgTarget)) {
|
||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||
throw new Error(`'${upgTarget}' is not a company.`);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ import Typography from "@mui/material/Typography";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Button from "@mui/material/Button";
|
||||
import { SelectChangeEvent } from "@mui/material/Select";
|
||||
import { FactionName } from "@enums";
|
||||
import { companiesMetadata } from "../../Company/data/CompaniesMetadata";
|
||||
import { CompanyName, FactionName } from "@enums";
|
||||
import { PartialRecord } from "../../Types/Record";
|
||||
import { isMember } from "../../utils/EnumHelper";
|
||||
|
||||
interface IProps {
|
||||
hashManager: HashManager;
|
||||
@@ -24,8 +25,9 @@ interface IProps {
|
||||
rerender: () => void;
|
||||
}
|
||||
|
||||
// Key is the hash upgrade name
|
||||
const serversMap: Record<string, string> = {};
|
||||
const companiesMap: Record<string, string> = {};
|
||||
const companiesMap: PartialRecord<string, CompanyName> = {};
|
||||
|
||||
export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
const [selectedServer, setSelectedServer] = useState(
|
||||
@@ -35,10 +37,9 @@ export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
setSelectedServer(event.target.value);
|
||||
serversMap[props.upg.name] = event.target.value;
|
||||
}
|
||||
const [selectedCompany, setSelectedCompany] = useState(
|
||||
companiesMap[props.upg.name] ? companiesMap[props.upg.name] : companiesMetadata[0].name,
|
||||
);
|
||||
function changeTargetCompany(event: SelectChangeEvent): void {
|
||||
const [selectedCompany, setSelectedCompany] = useState(companiesMap[props.upg.name] ?? CompanyName.NoodleBar);
|
||||
function changeTargetCompany(event: SelectChangeEvent<CompanyName>): void {
|
||||
if (!isMember("CompanyName", event.target.value)) return;
|
||||
setSelectedCompany(event.target.value);
|
||||
companiesMap[props.upg.name] = event.target.value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user