From 7aa287535355337f7c80d68ac3bd7f98097986cb Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Sun, 7 Jun 2020 11:37:44 -0700
Subject: [PATCH] Do a better job of labeling sole parents, and don't use slave
 indexes in the slave summary relation blocks.

---
 src/descriptions/familySummaries.js |  41 +++++++---
 src/js/slaveSummaryHelpers.js       | 119 ++++++++++++----------------
 2 files changed, 78 insertions(+), 82 deletions(-)

diff --git a/src/descriptions/familySummaries.js b/src/descriptions/familySummaries.js
index 66defe224a4..5db6e4def0c 100644
--- a/src/descriptions/familySummaries.js
+++ b/src/descriptions/familySummaries.js
@@ -93,22 +93,32 @@ App.Desc.family = (function() {
 			r.push(`${He} was <span class="lightgreen">born from ${knownSlave(slave.mother)}'s</span> fertile womb.`);
 		}
 
-		let children = V.slaves.filter((s) => slave.ID === s.father);
+		let children = V.slaves.filter((s) => slave.ID === s.father && slave.ID === s.mother);
+		const isSoleParent = children.length > 0;
 		if (children.length > 2) {
-			r.push(`${He} <span class="lightgreen">fathered ${slaveListToText(children)}.</span>`);
+			r.push(`${He} <span class="lightgreen">is the sole parent of ${slaveListToText(children)}.</span>`);
 		} else if (children.length > 1) {
-			r.push(`${He} <span class="lightgreen">fathered a pair of your slaves: ${slaveListToText(children)}.</span>`);
+			r.push(`${He} <span class="lightgreen">is the sole parent of a pair of your slaves: ${slaveListToText(children)}.</span>`);
 		} else if (children.length > 0) {
-			r.push(`${He} <span class="lightgreen">fathered a single slave of yours: ${slaveListToText(children)}.</span>`);
+			r.push(`${He} <span class="lightgreen">is the sole parent of a single slave of yours: ${slaveListToText(children)}.</span>`);
 		}
 
-		children = V.slaves.filter((s) => slave.ID === s.mother);
+		children = V.slaves.filter((s) => slave.ID === s.father && slave.ID !== s.mother);
 		if (children.length > 2) {
-			r.push(`${He} <span class="lightgreen">gave birth to ${slaveListToText(children)}.</span>`);
+			r.push(`${He} <span class="lightgreen">fathered ${slaveListToText(children)}${isSoleParent ? " with other mothers" : ""}.</span>`);
 		} else if (children.length > 1) {
-			r.push(`${He} <span class="lightgreen">gave birth to a pair of your slaves: ${slaveListToText(children)}.</span>`);
+			r.push(`${He} <span class="lightgreen">fathered a pair of your slaves${isSoleParent ? " with other mothers" : ""}: ${slaveListToText(children)}.</span>`);
 		} else if (children.length > 0) {
-			r.push(`${He} <span class="lightgreen">gave birth to a single slave of yours: ${slaveListToText(children)}.</span>`);
+			r.push(`${He} <span class="lightgreen">fathered a single slave of yours${isSoleParent ? " with another mother" : ""}: ${slaveListToText(children)}.</span>`);
+		}
+
+		children = V.slaves.filter((s) => slave.ID === s.mother && slave.ID !== s.father);
+		if (children.length > 2) {
+			r.push(`${He} <span class="lightgreen">gave birth to ${slaveListToText(children)}${isSoleParent ? " with other fathers" : ""}.</span>`);
+		} else if (children.length > 1) {
+			r.push(`${He} <span class="lightgreen">gave birth to a pair of your slaves${isSoleParent ? " with other fathers" : ""}: ${slaveListToText(children)}.</span>`);
+		} else if (children.length > 0) {
+			r.push(`${He} <span class="lightgreen">gave birth to a single slave of yours${isSoleParent ? " with another father" : ""}: ${slaveListToText(children)}.</span>`);
 		}
 
 		function getParentIndices(slaveID) {
@@ -634,16 +644,23 @@ App.Desc.family = (function() {
 			}
 		}
 
+		/* Player is sole parent */
+		let children = V.slaves.filter((s) => s.father === V.PC.ID && s.mother === V.PC.ID);
+		if (children.length > 0) {
+			r.push(`<br>You are the sole parent of ${num(children.length)} of your slaves, <span class="lightgreen">${slaveListToText(children)}.</span>`);
+		}
+		const isSoleParent = children.length > 0;
+
 		/* Player is Father, lists children you fathered */
-		let children = V.slaves.filter((s) => s.father === V.PC.ID);
+		children = V.slaves.filter((s) => s.father === V.PC.ID && s.mother !== V.PC.ID);
 		if (children.length > 0) {
-			r.push(`<br>You fathered ${num(children.length)} of your slaves, <span class="lightgreen">${slaveListToText(children)}.</span>`);
+			r.push(`<br>You fathered ${num(children.length)} of your slaves${isSoleParent ? " with other mothers" : ''}, <span class="lightgreen">${slaveListToText(children)}.</span>`);
 		}
 
 		/* Player is Mother, lists birthed children */
-		children = V.slaves.filter((s) => s.mother === V.PC.ID);
+		children = V.slaves.filter((s) => s.mother === V.PC.ID && s.father !== V.PC.ID);
 		if (children.length > 0) {
-			r.push(`<br>You gave birth to ${num(children.length)} of your slaves, <span class="lightgreen">${slaveListToText(children)}.</span>`);
+			r.push(`<br>You gave birth to ${num(children.length)} of your slaves${isSoleParent ? " who had other fathers" : ''}, <span class="lightgreen">${slaveListToText(children)}.</span>`);
 		}
 
 		/* Player is grandparent */
diff --git a/src/js/slaveSummaryHelpers.js b/src/js/slaveSummaryHelpers.js
index 1c2294d617f..50fb0e8af9e 100644
--- a/src/js/slaveSummaryHelpers.js
+++ b/src/js/slaveSummaryHelpers.js
@@ -1360,10 +1360,10 @@ App.UI.SlaveSummaryImpl = function() {
 			let res = "";
 			let handled = 0;
 			if (slave.mother > 0) {
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.mother);
-				if (_ssj !== -1) {
-					res += `${SlaveFullName(V.slaves[_ssj])}'s ${getPronouns(slave).daughter}`;
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
+				const _ssj = V.slaves.find(s => s.ID === slave.mother);
+				if (_ssj) {
+					res += `${SlaveFullName(_ssj)}'s ${getPronouns(slave).daughter}`;
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTermShort(slave);
 						res += ` & ${friendShipShort}`;
 						handled = 1;
@@ -1381,10 +1381,10 @@ App.UI.SlaveSummaryImpl = function() {
 				res += `${V.missingTable[slave.mother].fullName}'s ${getPronouns(slave).daughter} `;
 			}
 			if (slave.father > 0 && slave.father !== slave.mother) {
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.father);
-				if (_ssj !== -1) {
-					res += `${SlaveFullName(V.slaves[_ssj])}'s ${getPronouns(slave).daughter}`;
-					if (slave.relationshipTarget === V.slaves[_ssj].ID && handled !== 1) {
+				const _ssj = V.slaves.find(s => s.ID === slave.father);
+				if (_ssj) {
+					res += `${SlaveFullName(_ssj)}'s ${getPronouns(slave).daughter}`;
+					if (slave.relationshipTarget === _ssj.ID && handled !== 1) {
 						const friendShipShort = relationshipTermShort(slave);
 						res += ` & ${friendShipShort}`;
 						handled = 1;
@@ -1402,20 +1402,10 @@ App.UI.SlaveSummaryImpl = function() {
 				res += `${V.missingTable[slave.father].fullName}'s ${getPronouns(slave).daughter}`;
 			}
 			if (slave.daughters === 1) {
-				let _ssj = V.slaves.findIndex(s => s.mother === slave.ID);
-				if (_ssj !== -1) {
-					res += `${SlaveFullName(V.slaves[_ssj])}'s mother`;
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
-						const friendShipShort = relationshipTermShort(slave);
-						res += ` & ${friendShipShort}`;
-						handled = 1;
-					}
-				}
-				res += " ";
-				_ssj = V.slaves.findIndex(s => s.father === slave.ID);
-				if (_ssj !== -1) {
-					res += `${SlaveFullName(V.slaves[_ssj])}'s father`;
-					if (slave.relationshipTarget === V.slaves[_ssj].ID && handled !== 1) {
+				const _ssj = V.slaves.find(s => s.mother === slave.ID || s.father === slave.ID);
+				if (_ssj) {
+					res += `${SlaveFullName(_ssj)}'s ${relativeTerm(_ssj, slave)}`;
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTermShort(slave);
 						res += ` & ${friendShipShort}`;
 						handled = 1;
@@ -1426,10 +1416,10 @@ App.UI.SlaveSummaryImpl = function() {
 				res += `multiple daughters `;
 			}
 			if (slave.sisters === 1) {
-				const _ssj = V.slaves.findIndex(s => areSisters(s, slave) > 0);
-				if (_ssj !== -1) {
-					res += `${SlaveFullName(V.slaves[_ssj])}'s ${getPronouns(slave).sister}`;
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
+				const _ssj = V.slaves.find(s => areSisters(s, slave) > 0);
+				if (_ssj) {
+					res += `${SlaveFullName(_ssj)}'s ${getPronouns(slave).sister}`;
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTermShort(slave);
 						res += `& ${friendShipShort}`;
 						handled = 1;
@@ -1440,9 +1430,9 @@ App.UI.SlaveSummaryImpl = function() {
 				res += `multiple sisters `;
 			}
 			if (slave.relationship > 0 && handled !== 1) {
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.relationshipTarget);
-				if (_ssj !== -1) {
-					res += `${SlaveFullName(V.slaves[_ssj])}'s`;
+				const _ssj = V.slaves.find(s => s.ID === slave.relationshipTarget);
+				if (_ssj) {
+					res += `${SlaveFullName(_ssj)}'s`;
 					const friendShipShort = relationshipTermShort(slave);
 					res += ` ${friendShipShort}`;
 				}
@@ -1475,14 +1465,14 @@ App.UI.SlaveSummaryImpl = function() {
 		function short_rival(slave, c) {
 			if (slave.rivalry !== 0) {
 				const block = makeBlock(c, "lightsalmon");
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.rivalryTarget);
-				if (_ssj !== -1) {
+				const _ssj = V.slaves.find(s => s.ID === slave.rivalryTarget);
+				if (_ssj) {
 					if (slave.rivalry <= 1) {
-						block.textContent = `Disl ${SlaveFullName(V.slaves[_ssj])}`;
+						block.textContent = `Disl ${SlaveFullName(_ssj)}`;
 					} else if (slave.rivalry <= 2) {
-						block.textContent = `${SlaveFullName(V.slaves[_ssj])}'s rival`;
+						block.textContent = `${SlaveFullName(_ssj)}'s rival`;
 					} else {
-						block.textContent = `Hates ${SlaveFullName(V.slaves[_ssj])}`;
+						block.textContent = `Hates ${SlaveFullName(_ssj)}`;
 					}
 				}
 			}
@@ -1497,11 +1487,11 @@ App.UI.SlaveSummaryImpl = function() {
 			let handled = 0;
 			const block = makeBlock();
 			if (slave.mother > 0) {
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.mother);
-				if (_ssj !== -1) {
-					addText(block, `${SlaveFullName(V.slaves[_ssj])}'s `);
+				const _ssj = V.slaves.find(s => s.ID === slave.mother);
+				if (_ssj) {
+					addText(block, `${SlaveFullName(_ssj)}'s `);
 					const tmpSpan = makeSpan(block, getPronouns(slave).daughter, "lightgreen");
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTerm(slave);
 						tmpSpan.textContent += ` and ${friendShipShort}`;
 						handled = 1;
@@ -1521,11 +1511,11 @@ App.UI.SlaveSummaryImpl = function() {
 				makeSpan(block, `${getPronouns(slave).daughter}.`, "lightgreen");
 			}
 			if (slave.father > 0 && slave.father !== slave.mother) {
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.father);
-				if (_ssj !== -1) {
-					addText(block, `${SlaveFullName(V.slaves[_ssj])}'s `);
+				const _ssj = V.slaves.find(s => s.ID === slave.father);
+				if (_ssj) {
+					addText(block, `${SlaveFullName(_ssj)}'s `);
 					const tmpSpan = makeSpan(block, getPronouns(slave).daughter, "lightgreen");
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTerm(slave);
 						tmpSpan.textContent += ` and ${friendShipShort}`;
 						handled = 1;
@@ -1554,22 +1544,11 @@ App.UI.SlaveSummaryImpl = function() {
 				}
 			}
 			if (slave.daughters === 1) {
-				let _ssj = V.slaves.findIndex(s => s.mother === slave.ID);
-				if (_ssj !== -1) {
-					addText(block, `${SlaveFullName(V.slaves[_ssj])}'s `);
-					const tmpSpan = makeSpan(block, "mother", "lightgreen");
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
-						const friendShipShort = relationshipTerm(slave);
-						tmpSpan.textContent += ` and ${friendShipShort}`;
-						handled = 1;
-					}
-					tmpSpan.textContent += '.';
-				}
-				_ssj = V.slaves.findIndex(s => s.father === slave.ID);
-				if (_ssj !== -1) {
-					addText(block, `${SlaveFullName(V.slaves[_ssj])}'s `);
-					const tmpSpan = makeSpan(block, "father", "lightgreen");
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
+				const _ssj = V.slaves.find(s => s.mother === slave.ID || s.father === slave.ID);
+				if (_ssj) {
+					addText(block, `${SlaveFullName(_ssj)}'s `);
+					const tmpSpan = makeSpan(block, relativeTerm(_ssj, slave), "lightgreen");
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTerm(slave);
 						tmpSpan.textContent += ` and ${friendShipShort}`;
 						handled = 1;
@@ -1586,11 +1565,11 @@ App.UI.SlaveSummaryImpl = function() {
 				}
 			}
 			if (slave.sisters === 1) {
-				const _ssj = V.slaves.findIndex(s => areSisters(s, slave) > 0);
-				if (_ssj !== -1) {
-					addText(block, `${SlaveFullName(V.slaves[_ssj])}'s `);
+				const _ssj = V.slaves.find(s => areSisters(s, slave) > 0);
+				if (_ssj) {
+					addText(block, `${SlaveFullName(_ssj)}'s `);
 					const tmpSpan = makeSpan(block, getPronouns(slave).sister, "lightgreen");
-					if (slave.relationshipTarget === V.slaves[_ssj].ID) {
+					if (slave.relationshipTarget === _ssj.ID) {
 						const friendShipShort = relationshipTerm(slave);
 						tmpSpan.textContent += ` and ${friendShipShort}`;
 						handled = 1;
@@ -1607,10 +1586,10 @@ App.UI.SlaveSummaryImpl = function() {
 				}
 			}
 			if (slave.relationship > 0 && handled !== 1) {
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.relationshipTarget);
-				if (_ssj !== -1) {
+				const _ssj = V.slaves.find(s => s.ID === slave.relationshipTarget);
+				if (_ssj) {
 					const friendship = relationshipTerm(slave);
-					addText(block, `${SlaveFullName(V.slaves[_ssj])}'s `);
+					addText(block, `${SlaveFullName(_ssj)}'s `);
 					makeSpan(block, `${friendship}.`, "lightgreen");
 				}
 			} else if (slave.relationship === -3 && slave.mother !== -1 && slave.father !== -1 && areSisters(V.PC, slave) === 0) {
@@ -1645,17 +1624,17 @@ App.UI.SlaveSummaryImpl = function() {
 		function long_rival(slave, c) {
 			if (slave.rivalry !== 0) {
 				const block = makeBlock(c);
-				const _ssj = V.slaves.findIndex(s => s.ID === slave.rivalryTarget);
-				if (_ssj !== -1) {
+				const _ssj = V.slaves.find(s => s.ID === slave.rivalryTarget);
+				if (_ssj) {
 					if (slave.rivalry <= 1) {
 						makeSpan(block, "Dislikes", "lightsalmon");
-						block.appendChild(document.createTextNode(` ${SlaveFullName(V.slaves[_ssj])}.`));
+						block.appendChild(document.createTextNode(` ${SlaveFullName(_ssj)}.`));
 					} else if (slave.rivalry <= 2) {
-						block.appendChild(document.createTextNode(`${SlaveFullName(V.slaves[_ssj])}'s `));
+						block.appendChild(document.createTextNode(`${SlaveFullName(_ssj)}'s `));
 						makeSpan(block, "rival.", "lightsalmon");
 					} else {
 						makeSpan(block, "Hates", "lightsalmon");
-						block.appendChild(document.createTextNode(` ${SlaveFullName(V.slaves[_ssj])}.`));
+						block.appendChild(document.createTextNode(` ${SlaveFullName(_ssj)}.`));
 					}
 				}
 			}
-- 
GitLab