This commit is contained in:
Olivier Gagnon
2021-09-17 02:04:44 -04:00
parent ff726afcd6
commit acd51e8328
22 changed files with 724 additions and 450 deletions
+4 -2
View File
@@ -12,7 +12,7 @@ import { HospitalLocation } from "./HospitalLocation";
import { SlumsLocation } from "./SlumsLocation";
import { SpecialLocation } from "./SpecialLocation";
import { TechVendorLocation } from "./TechVendorLocation";
import { TravelAgencyLocation } from "./TravelAgencyLocation";
import { TravelAgencyRoot } from "./TravelAgencyRoot";
import { UniversityLocation } from "./UniversityLocation";
import { CasinoLocation } from "./CasinoLocation";
@@ -21,6 +21,7 @@ import { LocationType } from "../LocationTypeEnum";
import { CityName } from "../data/CityNames";
import { IEngine } from "../../IEngine";
import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { Settings } from "../../Settings/Settings";
@@ -32,6 +33,7 @@ import { CorruptableText } from "../../ui/React/CorruptableText";
type IProps = {
engine: IEngine;
router: IRouter;
loc: Location;
p: IPlayer;
returnToCity: () => void;
@@ -91,7 +93,7 @@ export class GenericLocation extends React.Component<IProps, any> {
}
if (this.props.loc.types.includes(LocationType.TravelAgency)) {
content.push(<TravelAgencyLocation key={"travelagencylocation"} p={this.props.p} travel={this.props.travel} />);
content.push(<TravelAgencyRoot key={"travelagencylocation"} p={this.props.p} router={this.props.router} />);
}
if (this.props.loc.types.includes(LocationType.University)) {
+7
View File
@@ -15,6 +15,7 @@ import { LocationName } from "../data/LocationNames";
import { CONSTANTS } from "../../Constants";
import { IEngine } from "../../IEngine";
import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { dialogBoxCreate } from "../../../utils/DialogBox";
@@ -22,6 +23,7 @@ import { dialogBoxCreate } from "../../../utils/DialogBox";
type IProps = {
initiallyInCity?: boolean;
engine: IEngine;
router: IRouter;
p: IPlayer;
};
@@ -47,6 +49,10 @@ export class LocationRoot extends React.Component<IProps, IState> {
}
enterLocation(to: LocationName): void {
if (to == LocationName.TravelAgency) {
this.props.router.toTravel();
return;
}
this.props.p.gotoLocation(to);
this.setState({
inCity: false,
@@ -98,6 +104,7 @@ export class LocationRoot extends React.Component<IProps, IState> {
return (
<GenericLocation
engine={this.props.engine}
router={this.props.router}
loc={loc}
p={this.props.p}
returnToCity={this.returnToCity}
@@ -10,28 +10,43 @@ import { TravelConfirmationPopup } from "./TravelConfirmationPopup";
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { IRouter } from "../../ui/Router";
import { Settings } from "../../Settings/Settings";
import { StdButton } from "../../ui/React/StdButton";
import { createPopup } from "../../ui/React/createPopup";
import { Money } from "../../ui/React/Money";
import { WorldMap } from "../../ui/React/WorldMap";
import { dialogBoxCreate } from "../../../utils/DialogBox";
type IProps = {
p: IPlayer;
travel: (to: CityName) => void;
router: IRouter;
};
function createTravelPopup(p: IPlayer, city: string, travel: () => void): void {
function travel(p: IPlayer, router: IRouter, to: CityName): void {
const cost = CONSTANTS.TravelCost;
if (!p.canAfford(cost)) {
dialogBoxCreate(`You cannot afford to travel to ${to}`);
return;
}
p.loseMoney(cost);
p.travel(to);
dialogBoxCreate(<span className="noselect">You are now in {to}!</span>);
router.toCity();
}
function createTravelPopup(p: IPlayer, router: IRouter, city: CityName): void {
if (Settings.SuppressTravelConfirmation) {
travel();
travel(p, router, city);
return;
}
const popupId = `travel-confirmation`;
createPopup(popupId, TravelConfirmationPopup, {
player: p,
city: city,
travel: travel,
travel: () => travel(p, router, city),
popupId: popupId,
});
}
@@ -45,7 +60,7 @@ function ASCIIWorldMap(props: IProps): React.ReactElement {
</p>
<WorldMap
currentCity={props.p.city}
onTravel={(city: CityName) => createTravelPopup(props.p, city, () => props.travel(city))}
onTravel={(city: CityName) => createTravelPopup(props.p, props.router, city)}
/>
</div>
);
@@ -66,7 +81,7 @@ function ListWorldMap(props: IProps): React.ReactElement {
return (
<StdButton
key={city}
onClick={() => createTravelPopup(props.p, city, () => props.travel(match[1]))}
onClick={() => createTravelPopup(props.p, props.router, city as CityName)}
style={{ display: "block" }}
text={`Travel to ${city}`}
/>
@@ -76,10 +91,15 @@ function ListWorldMap(props: IProps): React.ReactElement {
);
}
export function TravelAgencyLocation(props: IProps): React.ReactElement {
if (Settings.DisableASCIIArt) {
return <ListWorldMap p={props.p} travel={props.travel} />;
} else {
return <ASCIIWorldMap p={props.p} travel={props.travel} />;
}
export function TravelAgencyRoot(props: IProps): React.ReactElement {
return (
<>
<h1>Travel Agency</h1>
{Settings.DisableASCIIArt ? (
<ListWorldMap p={props.p} router={props.router} />
) : (
<ASCIIWorldMap p={props.p} router={props.router} />
)}
</>
);
}