From cc154eadbdaac89090e4592e6ccad5c79286535b Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Sun, 16 Feb 2020 16:55:39 -0500
Subject: [PATCH] start

---
 src/js/slaveInteract.js            | 81 +++++++++++++++++++++++++++---
 src/uncategorized/slaveInteract.tw |  2 +
 2 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/src/js/slaveInteract.js b/src/js/slaveInteract.js
index e305dc8789e..fbc7b3542d8 100644
--- a/src/js/slaveInteract.js
+++ b/src/js/slaveInteract.js
@@ -4,31 +4,100 @@ App.UI.SlaveInteract = {
 		/** @type {App.Entity.SlaveState} */
 		const slave = State.variables.activeSlave;
 		const {his} = getPronouns(slave);
+		el = document.createElement('div');
+
 		if ((slave.assignment === "please you") || (slave.assignment === "serve in the master suite") || (slave.assignment === "be your Concubine")) {
-			res += `<span class="story-label">Fucktoy use preference:</span> <span id = "hole" style="font-weight:bold">${slave.toyHole}.</span> `;
+			let storyLabel  = document.createElement('span');
+			storyLabel.className = "story-label";
+			storyLabel.textContent = `Fucktoy use preference: `;
+			el.appendChild(storyLabel);
+
+			let hole  = document.createElement('span');
+			hole.style.fontWeight = "bold";
+			hole.textContent = `${slave.toyHole}. `;
+			el.appendChild(hole);
+
 			/** @type {string[]} */
 			let links = [];
 			links.push('<<link "Mouth">><<set $activeSlave.toyHole = "mouth">><<replace "#hole">>$activeSlave.toyHole<</replace>><</link>>');
 			links.push('<<link "Tits">><<set $activeSlave.toyHole = "boobs">><<replace "#hole">>$activeSlave.toyHole<</replace>><</link>>');
 			if ((slave.vagina > 0) && canDoVaginal(slave)) {
 				links.push('<<link "Pussy">><<set $activeSlave.toyHole = "pussy">><<replace "#hole">>$activeSlave.toyHole<</replace>><</link>>');
+				links.push({text: ``, toyHole: ``});
 			} else if (slave.vagina === 0) {
 				links.push(App.UI.disabledLink("Pussy",
 					[`Take ${his} virginity before giving ${his} pussy special attention`]));
+					links.push({text: ``, toyHole: ``});
 			}
 			if ((slave.anus > 0) && canDoAnal(slave)) {
 				links.push('<<link "Ass">><<set $activeSlave.toyHole = "ass">><<replace "#hole">>$activeSlave.toyHole<</replace>><</link>>');
+				links.push({text: ``, toyHole: ``});
 			} else {
 				links.push(App.UI.disabledLink("Ass",
-					[`Take ${his} anal virginity before giving ${his} ass special attention`]));
+					links.push({text: `Take ${his} anal virginity before giving ${his} ass special attention`});
 			}
 			if ((slave.dick > 0) && canPenetrate(slave)) {
-				links.push('<<link "Dick">><<set $activeSlave.toyHole = "dick">><<replace "#hole">>$activeSlave.toyHole<</replace>><</link>>');
+				links.push({text: `Dick`, toyHole: `dick`});
+			}
+			links.push({text: `No Preference`, toyHole: `all ${his} holes`});
+		}
+		el.appendChild(generateRows(links));
+
+		function generateRows(toyHoleArray) {
+			let row = document.createDocumentFragment();
+			for (let i = 0; i < toyHoleArray.length; i++) {
+				let link;
+				const separator  = document.createTextNode(` | `);
+				const keys = Object.keys(toyHoleArray[i]);
+	
+				// Test to see if there was a problem with the key
+				for (let j = 0; j < keys.length; j++) {
+					if (["text", "toyHole"].includes(keys[j])) {
+						continue;
+					} else {
+						toyHoleArray[i].text += " ERROR, THIS SCENE WAS NOT ENTERED CORRECTLY";
+						console.log("Trash found while generateRows() was running: " + keys[j] + ": " + toyHoleArray[i][keys[j]]);
+						break;
+					}
+				}
+	
+				// is it just text?
+				if (keys.length === 1) {
+					if (toyHoleArray[i].text) {
+						link = document.createTextNode(toyHoleArray[i].text);
+					} else {
+						console.log(`expected 'text' only, got: ${toyHoleArray[i]}`);
+						link = document.createTextNode("error, text not found");
+					}
+				// Are they already on this toyHole?
+				} else if (toyHoleArray[i].toyHole === slave.toyHole) {
+					link = document.createTextNode(toyHoleArray[i].text);
+				// Set up the link
+				} else {
+					link = App.UI.DOM.link(
+						toyHoleArray[i].text,
+						() => {
+							slave.toyHole = toyHoleArray[i].toyHole,
+							App.UI.SlaveInteract.fucktoyPref(slave);
+						},
+					);
+	
+					// add a note node if required
+					if (toyHoleArray[i].note) {
+						let note  = document.createTextNode(toyHoleArray[i].note);
+						note.className = "note";
+						link.appendChild(note);
+					}
+				}
+				row.appendChild(link);
+				if (i < toyHoleArray.length-1) {
+					row.appendChild(separator);
+				}
 			}
-			links.push(`<<link "No Preference">><<set $activeSlave.toyHole = "all ${his} holes">><<replace "#hole">>$activeSlave.toyHole<</replace>><</link>>`);
-			res += links.join('&thinsp;|&thinsp;') + '<br>';
+	
+			return row;
 		}
-		App.UI.replace('#fucktoypref', res);
+		return jQuery('#hole').empty().append(el);
 	},
 
 	assignmentBlock: function(blockId) {
diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw
index 001f3e386ba..a2b752cad57 100644
--- a/src/uncategorized/slaveInteract.tw
+++ b/src/uncategorized/slaveInteract.tw
@@ -194,6 +194,8 @@
 	<<if $assignmentRecords[$activeSlave.ID] && $assignmentRecords[$activeSlave.ID] != $activeSlave.assignment>>
 		Previously: <<print $assignmentRecords[$activeSlave.ID]>>
 	<</if>>
+	<div id="hole"></div>
+	<script>App.UI.SlaveInteract.fucktoyPref(V.activeSlave)</script>
 	<span id="assignmentLinks"><<= App.UI.SlaveInteract.assignmentBlock("assignmentLinks")>></span>
 
 	<<set _numFacilities = $brothel+$club+$dairy+$farmyard+$servantsQuarters+$masterSuite+$spa+$nursery+$clinic+$schoolroom+$cellblock+$arcade+$HGSuite>>
-- 
GitLab