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

124 lines
4.1 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-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 { CityName } from "../data/CityNames";
import { IEngine } from "../../IEngine";
2021-09-17 08:04:44 +02:00
import { IRouter } from "../../ui/Router";
2021-09-05 01:09:30 +02:00
import { IPlayer } from "../../PersonObjects/IPlayer";
import { Settings } from "../../Settings/Settings";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
import { getServer, isBackdoorInstalled } from "../../Server/ServerHelpers";
import { StdButton } from "../../ui/React/StdButton";
import { CorruptableText } from "../../ui/React/CorruptableText";
type IProps = {
2021-09-05 01:09:30 +02:00
engine: IEngine;
2021-09-17 08:04:44 +02:00
router: IRouter;
2021-09-05 01:09:30 +02:00
loc: Location;
p: IPlayer;
returnToCity: () => void;
travel: (to: CityName) => void;
};
export class GenericLocation extends React.Component<IProps, any> {
2021-09-05 01:09:30 +02:00
/**
* Stores button styling that sets them all to block display
*/
btnStyle: any;
constructor(props: IProps) {
super(props);
this.btnStyle = { display: "block" };
}
/**
* Determine what needs to be rendered for this location based on the locations
* type. Returns an array of React components that should be rendered
*/
getLocationSpecificContent(): React.ReactNode[] {
const content: React.ReactNode[] = [];
if (this.props.loc.types.includes(LocationType.Company)) {
2021-09-18 01:43:08 +02:00
content.push(<CompanyLocation key={"companylocation"} locName={this.props.loc.name} />);
2021-09-05 01:09:30 +02:00
}
if (this.props.loc.types.includes(LocationType.Gym)) {
2021-09-09 05:47:34 +02:00
content.push(<GymLocation key={"gymlocation"} loc={this.props.loc} p={this.props.p} />);
2021-09-05 01:09:30 +02:00
}
if (this.props.loc.types.includes(LocationType.Hospital)) {
2021-09-09 05:47:34 +02:00
content.push(<HospitalLocation key={"hospitallocation"} p={this.props.p} />);
2021-09-05 01:09:30 +02:00
}
2019-04-04 02:08:11 +02:00
2021-09-05 01:09:30 +02:00
if (this.props.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
}
if (this.props.loc.types.includes(LocationType.Special)) {
content.push(
2021-09-09 05:47:34 +02:00
<SpecialLocation engine={this.props.engine} key={"speciallocation"} loc={this.props.loc} p={this.props.p} />,
2021-09-05 01:09:30 +02:00
);
}
2019-04-04 02:08:11 +02:00
2021-09-05 01:09:30 +02:00
if (this.props.loc.types.includes(LocationType.TechVendor)) {
2021-09-09 05:47:34 +02:00
content.push(<TechVendorLocation key={"techvendorlocation"} loc={this.props.loc} p={this.props.p} />);
2019-04-04 02:08:11 +02:00
}
2021-09-05 01:09:30 +02:00
if (this.props.loc.types.includes(LocationType.TravelAgency)) {
2021-09-17 08:04:44 +02:00
content.push(<TravelAgencyRoot key={"travelagencylocation"} p={this.props.p} router={this.props.router} />);
}
2021-09-05 01:09:30 +02:00
if (this.props.loc.types.includes(LocationType.University)) {
2021-09-18 01:43:08 +02:00
content.push(<UniversityLocation key={"universitylocation"} loc={this.props.loc} />);
}
2021-09-05 01:09:30 +02:00
if (this.props.loc.types.includes(LocationType.Casino)) {
content.push(<CasinoLocation key={"casinoLocation"} p={this.props.p} />);
}
return content;
}
render(): React.ReactNode {
const locContent: React.ReactNode[] = this.getLocationSpecificContent();
const ip = SpecialServerIps.getIp(this.props.loc.name);
const server = getServer(ip);
const backdoorInstalled = server !== null && isBackdoorInstalled(server);
return (
<div>
2021-09-09 05:47:34 +02:00
<StdButton onClick={this.props.returnToCity} style={this.btnStyle} text={"Return to World"} />
2021-09-05 01:09:30 +02:00
<h1 className="noselect">
{backdoorInstalled && !Settings.DisableTextEffects ? (
<CorruptableText content={this.props.loc.name} />
) : (
this.props.loc.name
)}
</h1>
{locContent}
</div>
);
}
}