Fix grafting crash when all Augs owned

This commit is contained in:
nickofolas 2022-03-30 14:29:59 -04:00
parent 8200b62384
commit a384b8af52

@ -64,74 +64,78 @@ export const GraftingRoot = (): React.ReactElement => {
<Box sx={{ my: 3 }}> <Box sx={{ my: 3 }}>
<Typography variant="h5">Graft Augmentations</Typography> <Typography variant="h5">Graft Augmentations</Typography>
<Paper sx={{ my: 1, width: "fit-content", display: "grid", gridTemplateColumns: "1fr 3fr" }}> {getAvailableAugs(player).length > 0 ? (
<List sx={{ maxHeight: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }}> <Paper sx={{ my: 1, width: "fit-content", display: "grid", gridTemplateColumns: "1fr 3fr" }}>
{getAvailableAugs(player).map((k, i) => ( <List sx={{ maxHeight: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }}>
<ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}> {getAvailableAugs(player).map((k, i) => (
<Typography>{k}</Typography> <ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}>
</ListItemButton> <Typography>{k}</Typography>
))} </ListItemButton>
</List> ))}
<Box sx={{ m: 1 }}> </List>
<Typography variant="h6" sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}> <Box sx={{ m: 1 }}>
<Construction sx={{ mr: 1 }} /> {selectedAug} <Typography variant="h6" sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}>
</Typography> <Construction sx={{ mr: 1 }} /> {selectedAug}
<Button
onClick={() => setGraftOpen(true)}
sx={{ width: "100%" }}
disabled={player.money < GraftableAugmentations[selectedAug].cost}
>
Graft Augmentation (
<Typography>
<Money money={GraftableAugmentations[selectedAug].cost} player={player} />
</Typography> </Typography>
) <Button
</Button> onClick={() => setGraftOpen(true)}
<ConfirmationModal sx={{ width: "100%" }}
open={graftOpen} disabled={player.money < GraftableAugmentations[selectedAug].cost}
onClose={() => setGraftOpen(false)} >
onConfirm={() => { Graft Augmentation (
const graftableAug = GraftableAugmentations[selectedAug]; <Typography>
player.loseMoney(graftableAug.cost, "augmentations"); <Money money={GraftableAugmentations[selectedAug].cost} player={player} />
player.startGraftAugmentationWork(selectedAug, graftableAug.time); </Typography>
player.startFocusing(); )
router.toWork(); </Button>
}} <ConfirmationModal
confirmationText={ open={graftOpen}
<> onClose={() => setGraftOpen(false)}
Cancelling grafting will <b>not</b> save grafting progress, and the money you spend will <b>not</b> be onConfirm={() => {
returned. const graftableAug = GraftableAugmentations[selectedAug];
<br /> player.loseMoney(graftableAug.cost, "augmentations");
<br /> player.startGraftAugmentationWork(selectedAug, graftableAug.time);
Additionally, grafting an Augmentation will increase the potency of the Entropy virus. player.startFocusing();
</> router.toWork();
} }}
/> confirmationText={
<Typography color={Settings.theme.info}>
<b>Time to Graft:</b>{" "}
{convertTimeMsToTimeElapsedString(
GraftableAugmentations[selectedAug].time / (1 + (player.getIntelligenceBonus(3) - 1) / 3),
)}
{/* Use formula so the displayed creation time is accurate to player bonus */}
</Typography>
<Typography sx={{ maxHeight: 305, overflowY: "scroll" }}>
{(() => {
const aug = Augmentations[selectedAug];
const info = typeof aug.info === "string" ? <span>{aug.info}</span> : aug.info;
const tooltip = (
<> <>
{info} Cancelling grafting will <b>not</b> save grafting progress, and the money you spend will <b>not</b>{" "}
be returned.
<br /> <br />
<br /> <br />
{aug.stats} Additionally, grafting an Augmentation will increase the potency of the Entropy virus.
</> </>
); }
return tooltip; />
})()} <Typography color={Settings.theme.info}>
</Typography> <b>Time to Graft:</b>{" "}
</Box> {convertTimeMsToTimeElapsedString(
</Paper> GraftableAugmentations[selectedAug].time / (1 + (player.getIntelligenceBonus(3) - 1) / 3),
)}
{/* Use formula so the displayed creation time is accurate to player bonus */}
</Typography>
<Typography sx={{ maxHeight: 305, overflowY: "scroll" }}>
{(() => {
const aug = Augmentations[selectedAug];
const info = typeof aug.info === "string" ? <span>{aug.info}</span> : aug.info;
const tooltip = (
<>
{info}
<br />
<br />
{aug.stats}
</>
);
return tooltip;
})()}
</Typography>
</Box>
</Paper>
) : (
<Typography>All Augmentations owned</Typography>
)}
</Box> </Box>
<Box sx={{ my: 3 }}> <Box sx={{ my: 3 }}>