mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +01:00
INFILTRATION: Fix a crash when rendering InfiltrationRoot with an invalid location (#1266)
This commit is contained in:
parent
519b4fef44
commit
7ee7a79763
@ -5,6 +5,8 @@ import { Page } from "../../ui/Router";
|
||||
import { calculateDifficulty, calculateReward } from "../formulas/game";
|
||||
import { Game } from "./Game";
|
||||
import { Intro } from "./Intro";
|
||||
import { dialogBoxCreate } from "../../ui/React/DialogBox";
|
||||
|
||||
interface IProps {
|
||||
location: Location;
|
||||
}
|
||||
@ -12,7 +14,20 @@ interface IProps {
|
||||
export function InfiltrationRoot(props: IProps): React.ReactElement {
|
||||
const [start, setStart] = useState(false);
|
||||
|
||||
if (props.location.infiltrationData === undefined) throw new Error("Trying to do infiltration on invalid location.");
|
||||
if (!props.location.infiltrationData) {
|
||||
/**
|
||||
* Using setTimeout is unnecessary, because we can just call cancel() and dialogBoxCreate(). However, without
|
||||
* setTimeout, we will go to City page (in "cancel" function) and update GameRoot while still rendering
|
||||
* InfiltrationRoot. React will complain: "Warning: Cannot update a component (`GameRoot`) while rendering a
|
||||
* different component (`InfiltrationRoot`)".
|
||||
*/
|
||||
setTimeout(() => {
|
||||
cancel();
|
||||
dialogBoxCreate(`You tried to infiltrate an invalid location: ${props.location.name}`);
|
||||
}, 100);
|
||||
return <></>;
|
||||
}
|
||||
|
||||
const startingSecurityLevel = props.location.infiltrationData.startingSecurityLevel;
|
||||
const difficulty = calculateDifficulty(startingSecurityLevel);
|
||||
const reward = calculateReward(startingSecurityLevel);
|
||||
|
Loading…
Reference in New Issue
Block a user