bitburner-src/src/Locations/ui/RamButton.tsx

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-09-09 09:17:01 +02:00
import React from "react";
2021-09-25 21:34:12 +02:00
import Button from "@mui/material/Button";
import Tooltip from "@mui/material/Tooltip";
2021-09-05 01:09:30 +02:00
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { purchaseRamForHomeComputer } from "../../Server/ServerPurchases";
import { Money } from "../../ui/React/Money";
import { MathComponent } from "mathjax-react";
type IProps = {
2021-09-05 01:09:30 +02:00
p: IPlayer;
2021-09-07 23:26:49 +02:00
rerender: () => void;
2021-09-05 01:09:30 +02:00
};
export function RamButton(props: IProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const homeComputer = props.p.getHomeComputer();
if (homeComputer.maxRam >= CONSTANTS.HomeComputerMaxRam) {
2021-09-25 21:34:12 +02:00
return <Button>Upgrade 'home' RAM - MAX</Button>;
2021-09-05 01:09:30 +02:00
}
const cost = props.p.getUpgradeHomeRamCost();
function buy(): void {
purchaseRamForHomeComputer(props.p);
2021-09-07 23:26:49 +02:00
props.rerender();
2021-09-05 01:09:30 +02:00
}
return (
2021-09-25 21:34:12 +02:00
<Tooltip title={<MathComponent tex={String.raw`\large{cost = 3.2 \times 10^3 \times 1.58^{log_2{(ram)}}}`} />}>
<Button disabled={!props.p.canAfford(cost)} onClick={buy}>
Upgrade 'home' RAM ({homeComputer.maxRam}GB -&gt;&nbsp;{homeComputer.maxRam * 2}GB) -&nbsp;
<Money money={cost} player={props.p} />
</Button>
</Tooltip>
2021-09-05 01:09:30 +02:00
);
}