2021-09-04 08:21:31 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
import { CONSTANTS } from "../../Constants";
|
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { purchaseRamForHomeComputer } from "../../Server/ServerPurchases";
|
|
|
|
|
|
|
|
import { StdButtonPurchased } from "../../ui/React/StdButtonPurchased";
|
|
|
|
import { StdButton } from "../../ui/React/StdButton";
|
|
|
|
import { Money } from "../../ui/React/Money";
|
|
|
|
import { MathComponent } from "mathjax-react";
|
2021-09-04 08:21:31 +02:00
|
|
|
|
|
|
|
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
|
|
|
};
|
2021-09-04 08:21:31 +02:00
|
|
|
|
|
|
|
export function RamButton(props: IProps): React.ReactElement {
|
2021-09-05 01:09:30 +02:00
|
|
|
const btnStyle = { display: "block" };
|
|
|
|
|
|
|
|
const homeComputer = props.p.getHomeComputer();
|
|
|
|
if (homeComputer.maxRam >= CONSTANTS.HomeComputerMaxRam) {
|
|
|
|
return (
|
|
|
|
<StdButtonPurchased style={btnStyle} text={"Upgrade 'home' RAM - MAX"} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 (
|
|
|
|
<StdButton
|
|
|
|
disabled={!props.p.canAfford(cost)}
|
|
|
|
onClick={buy}
|
|
|
|
style={btnStyle}
|
|
|
|
text={
|
|
|
|
<>
|
|
|
|
Upgrade 'home' RAM ({homeComputer.maxRam}GB ->{" "}
|
|
|
|
{homeComputer.maxRam * 2}GB) - <Money money={cost} player={props.p} />
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
tooltip={
|
|
|
|
<MathComponent
|
2021-09-05 19:48:38 +02:00
|
|
|
tex={String.raw`\large{cost = 3.2 \times 10^3 \times 1.58^{log_2{(ram)}}}`}
|
2021-09-05 01:09:30 +02:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2021-09-04 08:21:31 +02:00
|
|
|
}
|