bitburner-src/src/Locations/ui/GenericLocation.tsx

100 lines
3.4 KiB
TypeScript
Raw Normal View History

/**
* React Component for displaying a location's UI
*
* This is a "router" component of sorts, meaning it deduces the type of
* location that is being rendered and then creates the proper component(s) for that.
*/
import * as React from "react";
2021-09-25 21:34:12 +02:00
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
2021-09-05 01:09:30 +02:00
import { CompanyLocation } from "./CompanyLocation";
import { GymLocation } from "./GymLocation";
import { HospitalLocation } from "./HospitalLocation";
import { SlumsLocation } from "./SlumsLocation";
import { SpecialLocation } from "./SpecialLocation";
import { TechVendorLocation } from "./TechVendorLocation";
2021-09-17 08:04:44 +02:00
import { TravelAgencyRoot } from "./TravelAgencyRoot";
2021-09-05 01:09:30 +02:00
import { UniversityLocation } from "./UniversityLocation";
import { CasinoLocation } from "./CasinoLocation";
import { Location } from "../Location";
import { LocationType } from "../LocationTypeEnum";
import { Settings } from "../../Settings/Settings";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
import { getServer, isBackdoorInstalled } from "../../Server/ServerHelpers";
import { CorruptableText } from "../../ui/React/CorruptableText";
2021-09-18 10:01:07 +02:00
import { use } from "../../ui/Context";
type IProps = {
2021-09-05 01:09:30 +02:00
loc: Location;
};
2021-09-18 10:01:07 +02:00
export function GenericLocation({ loc }: IProps): React.ReactElement {
const router = use.Router();
const player = use.Player();
2021-09-05 01:09:30 +02:00
/**
* Determine what needs to be rendered for this location based on the locations
* type. Returns an array of React components that should be rendered
*/
2021-09-18 10:01:07 +02:00
function getLocationSpecificContent(): React.ReactNode[] {
2021-09-05 01:09:30 +02:00
const content: React.ReactNode[] = [];
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.Company)) {
content.push(<CompanyLocation key={"companylocation"} locName={loc.name} />);
2021-09-05 01:09:30 +02:00
}
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.Gym)) {
2021-09-20 07:45:32 +02:00
content.push(<GymLocation key={"gymlocation"} router={router} loc={loc} p={player} />);
2021-09-05 01:09:30 +02:00
}
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.Hospital)) {
content.push(<HospitalLocation key={"hospitallocation"} p={player} />);
2021-09-05 01:09:30 +02:00
}
2019-04-04 02:08:11 +02:00
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.Slums)) {
2021-09-18 01:43:08 +02:00
content.push(<SlumsLocation key={"slumslocation"} />);
2021-09-05 01:09:30 +02:00
}
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.Special)) {
content.push(<SpecialLocation key={"speciallocation"} loc={loc} />);
2021-09-05 01:09:30 +02:00
}
2019-04-04 02:08:11 +02:00
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.TechVendor)) {
2021-10-01 02:06:40 +02:00
content.push(<TechVendorLocation key={"techvendorlocation"} loc={loc} />);
2019-04-04 02:08:11 +02:00
}
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.TravelAgency)) {
content.push(<TravelAgencyRoot key={"travelagencylocation"} p={player} router={router} />);
}
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.University)) {
content.push(<UniversityLocation key={"universitylocation"} loc={loc} />);
}
2021-09-05 01:09:30 +02:00
2021-09-18 10:01:07 +02:00
if (loc.types.includes(LocationType.Casino)) {
content.push(<CasinoLocation key={"casinoLocation"} p={player} />);
2021-09-05 01:09:30 +02:00
}
return content;
}
2021-09-18 10:01:07 +02:00
const locContent: React.ReactNode[] = getLocationSpecificContent();
const ip = SpecialServerIps.getIp(loc.name);
const server = getServer(ip);
const backdoorInstalled = server !== null && isBackdoorInstalled(server);
return (
2021-09-25 21:34:12 +02:00
<>
<Button onClick={() => router.toCity()}>Return to World</Button>
<Typography variant="h4" className="noselect">
2021-09-18 10:01:07 +02:00
{backdoorInstalled && !Settings.DisableTextEffects ? <CorruptableText content={loc.name} /> : loc.name}
2021-09-25 21:34:12 +02:00
</Typography>
2021-09-18 10:01:07 +02:00
{locContent}
2021-09-25 21:34:12 +02:00
</>
2021-09-18 10:01:07 +02:00
);
}