tech vendor buttons update better

This commit is contained in:
Olivier Gagnon 2021-09-07 17:26:49 -04:00
parent 0d5a302580
commit 1c9542d102
4 changed files with 14 additions and 22 deletions

@ -9,14 +9,10 @@ import { MathComponent } from "mathjax-react";
type IProps = { type IProps = {
p: IPlayer; p: IPlayer;
rerender: () => void;
}; };
export function CoresButton(props: IProps): React.ReactElement { export function CoresButton(props: IProps): React.ReactElement {
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
}
const btnStyle = { display: "block" }; const btnStyle = { display: "block" };
const homeComputer = props.p.getHomeComputer(); const homeComputer = props.p.getHomeComputer();
@ -37,7 +33,7 @@ export function CoresButton(props: IProps): React.ReactElement {
if (!props.p.canAfford(cost)) return; if (!props.p.canAfford(cost)) return;
props.p.loseMoney(cost); props.p.loseMoney(cost);
homeComputer.cpuCores++; homeComputer.cpuCores++;
rerender(); props.rerender();
} }
return ( return (

@ -11,14 +11,10 @@ import { MathComponent } from "mathjax-react";
type IProps = { type IProps = {
p: IPlayer; p: IPlayer;
rerender: () => void;
}; };
export function RamButton(props: IProps): React.ReactElement { export function RamButton(props: IProps): React.ReactElement {
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
}
const btnStyle = { display: "block" }; const btnStyle = { display: "block" };
const homeComputer = props.p.getHomeComputer(); const homeComputer = props.p.getHomeComputer();
@ -32,7 +28,7 @@ export function RamButton(props: IProps): React.ReactElement {
function buy(): void { function buy(): void {
purchaseRamForHomeComputer(props.p); purchaseRamForHomeComputer(props.p);
rerender(); props.rerender();
} }
return ( return (

@ -3,7 +3,7 @@
* *
* This subcomponent renders all of the buttons for purchasing things from tech vendors * This subcomponent renders all of the buttons for purchasing things from tech vendors
*/ */
import * as React from "react"; import React, { useState } from "react";
import { Location } from "../Location"; import { Location } from "../Location";
import { createPurchaseServerPopup } from "../LocationsHelpers"; import { createPurchaseServerPopup } from "../LocationsHelpers";
@ -23,6 +23,10 @@ type IProps = {
}; };
export function TechVendorLocation(props: IProps): React.ReactElement { export function TechVendorLocation(props: IProps): React.ReactElement {
const setRerender = useState(false)[1];
function rerender() {
setRerender((old) => !old);
}
const btnStyle = { display: "block" }; const btnStyle = { display: "block" };
const purchaseServerButtons: React.ReactNode[] = []; const purchaseServerButtons: React.ReactNode[] = [];
@ -58,9 +62,9 @@ export function TechVendorLocation(props: IProps): React.ReactElement {
</i> </i>
</p> </p>
<br /> <br />
<TorButton p={props.p} /> <TorButton p={props.p} rerender={rerender} />
<RamButton p={props.p} /> <RamButton p={props.p} rerender={rerender} />
<CoresButton p={props.p} /> <CoresButton p={props.p} rerender={rerender} />
</div> </div>
); );
} }

@ -11,19 +11,15 @@ import { Money } from "../../ui/React/Money";
type IProps = { type IProps = {
p: IPlayer; p: IPlayer;
rerender: () => void;
}; };
export function TorButton(props: IProps): React.ReactElement { export function TorButton(props: IProps): React.ReactElement {
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
}
const btnStyle = { display: "block" }; const btnStyle = { display: "block" };
function buy(): void { function buy(): void {
purchaseTorRouter(props.p); purchaseTorRouter(props.p);
rerender(); props.rerender();
} }
if (props.p.hasTorRouter()) { if (props.p.hasTorRouter()) {