more conversion

This commit is contained in:
Olivier Gagnon 2021-08-28 02:57:57 -04:00
parent 4b53d6ecf7
commit 94ad7ccf4b
2 changed files with 45 additions and 41 deletions

@ -1,7 +1,6 @@
// React Component for displaying an Industry's overview information // React Component for displaying an Industry's overview information
// (top-left panel in the Industry UI) // (top-left panel in the Industry UI)
import React from "react"; import React from "react";
import { BaseReactComponent } from "./BaseReactComponent";
import { OfficeSpace } from "../OfficeSpace"; import { OfficeSpace } from "../OfficeSpace";
import { Industries } from "../IndustryData"; import { Industries } from "../IndustryData";
@ -10,11 +9,19 @@ import { numeralWrapper } from "../../ui/numeralFormat";
import { dialogBoxCreate } from "../../../utils/DialogBox"; import { dialogBoxCreate } from "../../../utils/DialogBox";
import { createProgressBarText } from "../../../utils/helpers/createProgressBarText"; import { createProgressBarText } from "../../../utils/helpers/createProgressBarText";
export class IndustryOverview extends BaseReactComponent { interface IProps {
renderMakeProductButton() { routing: any;
const division = this.routing().currentDivision; // Validated inside render() eventHandler: any;
corp: any;
currentCity: string;
}
var createProductButtonText, createProductPopupText; export function IndustryOverview(props: IProps): React.ReactElement {
function renderMakeProductButton() {
const division = props.routing.currentDivision; // Validated inside render()
let createProductButtonText = "";
let createProductPopupText = "";
switch(division.type) { switch(division.type) {
case Industries.Food: case Industries.Food:
createProductButtonText = "Build Restaurant"; createProductButtonText = "Build Restaurant";
@ -65,14 +72,13 @@ export class IndustryOverview extends BaseReactComponent {
const hasMaxProducts = division.hasMaximumNumberProducts(); const hasMaxProducts = division.hasMaximumNumberProducts();
const className = hasMaxProducts ? "a-link-button-inactive tooltip" : "std-button"; const className = hasMaxProducts ? "a-link-button-inactive tooltip" : "std-button";
const onClick = this.eventHandler().createMakeProductPopup.bind(this.eventHandler(), createProductPopupText, division);
const buttonStyle = { const buttonStyle = {
margin: "6px", margin: "6px",
display: "inline-block", display: "inline-block",
} }
return ( return (
<button className={className} onClick={onClick} style={buttonStyle}> <button className={className} onClick={() => props.eventHandler.createMakeProductPopup(createProductPopupText, division)} style={buttonStyle}>
{createProductButtonText} {createProductButtonText}
{ {
hasMaxProducts && hasMaxProducts &&
@ -84,9 +90,9 @@ export class IndustryOverview extends BaseReactComponent {
) )
} }
renderText() { function renderText() {
const corp = this.corp(); const corp = props.corp;
const division = this.routing().currentDivision; // Validated inside render() const division = props.routing.currentDivision; // Validated inside render()
const vechain = (corp.unlockUpgrades[4] === 1); const vechain = (corp.unlockUpgrades[4] === 1);
const profit = division.lastCycleRevenue.minus(division.lastCycleExpenses).toNumber(); const profit = division.lastCycleRevenue.minus(division.lastCycleExpenses).toNumber();
@ -111,7 +117,7 @@ export class IndustryOverview extends BaseReactComponent {
// Wrapper for createProgressBarText() // Wrapper for createProgressBarText()
// Converts the industry's "effectiveness factors" // Converts the industry's "effectiveness factors"
// into a graphic (string) depicting how high that effectiveness is // into a graphic (string) depicting how high that effectiveness is
function convertEffectFacToGraphic(fac) { function convertEffectFacToGraphic(fac: number) {
return createProgressBarText({ return createProgressBarText({
progress: fac, progress: fac,
totalTicks: 20, totalTicks: 20,
@ -185,12 +191,12 @@ export class IndustryOverview extends BaseReactComponent {
) )
} }
renderUpgrades() { function renderUpgrades() {
const corp = this.corp(); const corp = props.corp;
const division = this.routing().currentDivision; // Validated inside render() const division = props.routing.currentDivision; // Validated inside render()
const office = division.offices[this.props.currentCity]; const office = division.offices[props.currentCity];
if (!(office instanceof OfficeSpace)) { if (!(office instanceof OfficeSpace)) {
throw new Error(`Current City (${this.props.currentCity}) for UI does not have an OfficeSpace object`); throw new Error(`Current City (${props.currentCity}) for UI does not have an OfficeSpace object`);
} }
const upgrades = []; const upgrades = [];
@ -227,7 +233,7 @@ export class IndustryOverview extends BaseReactComponent {
} }
} }
upgrades.push(this.renderUpgrade({ upgrades.push(renderUpgrade({
onClick: onClick, onClick: onClick,
text: `${upgrade[4]} - ${numeralWrapper.formatMoney(cost)}`, text: `${upgrade[4]} - ${numeralWrapper.formatMoney(cost)}`,
tooltip: upgrade[5], tooltip: upgrade[5],
@ -237,7 +243,7 @@ export class IndustryOverview extends BaseReactComponent {
return upgrades; return upgrades;
} }
renderUpgrade(props) { function renderUpgrade(props: any) {
return ( return (
<div className={"cmpy-mgmt-upgrade-div tooltip"} onClick={props.onClick} key={props.text}> <div className={"cmpy-mgmt-upgrade-div tooltip"} onClick={props.onClick} key={props.text}>
{props.text} {props.text}
@ -249,21 +255,20 @@ export class IndustryOverview extends BaseReactComponent {
) )
} }
render() { const division = props.routing.currentDivision;
const division = this.routing().currentDivision;
if (division == null) { if (division == null) {
throw new Error(`Routing does not hold reference to the current Industry`); throw new Error(`Routing does not hold reference to the current Industry`);
} }
const makeProductButton = this.renderMakeProductButton(); const makeProductButton = renderMakeProductButton();
return ( return (
<div className={"cmpy-mgmt-industry-overview-panel"}> <div className={"cmpy-mgmt-industry-overview-panel"}>
{this.renderText()} {renderText()}
<br /> <br />
<u className={"industry-purchases-and-upgrades-header"}>Purchases & Upgrades</u><br /> <u className={"industry-purchases-and-upgrades-header"}>Purchases & Upgrades</u><br />
{this.renderUpgrades()} <br /> {renderUpgrades()} <br />
{ {
division.makesProducts && division.makesProducts &&
@ -271,5 +276,4 @@ export class IndustryOverview extends BaseReactComponent {
} }
</div> </div>
) )
}
} }

@ -196,7 +196,7 @@ interface IMaterialProps {
} }
// Creates the UI for a single Material type // Creates the UI for a single Material type
function MaterialComponent(props: any) { function MaterialComponent(props: IMaterialProps) {
const corp = props.corp; const corp = props.corp;
const division = props.division; const division = props.division;
const warehouse = props.warehouse; const warehouse = props.warehouse;