bitburner-src/src/Infiltration/ui/InfiltrationRoot.tsx

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-09-18 01:43:08 +02:00
import React, { useState } from "react";
2021-09-18 10:01:07 +02:00
import { Location } from "../../Locations/Location";
2021-09-18 01:43:08 +02:00
import { use } from "../../ui/Context";
import { calculateDifficulty, calculateReward } from "../formulas/game";
2022-04-25 01:51:30 +02:00
import { Game } from "./Game";
import { Intro } from "./Intro";
2021-09-18 01:43:08 +02:00
interface IProps {
2021-09-18 10:01:07 +02:00
location: Location;
2021-09-18 01:43:08 +02:00
}
2021-12-03 21:11:31 +01:00
2021-09-18 01:43:08 +02:00
export function InfiltrationRoot(props: IProps): React.ReactElement {
const player = use.Player();
const router = use.Router();
const [start, setStart] = useState(false);
2021-09-18 10:01:07 +02:00
if (props.location.infiltrationData === undefined) throw new Error("Trying to do infiltration on invalid location.");
const startingSecurityLevel = props.location.infiltrationData.startingSecurityLevel;
const difficulty = calculateDifficulty(player, startingSecurityLevel);
const reward = calculateReward(player, startingSecurityLevel);
2021-09-18 01:43:08 +02:00
function cancel(): void {
router.toCity();
}
return (
2022-04-29 22:56:34 +02:00
<div style={{ display: "flex", alignItems: "center", height: "100vh" }}>
2022-04-24 23:51:00 +02:00
{start ? (
<Game
StartingDifficulty={startingSecurityLevel}
Difficulty={difficulty}
Reward={reward}
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
/>
) : (
<Intro
Location={props.location}
Difficulty={difficulty}
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
start={() => setStart(true)}
cancel={cancel}
/>
)}
</div>
2021-09-18 01:43:08 +02:00
);
}