From 6b884736cd24003b5efa4381e76b0fbd8849e492 Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Sun, 1 Nov 2020 20:20:36 -0500
Subject: [PATCH] start corpo

---
 src/Corporation/corporationDevelopments.tw    |  97 -----------------
 .../economics/corporationDevelopments.js      | 101 ++++++++++++++++++
 src/uncategorized/economics.tw                |   5 +-
 3 files changed, 103 insertions(+), 100 deletions(-)
 delete mode 100644 src/Corporation/corporationDevelopments.tw
 create mode 100644 src/endWeek/economics/corporationDevelopments.js

diff --git a/src/Corporation/corporationDevelopments.tw b/src/Corporation/corporationDevelopments.tw
deleted file mode 100644
index a664bf48726..00000000000
--- a/src/Corporation/corporationDevelopments.tw
+++ /dev/null
@@ -1,97 +0,0 @@
-:: Corporation Developments [nobr]
-
-/*Main Corporation Pass*/
-
-<<if App.Corporate.cash < 0>>
-	<<set App.Corporate.cash = Math.trunc(App.Corporate.cash * 1.02)>> /*2% weekly interest rate on negative cash*/
-<</if>>
-
-<h1>Corporation Management</h1>
-<h2>Operational Results</h2>
-/*Divisions doing their thing*/
-<<set _weekLedger = App.Corporate.endWeek()>>
-<<for _d range _weekLedger.divisionLedgers>>
-	<<set _div = _d.division>>
-	/* Reporting on number of slaves being processed or completed processing */
-	<br><<= _div.name>>: The division <<= _div.message_endWeek_Slaves(_d) >>
-	<<if _d.market.originalBuy != null>>
-		<br>
-		<<if _d.market.buy == 0>>
-			It couldn't purchase <<= numberWithPlural(_d.market.originalBuy, "slave") >> to replenish its stock from the market because it couldn't afford to purchase price.
-		<<else>>
-			It needed to replenish its slave stock of <<= numberWithPlural(_d.market.originalBuy, "slave")>>, but couldn't afford to buy all of them. It bought <<= numberWithPlural(_d.market.buy, _div.nounSlaveFromMarket)>> for <<= cashFormatColor(_d.market.finalPurchase, true) >>.
-		<</if>>
-	<<elseif _d.market.buy > 0>>
-		<br>It replenished its slave stock and bought <<= numberWithPlural(_d.market.buy, _div.nounSlaveFromMarket) >> from the market for <<= cashFormatColor(_d.market.finalPurchase, true) >>.
-	<</if>>
-	<<if _d.transfer.total > 0>>
-		<<for _nextDivLedger range _d.transfer.divisions>>
-			<<set _nextDiv = _nextDivLedger.division>>
-			<<set _slavesToNext = _nextDivLedger.fill>>
-
-			It moved <<= numberWithPlural(_slavesToNext, "slave")>> to the <<= _nextDiv.name>> Division.
-		<</for>>
-	<</if>>
-	<<if _div.toMarket>>
-		<<if _div.heldSlaves == 0>>
-			<<if _d.market.sell > 0>>
-				It immediately sold <<= numberWithPlural(_d.market.sell, _div.nounFinishedSlave) >> to the market and made <<= cashFormatColor(_d.market.finalSale)>>.
-			<</if>>
-		<<else>>
-			It holds @@.green;<<= numberWithPlural(_div.heldSlaves, _div.nounFinishedSlave)>>@@ at the end of the
-			<<if _d.market.sell > 0>>
-				 week, but it ran out of storage space and had to sell @@.red;<<= numberWithPlural(_d.market.sell, "slave")>>@@ and made <<= cashFormatColor(_d.market.finalSale)>>.
-			<<else>>
-				 week.
-			<</if>>
-		<</if>>
-	<</if>>
-	<<if _d.revenue.value > 0>>
-		It earned <<= cashFormatColor(_d.revenue.value)>> in revenue.
-	<</if>>
-<</for>>
-
-/*Aggregate Corporation Results*/
-<<includeDOM App.Corporate.writeLedger(App.Corporate.ledger.current, $week)>>
-
-/*Division Expansion Tokens*/
-<<if _weekLedger.canExpandNow>>
-	<div class="majorText">Your corporation is ready to start an additional division!</div>
-<</if>>
-
-/*Specializations tokens*/
-<<if _weekLedger.canSpecializeNow>>
-	<div class="majorText">Your corporation is ready to specialize its slaves further!</div>
-<</if>>
-
-/*Calculating cash set aside for dividend*/
-<h2>Dividend</h2>
-<div>
-<<if App.Corporate.dividendRatio > 0>>
-	The corporation is currently reserving <<= Math.floor(App.Corporate.dividendRatio * 100)>>% of its profit to be paid out as dividends.
-<<else>>
-	The corporation is currently not reserving a portion of its profit to be paid out as dividends.
-<</if>>
-<<if App.Corporate.payoutCash>>
-	It is putting aside unused cash reserves to be paid out as dividends.
-<</if>>
-</div>
-<div>
-<<if App.Corporate.dividend > 0>>
-	<<if _weekLedger.hasDividend>>
-		It reserved <<print cashFormatColor(_weekLedger.dividend)>> this week.
-	<</if>>
-	A total of <<print cashFormatColor(App.Corporate.dividend)>> has been put aside for its shareholders.
-<</if>>
-</div>
-<<if _weekLedger.hasPayout>>
-	<div>This week the dividends were paid out, you received <<print cashFormatColor(_weekLedger.payout)>>.</div>
-<</if>>
-
-/*Bankrupted the Corporation*/
-<<if App.Corporate.value < 0>>
-	<<run App.Corporation.Dissolve()>>
-	<br>@@.red;Your corporation went bankrupt.@@
-<</if>>
-/*This needs to be at the very end of the financials*/
-<<run App.Corporate.ledger.swap()>>
diff --git a/src/endWeek/economics/corporationDevelopments.js b/src/endWeek/economics/corporationDevelopments.js
new file mode 100644
index 00000000000..3331bea7fc7
--- /dev/null
+++ b/src/endWeek/economics/corporationDevelopments.js
@@ -0,0 +1,101 @@
+App.EndWeek.corporationDevelopments = function() {
+	const el = document.createElement("p");
+	let r = [];
+	/* Main Corporation Pass*/
+
+	if (App.Corporate.cash < 0) {
+		App.Corporate.cash = Math.trunc(App.Corporate.cash * 1.02); /* 2% weekly interest rate on negative cash*/
+	}
+	App.UI.DOM.appendNewElement("h1", el, "Corporation Management");
+	App.UI.DOM.appendNewElement("h2", el, "Operational Results");
+	/* Divisions doing their thing*/
+	const _weekLedger = App.Corporate.endWeek();
+	for (const _d in _weekLedger.divisionLedgers) {
+		const _div = _d.division;
+		const r = [];
+		/* Reporting on number of slaves being processed or completed processing */
+		r.push(`${_div.name}: The division ${_div.message_endWeek_Slaves(_d)}`);
+		if (_d.market.originalBuy !== null) {
+			if (_d.market.buy === 0) {
+				r.push(App.UI.DOM.makeElement("div", `It couldn't purchase ${numberWithPlural(_d.market.originalBuy, "slave")} to replenish its stock from the market because it couldn't afford to purchase price.`));
+			} else {
+				r.push(App.UI.DOM.makeElement("div",  `It needed to replenish its slave stock of ${numberWithPlural(_d.market.originalBuy, "slave")}, but couldn't afford to buy all of them. It bought ${numberWithPlural(_d.market.buy, _div.nounSlaveFromMarket)} for ${cashFormatColor(_d.market.finalPurchase, true)}.`));
+			}
+		} else if (_d.market.buy > 0) {
+			r.push(App.UI.DOM.makeElement("div", `It replenished its slave stock and bought ${numberWithPlural(_d.market.buy, _div.nounSlaveFromMarket)} from the market for ${cashFormatColor(_d.market.finalPurchase, true)}.`));
+		}
+		if (_d.transfer.total > 0) {
+			for (const _nextDivLedger of _d.transfer.divisions) {
+				const _nextDiv = _nextDivLedger.division;
+				const _slavesToNext = _nextDivLedger.fill;
+				r.push(`It moved ${numberWithPlural(_slavesToNext, "slave")} to the ${_nextDiv.name} Division.`);
+			}
+		}
+		if (_div.toMarket) {
+			if (_div.heldSlaves === 0) {
+				if (_d.market.sell > 0) {
+					r.push(`It immediately sold ${numberWithPlural(_d.market.sell, _div.nounFinishedSlave)} to the market and made ${cashFormatColor(_d.market.finalSale)}.`);
+				}
+			} else {
+				r.push(`It holds <span class="green">${numberWithPlural(_div.heldSlaves, _div.nounFinishedSlave)}</span> at the end of the`);
+				if (_d.market.sell > 0) {
+					r.push(`week, but it ran out of storage space and had to sell <span class="red">${numberWithPlural(_d.market.sell, "slave")}</span> and made ${cashFormatColor(_d.market.finalSale)}.`);
+				} else {
+					r.push(`week.`);
+				}
+			}
+		}
+		if (_d.revenue.value > 0) {
+			r.push(`It earned ${cashFormatColor(_d.revenue.value)} in revenue.`);
+		}
+		App.Events.addNode(el, r, "div");
+	}
+	App.Events.addNode(el, r);
+
+	/* Aggregate Corporation Results*/
+	el.append(App.Corporate.writeLedger(App.Corporate.ledger.current, V.week));
+
+	/* Division Expansion Tokens*/
+	if (_weekLedger.canExpandNow) {
+		App.UI.DOM.appendNewElement("div", el, "Your corporation is ready to start an additional division!", "majorText");
+	}
+
+	/* Specializations tokens*/
+	if (_weekLedger.canSpecializeNow) {
+		App.UI.DOM.appendNewElement("div", el, "Your corporation is ready to specialize its slaves further!", "majorText");
+	}
+
+	/* Calculating cash set aside for dividend*/
+	App.UI.DOM.appendNewElement("h2", el, "Dividend");
+	r = [];
+	if (App.Corporate.dividendRatio > 0) {
+		r.push(`The corporation is currently reserving ${Math.floor(App.Corporate.dividendRatio * 100)}% of its profit to be paid out as dividends.`);
+	} else {
+		r.push(`The corporation is currently not reserving a portion of its profit to be paid out as dividends.`);
+	}
+	if (App.Corporate.payoutCash) {
+		r.push(`It is putting aside unused cash reserves to be paid out as dividends.`);
+	}
+	App.Events.addNode(el, r, "div");
+
+	if (App.Corporate.dividend > 0) {
+		r = [];
+		if (_weekLedger.hasDividend) {
+			r.push(`It reserved ${cashFormatColor(_weekLedger.dividend)} this week.`);
+		}
+		r.push(`A total of ${cashFormatColor(App.Corporate.dividend)} has been put aside for its shareholders.`);
+		App.Events.addNode(el, r, "div");
+	}
+
+	if (_weekLedger.hasPayout) {
+		App.UI.DOM.appendNewElement("div", el, `This week the dividends were paid out, you received ${cashFormatColor(_weekLedger.payout)}.`);
+	}
+
+	/* Bankrupted the Corporation*/
+	if (App.Corporate.value < 0) {
+		App.Corporation.Dissolve();
+		App.UI.DOM.appendNewElement("div", el, "Your corporation went bankrupt.", "red");
+	}
+	/* This needs to be at the very end of the financials*/
+	App.Corporate.ledger.swap();
+};
diff --git a/src/uncategorized/economics.tw b/src/uncategorized/economics.tw
index 15fe30f21f0..d525617fe12 100644
--- a/src/uncategorized/economics.tw
+++ b/src/uncategorized/economics.tw
@@ -27,8 +27,7 @@
 	<</if>>
 
 	<<if $corp.Incorporated == 1>>
-		<br><br>
-		<<include "Corporation Developments">>
+		<<includeDOM App.EndWeek.corporationDevelopments()>>
 	<</if>>
 
 	<<if $secExpEnabled > 0>>
@@ -89,7 +88,7 @@
 		<<if $corp.Incorporated == 1>>
 			<div id="Corporation" class="tab-content">
 				<div class="content">
-					<<include "Corporation Developments">>
+					<<includeDOM App.EndWeek.corporationDevelopments()>>
 				</div>
 			</div>
 		<</if>>
-- 
GitLab