Fix conditional rendering of BN mults element

This commit is contained in:
nickofolas 2022-05-07 17:16:47 -05:00
parent 6d1a3bb47a
commit d1498598a9

@ -1,7 +1,7 @@
import { Paper, Table, TableBody, Box, IconButton, Typography, Container, Tooltip } from "@mui/material"; import { Paper, Table, TableBody, Box, IconButton, Typography, Container, Tooltip } from "@mui/material";
import { MoreHoriz, Info } from "@mui/icons-material"; import { MoreHoriz, Info } from "@mui/icons-material";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { BitNodes } from "../BitNode/BitNode"; import { BitNodes, defaultMultipliers, getBitNodeMultipliers } from "../BitNode/BitNode";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers"; import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { BitNodeMultipliersDisplay } from "../BitNode/ui/BitnodeMultipliersDescription"; import { BitNodeMultipliersDisplay } from "../BitNode/ui/BitnodeMultipliersDescription";
import { HacknetServerConstants } from "../Hacknet/data/Constants"; import { HacknetServerConstants } from "../Hacknet/data/Constants";
@ -15,6 +15,7 @@ import { Modal } from "./React/Modal";
import { Money } from "./React/Money"; import { Money } from "./React/Money";
import { StatsRow } from "./React/StatsRow"; import { StatsRow } from "./React/StatsRow";
import { StatsTable } from "./React/StatsTable"; import { StatsTable } from "./React/StatsTable";
import { isEqual } from "lodash";
interface EmployersModalProps { interface EmployersModalProps {
open: boolean; open: boolean;
@ -224,6 +225,14 @@ export function CharacterStats(): React.ReactElement {
} }
timeRows.push(["Total", convertTimeMsToTimeElapsedString(player.totalPlaytime)]); timeRows.push(["Total", convertTimeMsToTimeElapsedString(player.totalPlaytime)]);
let showBitNodeMults = false;
if (player.sourceFileLvl(5) > 0) {
const n = player.bitNodeN;
const maxSfLevel = n === 12 ? Infinity : 3;
const mults = getBitNodeMultipliers(n, Math.min(player.sourceFileLvl(n) + 1, maxSfLevel));
showBitNodeMults = !isEqual(mults, defaultMultipliers);
}
return ( return (
<Container maxWidth="lg" disableGutters sx={{ mx: 0 }}> <Container maxWidth="lg" disableGutters sx={{ mx: 0 }}>
<Typography variant="h4">Stats</Typography> <Typography variant="h4">Stats</Typography>
@ -534,7 +543,7 @@ export function CharacterStats(): React.ReactElement {
mult: "Crime Money", mult: "Crime Money",
value: player.crime_money_mult, value: player.crime_money_mult,
effValue: player.crime_money_mult * BitNodeMultipliers.CrimeMoney, effValue: player.crime_money_mult * BitNodeMultipliers.CrimeMoney,
color: Settings.theme.money color: Settings.theme.money,
}, },
]} ]}
color={Settings.theme.combat} color={Settings.theme.combat}
@ -580,7 +589,7 @@ export function CharacterStats(): React.ReactElement {
<CurrentBitNode /> <CurrentBitNode />
{player.bitNodeN !== 1 && player.sourceFileLvl(5) > 0 && ( {showBitNodeMults && (
<Paper sx={{ p: 1, mb: 1 }}> <Paper sx={{ p: 1, mb: 1 }}>
<Typography variant="h5">BitNode Multipliers</Typography> <Typography variant="h5">BitNode Multipliers</Typography>
<BitNodeMultipliersDisplay n={player.bitNodeN} /> <BitNodeMultipliersDisplay n={player.bitNodeN} />