From 732b9f4ee296772af2a15c586c0b4bf2914eb381 Mon Sep 17 00:00:00 2001
From: DCoded <dcoded@live.com>
Date: Wed, 29 Jul 2020 02:08:13 -0400
Subject: [PATCH] DOMified expand farmyard and remove slaves

---
 src/facilities/farmyard/farmyard.js | 57 +++++++++++++++++++++++++++++
 src/facilities/farmyard/farmyard.tw | 14 +------
 2 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/src/facilities/farmyard/farmyard.js b/src/facilities/farmyard/farmyard.js
index e208f0a3adc..aaf407d04ee 100644
--- a/src/facilities/farmyard/farmyard.js
+++ b/src/facilities/farmyard/farmyard.js
@@ -1,3 +1,60 @@
+App.Facilities.Farmyard.expand = function() {
+	const
+		frag = new DocumentFragment(),
+
+		desc = document.createElement("div"),
+		link = document.createElement("div"),
+		note = document.createElement("span"),
+		cost = document.createElement("span"),
+
+		upgradeCost = Math.trunc(V.farmyard * 1000 * V.upgradeMultiplierArcology);
+
+		link.classList.add("indent");
+		note.classList.add("note");
+		cost.classList.add("yellowgreen");
+
+		cost.append(cashFormat(upgradeCost));
+
+	desc.append(`It can support ${V.farmyard} farmhands. Currently there ${V.farmyard === 1 ? `is` : `are`} ${V.farmyard} ${V.farmyard === 1 ? `farmhand` : `farmhands`} in ${V.farmyardName}. `);
+	note.append(` Costs `, cost, ` and will increase upkeep costs`);
+
+	link.append(App.UI.DOM.passageLink(`Expand ${V.farmyardName}`, "Farmyard", () => {
+		cashX(forceNeg(cost));
+		V.farmyard += 5;
+		V.PC.skill.engineering += .1;
+	}));
+
+	link.append(note);
+	desc.append(link);
+	frag.append(desc);
+
+	if (V.farmyardFarmers || V.farmyardShowgirls) {
+		const
+			removeLink = document.createElement("div"),
+			warning = document.createElement("span"),
+
+			count = App.Entity.facilities.farmyard.totalEmployeesCount,
+			newPop = count + V.dormitoryPopulation;
+
+		removeLink.classList.add("indent");
+		warning.classList.add("red");
+
+		warning.append(` Dormitory capacity will be exceeded.`);
+
+		removeLink.append(App.UI.DOM.passageLink("Remove all slaves", "Farmyard", () => {
+			App.Utils.moveFacilityWorkers(App.Entity.facilities.farmyard);
+		}));
+
+		if (newPop > V.dormitory) {
+			removeLink.append(warning);
+		}
+
+		frag.append(removeLink);
+	}
+
+	return frag;
+};
+
 App.Facilities.Farmyard.transferMenials = function() {
 	const
 		frag = new DocumentFragment(),
diff --git a/src/facilities/farmyard/farmyard.tw b/src/facilities/farmyard/farmyard.tw
index 69286f1c8b4..b7675f7b242 100644
--- a/src/facilities/farmyard/farmyard.tw
+++ b/src/facilities/farmyard/farmyard.tw
@@ -88,19 +88,7 @@
 </p>
 
 <div id="farmhandcount">
-	<<set _Tmult0 = Math.trunc($farmyard*1000*$upgradeMultiplierArcology)>>
-	It can support $farmyard farmhands. Currently there <<if _FyL == 1>>is<<else>>are<</if>> _FyL farmhand<<if _FyL != 1>>s<</if>> at $farmyardName.
-	<div class= "choices">
-		[[Expand the farmyard|Farmyard][cashX(forceNeg(_Tmult0), "capEx"), $farmyard += 5, $PC.skill.engineering += .1]]
-		<span class="note">
-			Costs <<print cashFormat(_Tmult0)>> and will increase upkeep costs
-		</span>
-	</div>
-	<div class= "choices">
-		<<if _FyL > 0>>
-			<<removeFacilityWorkers "farmyard" "rest" "rest">>
-		<</if>>
-	</div>
+<<includeDOM App.Facilities.Farmyard.expand()>>
 </div>
 
 <div id="menials">
-- 
GitLab