Merge pull request #4248 from borisflagell/hospital

UI: #4242 Fix hospital ReactComponent
This commit is contained in:
hydroflame 2022-10-19 11:45:20 -04:00 committed by GitHub
commit 532b32c51a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,29 +12,22 @@ import { getHospitalizationCost } from "../../Hospital/Hospital";
import { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../ui/React/DialogBox";
import { useEffect, useState } from "react";
type IState = { export function HospitalLocation(): React.ReactElement {
currHp: number;
};
//Todo: Make this a functional component
export class HospitalLocation extends React.Component<Record<string, never>, IState> {
/** Stores button styling that sets them all to block display */ /** Stores button styling that sets them all to block display */
btnStyle = { display: "block" }; const btnStyle = { display: "block" };
const setRerender = useState(false)[1];
constructor() { function rerender(): void {
super({}); setRerender((old) => !old);
this.state = {
currHp: Player.hp.current,
};
} }
getCost(): number { useEffect(() => {
return getHospitalizationCost(); const id = setInterval(rerender, 200);
} return () => clearInterval(id);
}, []);
getHealed(e: React.MouseEvent<HTMLElement>): void { function getHealed(e: React.MouseEvent<HTMLElement>): void {
if (!e.isTrusted) { if (!e.isTrusted) {
return; return;
} }
@ -46,14 +39,12 @@ export class HospitalLocation extends React.Component<Record<string, never>, ISt
return; return;
} }
const cost = this.getCost(); const cost = getHospitalizationCost();
Player.loseMoney(cost, "hospitalization"); Player.loseMoney(cost, "hospitalization");
Player.hp.current = Player.hp.max; Player.hp.current = Player.hp.max;
// This just forces a re-render to update the cost // This just forces a re-render to update the cost
this.setState({ rerender();
currHp: Player.hp.current,
});
dialogBoxCreate( dialogBoxCreate(
<> <>
@ -62,13 +53,9 @@ export class HospitalLocation extends React.Component<Record<string, never>, ISt
); );
} }
render(): React.ReactNode {
const cost = this.getCost();
return ( return (
<Button onClick={this.getHealed} style={this.btnStyle}> <Button onClick={getHealed} style={btnStyle}>
Get treatment for wounds - <Money money={cost} forPurchase={true} /> Get treatment for wounds - <Money money={getHospitalizationCost()} forPurchase={true} />
</Button> </Button>
); );
}
} }