From 0c8b8315183682019ac8aa4be2779c8f192c15b4 Mon Sep 17 00:00:00 2001
From: DCoded <dcoded@live.com>
Date: Sun, 7 Jun 2020 00:31:45 -0400
Subject: [PATCH] Rewrote nursery rewrote in DOM

---
 .../nursery/widgets/reports/nurseryReport.js  | 414 +++++++++---------
 1 file changed, 196 insertions(+), 218 deletions(-)

diff --git a/src/facilities/nursery/widgets/reports/nurseryReport.js b/src/facilities/nursery/widgets/reports/nurseryReport.js
index 2321cc480a3..e23ca32d785 100644
--- a/src/facilities/nursery/widgets/reports/nurseryReport.js
+++ b/src/facilities/nursery/widgets/reports/nurseryReport.js
@@ -4,193 +4,227 @@
  */
 // TODO: refactor this
 App.Facilities.Nursery.nurseryReport = function nurseryReport() {
-	"use strict";
-
-	let r = ``;
+	let
+		frag = document.createDocumentFragment();
 
 	const
-		Matron = getSlave(V.Matron.ID),
-		arcology = V.arcologies[0];
+		slaves = App.Utils.sortedEmployees(App.Entity.facilities.nursery),
+		devBonus = (V.nurseryDecoration !== "standard") ? 1 : 0;
 
 	let
-		NL = App.Utils.jobForAssignment(Job.NURSERY).employeesIDs().size,
-		healthBonus = 0,
-		trustBonus = 0,
-		idleBonus = 0,
-		devBonus = 0;
+		matronBonus = 0;
+
+	function matronChanges() {
+		if (S.Matron) {
+			S.Matron.devotion += devBonus;
+
+			if (S.Matron.health.condition < -80) {
+				improveCondition(S.Matron, 20);
+			} else if (S.Matron.health.condition < -40) {
+				improveCondition(S.Matron, 15);
+			} else if (S.Matron.health.condition < 0) {
+				improveCondition(S.Matron, 10);
+			} else if (S.Matron.health.condition < 90) {
+				improveCondition(S.Matron, 7);
+			}
 
-	if (V.nurseryDecoration !== "standard") {
-		devBonus = 1;
-	}
+			if (S.Matron.devotion <= 60) {
+				S.Matron.devotion++;
+			}
 
-	if (Matron) {
-		const
-			{
-				he, him, his, himself, He, His
-			} = getPronouns(Matron);
+			if (S.Matron.trust < 60) {
+				S.Matron.trust++;
+			}
 
-		if (Matron.health.condition < 100) {
-			improveCondition(Matron, 20);
-		}
-		if (Matron.devotion <= 60) {
-			Matron.devotion++;
-		}
-		if (Matron.trust <= 60) {
-			Matron.trust++;
-		}
-		if (Matron.rules.living !== "luxurious") {
-			Matron.rules.living = "luxurious";
+			if (S.Matron.rules.living !== "luxurious") {
+				S.Matron.rules.living = "luxurious";
+			}
 		}
+	}
+
+	function matronText() {
+		if (S.Matron) {
+			const
+				{ He, he, His, his, him } = getPronouns(S.Matron);
+
+			let
+				r = [];
+
+			r.push(`${SlaveFullName(S.Matron)} is serving as your Matron.`);
 
-		let FLsFetish = 0;
-		/*
-		if (Matron.fetishStrength <= 95) {
-			if (Matron.fetish !== "caring") {
-				if (fetishChangeChance(Matron) > jsRandom(0, 100)) {
-					FLsFetish = 1, Matron.fetishKnown = 1, Matron.fetish = "caring";
-				}
-			} else if (!Matron.fetishKnown) {
-				FLsFetish = 1, Matron.fetishKnown = 1;
+			if (S.Matron.relationship === -3 && S.Matron.devotion > 50) {
+				r.push(`${He} does ${his} best to ${V.nurseryChildren ?
+					`properly raise and look after the children in ${V.nurseryName}` :
+					`look after ${V.nurseryName} and keep it tidy and running smoothly`}.`);
+			}
+
+			if (S.Matron.health.condition < 10) {
+				r.push(`${He} does ${his} best to take good care of ${V.nurseryChildren ? `the children` : `${V.nurseryName}`}, but ${his} poor health limits ${his} ability to do so.`);
+			} else if (S.Matron.health.condition < 80) {
+				r.push(`${His} good health allows ${him} to keep up with the demands of ${V.nurseryName}${V.nurseryNannies ? `and <span class="yellowgreen">work</span> the nannies hard` : ``}.`);
+
+				matronBonus += V.nurseryNannies ? 50 : 0;
 			} else {
-				FLsFetish = 2, Matron.fetishStrength += 4;
+				r.push(`${His} perfect health allows ${him} to really stay on top of things in ${V.nurseryName}${V.nurseryNannies ? ` and <span class="yellowgreen">really drive</span> the nannies hard.` : ``}`);
+
+				matronBonus += V.nurseryNannies ? 75 : 0;
 			}
-		}
-		*/
-		if (Matron.fetish === "none" || Matron.fetish === "caring") {
-			devBonus++;
-		}
 
-		Matron.devotion += devBonus;
+			if (setup.matronCareers.includes(S.Matron.career)) {
+				r.push(`${He} has experience with looking after children from ${his} life before ${he} was a slave.`);
 
-		if (V.Matron !== Matron) {
-			V.Matron = Matron;
-		}
+				matronBonus += 25;
+			} else if (S.Matron.skill.matron >= V.masteredXP) {
+				r.push(`${He} has applicable experience with taking care of children from working for you.`);
 
-		r += `&nbsp;&nbsp;&nbsp;&nbsp;${SlaveFullName(Matron)} is serving as ${V.nurseryName} matron. `;
+				matronBonus += 25;
+			} else {
+				S.Matron.skill.matron += jsRandom(1, Math.ceil((
+					S.Matron.intelligence + S.Matron.intelligenceImplant
+				) / 15) + 8);
+			}
 
-		if (Matron.relationship === -3 && Matron.devotion > 50) {
-			r += `${He} tries ${his} best to ${V.nurseryChildren ? `properly take care of and raise the children` : `look after ${V.nurseryName} and keep it tidy and running smoothly`}. `;
-		}
+			if (S.Matron.actualAge > 35) {
+				r.push(`${His} age and experience make ${him} more effective.`);
 
-		if (FLsFetish === 1) {
-			r += `${He} ${V.nurseryChildren ? `seems to have a real soft spot for children, and enjoys working with the child${V.nurseryChildren > 1 ? `ren` : ``} in ${V.nurseryName} and raising ${V.nurseryChildren > 1 ? `them` : V.cribs[0].genes === "XX" ? `her` : `him`} to be ${V.nurseryChildren > 1 ? `good slaves` : `a good slave`}` : ``/* TODO: */}. ${He} finds real satisfaction in helping your slaves find sexual gratification, and <span class="lightsalmon">becomes more caring.</span> `;
-		} else if (FLsFetish === 2) {
-			r += `Every new slave in the nursery is a new person ${he} gets to connect with and serve. Sexually. <span class='lightsalmon'>${He} becomes more caring.</span>`;	// TODO:
-		}
+				matronBonus += 25;
+			} else if (!V.AgePenalty) {
+				matronBonus += 25;
+			}
 
-		// TODO:
-		if (setup.matronCareers.includes(Matron.career)) {
-			r += `${He} has experience with childcare from ${his} life before ${he} was a slave, making ${him} better at properly raising children, and giving ${him} a better chance of softening flaws into beneficial quirks. `;
-			idleBonus++;
-		} else if (Matron.skill.matron >= V.masteredXP) {
-			r += `${He} has experience with childcare from working for you, making ${him} better at properly raising children, and giving ${him} a better chance of softening flaws into beneficial quirks. `;
-			idleBonus++;
-		} else {
-			Matron.skill.matron += jsRandom(1, (Matron.intelligence + 4) * 2);
-		}
+			if (S.Matron.intelligence + S.Matron.intelligenceImplant > 15) {
+				r.push(`${He}'s intelligent enough that ${he} is more effectively able to take care of ${V.nurseryName}${V.nurseryChildren ? ` and its children` : ``}.`);
 
-		// TODO:
-		if (Matron.fetish === "none") {
-			r += `${Matron.slaveName} respects the slaves working in the nursery, allowing them to care for the children more effectively. `;
-			idleBonus++;
-		} else if (Matron.fetish === "dom") {
-			r += `${Matron.slaveName} enjoys being able to have control over the nannies. `;
-			idleBonus++;
-		} else if (Matron.fetishKnown) {
-			r += `${Matron.slaveName} can't keep ${his} hands to ${himself}, preventing the slaves in the nursery from relaxing completely. `;
-		}
+				matronBonus += S.Matron.intelligence + S.Matron.intelligenceImplant;
+			}
 
-		// TODO:
-		if (Matron.visualAge > 35) {
-			r += `${His} apparent maturity encourages the slaves in the nursery to relax and pour out their troubles to ${him}. `;
-		}
+			if (slaves.length < V.nursery) {
+				let seed = jsRandom(1, 10) + ((V.nursery - NL) * (jsRandom(150, 170) + (idleBonus * 10)));
+				cashX(seed, "nursery", Matron);
+
+				r.push(`<br>&nbsp;&nbsp;&nbsp;&nbsp;Since ${he} doesn't have enough children to occupy all ${his} time, ${V.nurseryName} takes in citizens' children on a contract basis and ${he} cares for them too, earning <span class='yellowgreen'>${cashFormat(seed)}.</span>`);
+			}
 
-		// TODO:
-		if (Matron.intelligence > 0) {
-			r += `${He}'s so intelligent ${he} can suss out the cause of slaves' emotional issues and counsel them effectively. `;
+			if (arcology.FSRepopulationFocus > 0 && V.nurseryBabies > 0) {
+				r += `Society <span class='green'>loves</span> the way you are raising more children for ${arcology.name}. `;
+				FSChange("Repopulationist", 2);
+			}
 		}
 
-		// TODO: write more
+		return r.join(' ');
+	}
 
-		if (NL < V.nursery) {
-			let seed = jsRandom(1, 10) + ((V.nursery - NL) * (jsRandom(150, 170) + (idleBonus * 10)));
-			cashX(seed, "nursery", Matron);
-			r += `<br>&nbsp;&nbsp;&nbsp;&nbsp;Since ${he} doesn't have enough children to occupy all ${his} time, ${V.nurseryName} takes in citizens' children on a contract basis and ${he} cares for them too, earning <span class='yellowgreen'>${cashFormat(seed)}.</span> `;
-		}
+	/**
+	 * Generates (and returns if not silent) a standard slave report
+	 * @param {App.Entity.SlaveState} slave
+	 * @param {boolean} silent
+	 * @returns {HTMLElement|null}
+	 */
+	function standardSlaveReport(slave, silent) {
+		const
+			clothes = App.SlaveAssignment.choosesOwnClothes(slave);
+			tired(slave);
+
+		const
+			rules = App.UI.DOM.renderPassage("SA rules"),
+			diet = App.UI.DOM.renderPassage("SA diet"),
+			ltEffects = App.UI.DOM.renderPassage("SA long term effects"),
+			drugs = App.SlaveAssignment.drugs(slave),
+			relationships = App.UI.DOM.renderPassage("SA relationships"),
+			rivalries = App.UI.DOM.renderPassage("SA rivalries"),
+			devotion = App.UI.DOM.renderPassage("SA devotion");
+
+			if (!silent) {
+				const content = App.UI.DOM.makeElement("div", '', "indent");
+
+				$(content).append(clothes, rules, diet, ltEffects, drugs, relationships, rivalries, document.createElement('br'), devotion);
+
+				return content;
+			}
 
-		if (arcology.FSRepopulationFocus > 0 && V.nurseryBabies > 0) {
-			r += `Society <span class='green'>loves</span> the way you are raising more children for ${arcology.name}. `;
-			FSChange("Repopulationist", 2);
-		}
 
-		if (NL > 0) {
-			r += `<br><br>`;
-		}
 	}
 
-	if (NL > 0) {
-		r += `&nbsp;&nbsp;&nbsp;&nbsp;<strong>${NL > 1 ? `There are ${NL} slaves` : `There is one slave`} working in ${V.nurseryName}.</strong> `;
+	const
+		matronEffects = App.UI.DOM.appendNewElement("p", frag, '', "indent");
+
+	matronChanges();
+	$(matronEffects).append(matronText());
+
+	if (slaves) {
+		const
+			intro = App.UI.DOM.appendNewElement("p", frag, '', "indent");
+
+		let
+			r = [];
+
+		r.push(`${slaves.length > 1 ? `There are ${slaves.length} slaves` : `There is one slave`} working in ${V.nurseryName}.</strong>`);
+
 		if (arcology.FSRepopulationFocus > 0 && V.nurseryBabies > 0) {
-			r += `Society <span class="green">approves</span> of your bringing more children into this world. `;
+			r.push(`Society <span class="green">approves</span> of your bringing more children into this world.`);
 		} else if (arcology.FSGenderFundamentalist > 0) {
-			r += `Society <span class="green">approves</span> of your assigning slaves to a traditionally feminine role. `;
+			r.push(`Society <span class="green">approves</span> of your assigning slaves to a traditionally feminine role.`);
 		}
+
+		$(intro).append(r.join(' '));
 	}
 
-	if (Matron) {
-		V.i = V.slaveIndices[Matron.ID];
-		if (V.showEWD) {
-			// TODO: all this
-			r += `<br><br>`;
-			/* 000-250-006 */
+	if (S.Matron) {
+		/** @type {App.Entity.SlaveState} */
+		const slave = S.Matron;
+
+		V.i = V.slaveIndices[slave.ID];
+		App.Utils.setLocalPronouns(slave);	// needed for "include"s
+
+		if (V.showEWD !== 0) {
+			const
+				matronEntry = App.UI.DOM.appendNewElement("div", frag, '', "slave-report");
+
 			if (V.seeImages && V.seeReportImages) {
-				r += `<div class="imageRef medImg">${SlaveArt(Matron, 2, 0)}</div>`;
+				App.UI.DOM.appendNewElement("div", matronEntry, App.Art.SlaveArtElement(slave, 0, 0), ["imageRef", "tinyImg"]);
 			}
-			/* 000-250-006 */
-			r += `<strong><u><span class="pink">${SlaveFullName(Matron)}</span></u></strong> is serving as the Matron in ${V.nurseryName}.`;
-			r += `${App.SlaveAssignment.choosesOwnClothes(Matron)}`;
-			r += `<<include "SA rules">>`;
-			r += `<<include "SA diet">>`;
-			r += `<<include "SA long term effects">>`;
-			r += `${App.SlaveAssignment.drugs(Matron)}`;
-			r += `<<include "SA relationships">>`;
-			r += `<<include "SA rivalries">>`;
-			r += `<br><<include "SA devotion">>`;
+
+			$(matronEntry).append(`<span class="slave-name">${SlaveFullName(slave)}</span> is serving as your Matron.`);
+			$(matronEntry).append(standardSlaveReport(slave, false));
 		} else {
-			r += `<<silently>>
-			${App.SlaveAssignment.choosesOwnClothes(Matron)};
-			<<include "SA rules">>
-			<<include "SA diet">>
-			<<include "SA long term effects">>
-			${App.SlaveAssignment.drugs(Matron)};
-			<<include "SA relationships">>
-			<<include "SA rivalries">>
-			<<include "SA devotion">>
-			<</silently>>`;
+			standardSlaveReport(slave, true);
 		}
 	}
 
-	for (const slave of App.Utils.sortedEmployees(App.Utils.jobForAssignment(Job.NURSERY))) {
+	// FIXME: check these numbers over to make sure they make sense
+	for (const slave of slaves) {
 		V.i = V.slaveIndices[slave.ID];
 
-		slave.devotion += devBonus, slave.trust += trustBonus;
-		improveCondition(slave, healthBonus);
+		slave.devotion += devBonus;
+
+		if (slave.devotion <= 20 && slave.trust >= -20) {
+			slave.devotion -= 5;
+			slave.trust -= 5;
+		} else if (slave.devotion <= 10) {
+			slave.devotion += 2;
+		} else if (slave.devotion >= 80) {
+			slave.devotion -= 2;
+		}
 
-		// TODO: rework these
-		if (slave.devotion < 60 && slave.trust < 60) {
-			slave.devotion++, slave.trust++;
-		} else if (slave.devotion < 40) {
-			slave.devotion += 10;
-		} else if (slave.trust < 40) {
-			slave.trust += 10;
+		if (slave.trust < -20) {
+			slave.trust += 3;
+		} else if (slave.trust < -50) {
+			slave.trust += 2;
+		} else if (slave.trust < -30) {
+			slave.trust += 1;
 		}
 
-		// TODO: rework this
-		if (V.nurseryUpgrade === 1 && slave.health.condition < 20) {
+		if (slave.health.condition < -80) {
+			improveCondition(slave, 20);
+		} else if (slave.health.condition < -40) {
+			improveCondition(slave, 10);
+		} else if (slave.health.condition < 0) {
+			improveCondition(slave, 7);
+		} else if (slave.health.condition < 90) {
 			improveCondition(slave, 3);
 		}
 
-		// TODO:
+		// TODO: add more cases
 		switch (V.nurseryDecoration) {
 			case "Repopulationist":
 				slave.rules.living = "luxurious";
@@ -203,96 +237,40 @@ App.Facilities.Nursery.nurseryReport = function nurseryReport() {
 				break;
 		}
 
-		// TODO:
+		App.Utils.setLocalPronouns(slave);	// needed for "include"s
+
 		if (V.showEWD) {
 			const
-				He = slave.genes === "XX" ? `She` : `He`;
+				{He} = getPronouns(slave),
+				slaveEntry = App.UI.DOM.appendNewElement("div", frag, '', "slave-report");
 
-			r += `<br><br>`;
-			/* 000-250-006 */
 			if (V.seeImages && V.seeReportImages) {
-				r += `<div class="imageRef smlImg">${SlaveArt(slave, 0, 0)}</div>`;
+				App.UI.DOM.appendNewElement("div", slaveEntry, App.Art.SlaveArtElement(slaveEntry, 0, 0), ["imageRef", "tinyImg"]);
 			}
-			/* 000-250-006 */
-			r += `<strong><u><span class="pink">${SlaveFullName(slave)}</span></u></strong>`;
+
+			$(slaveEntry).append(`<span class="slave-name">${SlaveFullName(slaveEntry)}</span> `);
+
 			if (slave.choosesOwnAssignment === 2) {
-				r += `${choosesOwnJob(slave)}`;
+				$(slaveEntry).append(App.UI.DOM.renderPassage("SA chooses own job"));
 			} else {
-				r += ` is working in ${V.nurseryName}. `;
+				$(slaveEntry).append(`is working out of ${V.nurseryName}.`);
 			}
-			// TODO: clean this mess up
-			r += `<br>&nbsp;&nbsp;&nbsp;&nbsp;${He} ${App.SlaveAssignment.nanny(slave)}<br>&nbsp;&nbsp;&nbsp;`;
-			r += `${App.SlaveAssignment.choosesOwnClothes(slave)} ${saRules(slave)}`;
-			r += `<<include "SA diet">>`;					// TODO:
-			r += `<<include "SA long term effects">>`;		// TODO:
-			r += `${App.SlaveAssignment.drugs(slave)}`;						// TODO:
-			r += `<<include "SA relationships">>`;			// TODO:
-			r += `<<include "SA rivalries">>`;				// TODO:
-			r += `<br><<include "SA devotion">>`;			// TODO:
-		} else {
-			r += `<<silently>>`;
-			r += `${choosesOwnJob(slave)} ${App.SlaveAssignment.nanny(slave)} ${App.SlaveAssignment.choosesOwnClothes(slave)} ${saRules(slave)}`;
-			r += `<<include "SA diet">>`;
-			r += `<<include "SA long term effects">>`;
-			r += `${App.SlaveAssignment.drugs(slave)}`;
-			r += `<<include "SA relationships">>`;
-			r += `<<include "SA rivalries">>`;
-			r += `<<include "SA devotion">>`;
-			r += `<</silently>>`;
-		}
-	}
 
-	if (NL > 0 || Matron) {
-		r += `<br><br>`;
-	}
-
-	function choosesOwnJob(slave) {
-		let r = ``;
+			const
+				nannyContent = App.UI.DOM.appendNewElement("div", slaveEntry, '', "indent");
 
-		if (V.universalRulesAssignsSelfFacility && slave.devotion > 50 && canWalk(slave) && canSee(slave) && slave.sexualQuirk === "caring" && V.nurseryNannies > NL) {
-			slave.choosesOwnAssignmentText += ` enjoys taking care of children, so ${he} decides to work in ${V.nurseryName}. `;
-			r = slave.choosesOwnAssignmentText;
-			assignJob(slave, Job.NURSERY);
+			$(nannyContent).append(`${He} ${App.SlaveAssignment.nanny(slaveEntry, matronBonus)}`);
+		} else {	// silently discard return values
+			App.SlaveAssignment.nanny(slave, matronBonus);
+			standardSlaveReport(slave, true);
 		}
-
-		return r;
 	}
 
-	// function diet(slave) {
-	// 	let r = ``;
-
-	// 	return r;
-	// }
-
-	// function longTermEffects(slave) {
-	// 	let r = ``;
-
-	// 	return r;
-	// }
-
-	// function drugs(slave) {
-	// 	let r = ``;
-
-	// 	return r;
-	// }
-
-	// function relationships(slave) {
-	// 	let r = ``;
-
-	// 	return r;
-	// }
-
-	// function rivalries(slave) {
-	// 	let r = ``;
-
-	// 	return r;
-	// }
-
-	// function devotion(slave) {
-	// 	let r = ``;
+	if (V.nurseryDecoration !== "standard") {
+		const decorationEffects = App.UI.DOM.appendNewElement("p", frag, '', "indent");
 
-	// 	return r;
-	// }
+		$(decorationEffects).append(`${V.nurseryNameCaps}'s ${V.nurseryDecoration} atmosphere <span class="devotion inc">has a minor impact on your servants.</span>`)
+	}
 
-	return r;
+	return frag;
 };
-- 
GitLab