MISC: Refactor code of traveling and going to location (#1365)

This commit is contained in:
catloversg
2024-06-09 03:52:10 +07:00
committed by GitHub
parent b8f03cb50b
commit a354867fc4
8 changed files with 38 additions and 34 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ export function CompanyLocation(props: IProps): React.ReactElement {
*/
const currentPosition = jobTitle ? CompanyPositions[jobTitle] : null;
Player.location = companyNameAsLocationName(props.companyName);
Player.gotoLocation(companyNameAsLocationName(props.companyName));
function startInfiltration(e: React.MouseEvent<HTMLElement>): void {
if (!e.isTrusted) {
+5 -8
View File
@@ -24,14 +24,12 @@ import Button from "@mui/material/Button";
import { useRerender } from "../../ui/React/hooks";
function travel(to: CityName): void {
const cost = CONSTANTS.TravelCost;
if (!Player.canAfford(cost)) {
if (!Player.travel(to)) {
return;
}
Player.loseMoney(cost, "other");
Player.travel(to);
if (!Settings.SuppressTravelConfirmation) dialogBoxCreate(`You are now in ${to}!`);
if (!Settings.SuppressTravelConfirmation) {
dialogBoxCreate(`You are now in ${to}!`);
}
Router.toPage(Page.City);
}
@@ -41,8 +39,7 @@ export function TravelAgencyRoot(): React.ReactElement {
useRerender(1000);
function startTravel(city: CityName): void {
const cost = CONSTANTS.TravelCost;
if (!Player.canAfford(cost)) {
if (!Player.canAfford(CONSTANTS.TravelCost)) {
return;
}
if (Settings.SuppressTravelConfirmation) {
+2 -2
View File
@@ -14,7 +14,6 @@ interface IProps {
}
export function TravelConfirmationModal(props: IProps): React.ReactElement {
const cost = CONSTANTS.TravelCost;
function travel(): void {
props.travel();
}
@@ -22,7 +21,8 @@ export function TravelConfirmationModal(props: IProps): React.ReactElement {
return (
<Modal open={props.open} onClose={props.onClose}>
<Typography>
Would you like to travel to {props.city}? The trip will cost <Money money={cost} forPurchase={true} />.
Would you like to travel to {props.city}? The trip will cost{" "}
<Money money={CONSTANTS.TravelCost} forPurchase={true} />.
</Typography>
<br />
<br />