From 9d5a838f022eb7ed4c0a00b3ef1c9b9350c97b73 Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Mon, 17 Feb 2020 23:24:11 -0500
Subject: [PATCH] shoes

---
 src/js/itemAvailability.js         |   6 +-
 src/js/wardrobeUse.js              | 128 +++++++++++++++++++++++++++++
 src/uncategorized/slaveInteract.tw |   3 +
 3 files changed, 135 insertions(+), 2 deletions(-)

diff --git a/src/js/itemAvailability.js b/src/js/itemAvailability.js
index 9053b3884c4..eb2139a7328 100644
--- a/src/js/itemAvailability.js
+++ b/src/js/itemAvailability.js
@@ -223,13 +223,15 @@ window.isClothingAccessible = (function() {
 		} else if (category === "collar") {
 			niceDB = App.Data.misc.niceCollars;
 			harshDB = App.Data.misc.harshCollars;
+		} else {
+			niceDB = App.Data.misc[category];
 		}
 		let item = niceDB.find((i) => i.value === string);
-		if (!item) {
+		if (!item && typeof harshDB !== undefined) {
 			item = harshDB.find((i) => i.value === string);
 		}
 		if (!item) {
-			console.log(`${string} is not a registered piece of clothing! Check App.Data.Misc.`);
+			console.log(`${string} is not a registered piece of clothing! Check App.Data.Misc.${category}`);
 			return false; /* couldn't be found */
 		}
 		return isAvailable(item);
diff --git a/src/js/wardrobeUse.js b/src/js/wardrobeUse.js
index af36556a720..99ee1e71b29 100644
--- a/src/js/wardrobeUse.js
+++ b/src/js/wardrobeUse.js
@@ -415,10 +415,138 @@ App.UI.Wardrobe.armAccessory = function(slave) {
 	}
 };
 
+App.UI.Wardrobe.shoes = function(slave) {
+	if (slave.fuckdoll !== 0) {
+		return;
+	}
+
+	const
+		{
+			// eslint-disable-next-line no-unused-vars
+			he, him, his, hers, himself, boy, He, His
+		} = getPronouns(slave);
+
+	let choiceOptionsArray= [];
+	choiceOptionsArray.push({text: `None`, updateSlave: {shoes: `none`}});
+
+	let optionsArray= [];
+
+	let clothingOption;
+	App.Data.misc.shoes.forEach(item => {
+		clothingOption = {
+			text: item.name,
+			updateSlave: {shoes: item.value}
+		};
+		if (item.fs) {
+			clothingOption.FS = item.fs;
+		}
+		optionsArray.push(clothingOption);
+	});
+
+	// Sort
+	optionsArray = optionsArray.sort((a, b) => (a.text > b.text) ? 1 : -1);
+
+	let el = document.createElement('div');
+
+	let label = document.createElement('div');
+	label.append(`Shoes: `);
+
+	let choice = document.createElement('span');
+	choice.style.fontWeight = "bold";
+	choice.textContent = (`${slave.shoes} `);
+	label.appendChild(choice);
+
+	// Choose her own
+	label.appendChild(generateRows(choiceOptionsArray));
+
+	el.appendChild(label);
+
+
+	// Options
+	let links = document.createElement('div');
+	links.className = "choices";
+	links.appendChild(generateRows(optionsArray));
+	el.appendChild(links);
+
+	return jQuery('#shoes').empty().append(el);
+
+
+	function generateRows(array) {
+		let row = document.createElement('span');
+		for (let i = 0; i < array.length; i++) {
+			let link;
+			const separator  = document.createTextNode(` | `);
+			const keys = Object.keys(array[i]);
+
+			// Test to see if there was a problem with the key
+			for (let j = 0; j < keys.length; j++) {
+				if (["FS", "text", "updateSlave", "update", "note", "disabled"].includes(keys[j])) {
+					continue;
+				} else {
+					array[i].text += " ERROR, THIS SCENE WAS NOT ENTERED CORRECTLY";
+					console.log("Trash found while generateRows() was running: " + keys[j] + ": " + array[i][keys[j]]);
+					break;
+				}
+			}
+			if (array[i].updateSlave.shoes === `none` || isClothingAccessible.entry(array[i].updateSlave.shoes, "shoes")) {
+				// is it just text?
+				if (array[i].disabled) {
+					link = App.UI.DOM.disabledLink(array[i].text, [array[i].disabled]);
+				} else {
+					link = document.createElement('span');
+
+					// Set up the link
+					link.appendChild(
+						App.UI.DOM.link(
+							`${array[i].text} `,
+							() => { click(array[i]); },
+						)
+					);
+
+					if (array[i].FS) {
+						let FS = array[i].FS.substring(2); // Given "FSEdoRevivalist", cut off the first two letters to start a user friendly tooltip
+						FS = FS.replace(/([A-Z])/g, ` $1`); // Given "EdoRevivalist", find every capital letter and put a space in front of it
+						FS = App.UI.DOM.disabledLink(`FS`, [FS]); // Tooltip should read "Edo Revivalist"
+						FS.style.fontStyle = "italic";
+						link.appendChild(FS);
+					}
+
+					// add a note node if required
+					if (array[i].note) {
+						let note  = document.createElement('span');
+						note.textContent = (` ${array[i].note}`);
+						note.className = "note";
+						link.appendChild(note);
+					}
+				}
+				row.appendChild(link);
+				if (i < array.length-1) {
+					row.appendChild(separator);
+				}
+			}
+		}
+
+		return row;
+
+		function click(arrayOption) {
+			if (arrayOption.updateSlave) {
+				Object.assign(slave, arrayOption.updateSlave);
+			}
+			if (arrayOption.update) {
+				Object.assign(V, arrayOption.update);
+			}
+			App.UI.Wardrobe.refreshAll(slave);
+			return;
+		}
+	}
+};
+
+
 App.UI.Wardrobe.refreshAll = function(slave) {
 	App.UI.Wardrobe.clothes(slave);
 	App.UI.Wardrobe.collar(slave);
 	App.UI.Wardrobe.armAccessory(slave);
+	App.UI.Wardrobe.shoes(slave);
 	return;
 };
 
diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw
index e28c00e5f14..962dbaf94fb 100644
--- a/src/uncategorized/slaveInteract.tw
+++ b/src/uncategorized/slaveInteract.tw
@@ -205,6 +205,9 @@
 	<span id="armAccessory"></span>
 	<script>App.UI.Wardrobe.armAccessory(V.activeSlave)</script>
 
+	<span id="shoes"></span>
+	<script>App.UI.Wardrobe.shoes(V.activeSlave)</script>
+
 
 	<<if hasAnyLegs($activeSlave)>>
 		<br>Shoes: ''<span id="shoes">$activeSlave.shoes</span>.''
-- 
GitLab