From 2e4057d1e2d4e505b6d5b9455f2e08bbcb632165 Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Tue, 18 Feb 2020 14:21:07 -0500
Subject: [PATCH] Anal accessory attachment

---
 js/003-data/miscData.js            |   8 +--
 src/js/itemAvailability.js         |  12 +++-
 src/js/rulesAssistantOptions.js    |   2 +-
 src/js/wardrobeUse.js              | 100 +++++++++++++++++++++++------
 src/uncategorized/slaveInteract.tw |  11 +---
 5 files changed, 100 insertions(+), 33 deletions(-)

diff --git a/js/003-data/miscData.js b/js/003-data/miscData.js
index 5d4cc6c74d2..fdff05b911f 100644
--- a/js/003-data/miscData.js
+++ b/js/003-data/miscData.js
@@ -2251,10 +2251,10 @@ App.Data.misc = {
 
 	buttplugAttachments: [
 		{name: "None", value: "none"},
-		{name: "Tail", value: "tail", rs: "buyTails"},
-		{name: "Fox tail", value: "fox tail", rs: "buyTails"},
-		{name: "Cat tail", value: "cat tail", rs: "buyTails"},
-		{name: "Cow tail", value: "cow tail", rs: "buyTails"}
+		{name: "Tail", value: "tail", rs: "toysBoughtButtPlugTails"},
+		{name: "Fox tail", value: "fox tail", rs: "toysBoughtButtPlugTails"},
+		{name: "Cat tail", value: "cat tail", rs: "toysBoughtButtPlugTails"},
+		{name: "Cow tail", value: "cow tail", rs: "toysBoughtButtPlugTails"}
 	],
 
 	facilityCareers: ["be confined in the arcade", "be confined in the cellblock", "be the Attendant", "be the DJ", "be the Farmer", "be the Madam", "be the Matron", "be the Milkmaid", "be the Nurse", "be the Schoolteacher", "be the Stewardess", "be the Wardeness", "be your Concubine", "get treatment in the clinic", "learn in the schoolroom", "live with your Head Girl", "rest in the spa", "serve in the club", "serve in the master suite", "work as a farmhand", "work as a nanny", "work as a servant", "work in the brothel", "work in the dairy"],
diff --git a/src/js/itemAvailability.js b/src/js/itemAvailability.js
index fbf2b6f2c7d..56c38c033f3 100644
--- a/src/js/itemAvailability.js
+++ b/src/js/itemAvailability.js
@@ -227,11 +227,21 @@ window.isClothingAccessible = (function() {
 			niceDB = App.Data.misc.bellyAccessories;
 		} else if (category === "buttplug") {
 			niceDB = App.Data.misc.buttplugs;
+		} else if (category === "buttplugAttachment") {
+			niceDB = App.Data.misc.buttplugAttachments;
+		} else if (category === "vaginalAccessory") {
+			niceDB = App.Data.misc.vaginalAccessories;
+		} else if (category === "vaginalAttachment") {
+			niceDB = App.Data.misc.vaginalAttachments;
+		} else if (category === "dickAccessory") {
+			niceDB = App.Data.misc.vaginalAccessories;
+		//} else if (category === "chastity") {
+		//	niceDB = App.Data.misc.vaginalAccessories; //this is going to be weird, they aren't in App.Data.Misc
 		} else {
 			niceDB = App.Data.misc[category];
 		}
 		let item = niceDB.find((i) => i.value === string);
-		if (!item && typeof harshDB !== undefined) {
+		if (!item && (typeof harshDB !== 'undefined')) {
 			item = harshDB.find((i) => i.value === string);
 		}
 		if (!item) {
diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js
index f0d5b32d9db..7a3414cfad7 100644
--- a/src/js/rulesAssistantOptions.js
+++ b/src/js/rulesAssistantOptions.js
@@ -2005,7 +2005,7 @@ window.rulesAssistantOptions = (function() {
 			setup.buttplugAttachments.forEach(acc => {
 				if (acc.fs === undefined && acc.rs === undefined) {
 					accs.push([acc.name, acc.value]);
-				} else if (acc.rs === "buyTails" && V.toysBoughtButtPlugTails === 1) {
+				} else if (acc.rs === "toysBoughtButtPlugTails" && V.toysBoughtButtPlugTails === 1) {
 					accs.push([`${acc.name} (Purchased)`, acc.value]);
 				}
 			});
diff --git a/src/js/wardrobeUse.js b/src/js/wardrobeUse.js
index c1f2b0f909f..2d5b6a91c57 100644
--- a/src/js/wardrobeUse.js
+++ b/src/js/wardrobeUse.js
@@ -430,6 +430,87 @@ App.UI.Wardrobe.buttplug = function(slave) {
 	return jQuery('#buttplug').empty().append(el);
 };
 
+App.UI.Wardrobe.buttplugAttachment = function(slave) {
+	if (slave.fuckdoll !== 0) {
+		return;
+	} else if (slave.buttplug === "none") {
+		return jQuery('#buttplugAttachment').empty();
+	}
+
+	const
+		{
+			// eslint-disable-next-line no-unused-vars
+			he, him, his, hers, himself, boy, He, His
+		} = getPronouns(slave);
+
+	let el = document.createElement('div');
+
+	let label = document.createElement('div');
+	label.append(`Anal accessory attachment: `);
+
+	let choice = document.createElement('span');
+	choice.style.fontWeight = "bold";
+	choice.textContent = (`${slave.buttplugAttachment} `);
+	label.appendChild(choice);
+
+	if (slave.buttplugAttachment !== `none`) {
+		let choiceOptionsArray = [];
+		choiceOptionsArray.push({text: `None`, updateSlave: {buttplugAttachment: `none`}});
+		label.appendChild(App.UI.Wardrobe.generateRows(choiceOptionsArray, "buttplugAttachment", slave, true));
+	}
+	el.appendChild(label);
+
+	let optionsArray = [];
+
+	let clothingOption;
+	App.Data.misc.buttplugAttachments.forEach(item => {
+		clothingOption = {
+			text: item.name,
+			updateSlave: {buttplugAttachment: item.value}
+		};
+		if (item.fs) {
+			clothingOption.FS = item.fs;
+		}
+
+		if (item.value === "huge plug") {
+			if (slave.anus < 2) {
+				clothingOption.disabled = `Slave's anus is too small for this right now`;
+			}
+		} else if (item.value === "long plug") {
+			if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
+				clothingOption.disabled = "Elites frown on this";
+			}
+		} else if (item.value === "long, large plug") {
+			if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
+				clothingOption.disabled = "Elites frown on this";
+			}
+		} else if (item.value === "long, huge plug") {
+			if (slave.anus < 2) {
+				clothingOption.disabled = `Slave's anus is too small for this right now`;
+			}
+			if (!(slave.breedingMark !== 1 || V.propOutcome === 0 || V.eugenicsFullControl === 1 || V.arcologies[0].FSRestart === "unset")) {
+				clothingOption.disabled = "Elites frown on this";
+			}
+		}
+		if (item.value !== "none") {
+			// skip none in set, we set the link elsewhere.
+			optionsArray.push(clothingOption);
+		}
+	});
+
+	// Sort
+	optionsArray = optionsArray.sort((a, b) => (a.text > b.text) ? 1 : -1);
+
+	// Options
+	let links = document.createElement('div');
+	links.className = "choices";
+	links.appendChild(App.UI.Wardrobe.generateRows(optionsArray, "buttplugAttachment", slave));
+	el.appendChild(links);
+
+	return jQuery('#buttplugAttachment').empty().append(el);
+};
+
+
 App.UI.Wardrobe.generateRows = function(array, category, slave, ignoreAccessCheck="false") { // category should be in the form of slave.category, the thing we want to update.
 	let row = document.createElement('span');
 	for (let i = 0; i < array.length; i++) {
@@ -507,28 +588,11 @@ App.UI.Wardrobe.refreshAll = function(slave) {
 	App.UI.Wardrobe.legAccessory(slave);
 	App.UI.Wardrobe.bellyAccessory(slave);
 	App.UI.Wardrobe.buttplug(slave);
+	App.UI.Wardrobe.buttplugAttachment(slave);
 	return;
 };
 
 /*
-	<br>Anal accessory: ''<span id="buttplug">slave.buttplug</span>.''
-	<<link "None">>slave.buttplug = "none", slave.buttplugAttachment = "none";<</link>>
-	<<link "Normal">>slave.buttplug = "plug";<</link>>
-
-		<<link "Long">>slave.buttplug = "long plug";<</link>>
-	}
-	<<link "Large">>slave.buttplug = "large plug";<</link>>
-
-		<<link "Long and large">>slave.buttplug = "long, large plug";<</link>>
-	}
-	if (slave.anus >= 2) {
-		<<link "Huge">>slave.buttplug = "huge plug";<</link>>
-
-			if ((slave.breedingMark !== 1 |V.propOutcome === 0 |V.eugenicsFullControl === 1 |V.arcologies[0].FSRestart === "unset")) {
-				<<link "Long and huge">>slave.buttplug = "long, huge plug";<</link>>
-			}
-		}
-	}
 	if (isItemAccessible("tail") && slave.buttplug !== "none") {
 		<br>
 		&nbsp;&nbsp;&nbsp;&nbsp;Anal accessory attachment: ''<span id="buttplugAttach">slave.buttplugAttachment</span>.''
diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw
index 3d375fdf354..c451a7d7d37 100644
--- a/src/uncategorized/slaveInteract.tw
+++ b/src/uncategorized/slaveInteract.tw
@@ -220,15 +220,8 @@
 	<script>App.UI.Wardrobe.buttplug(V.activeSlave)</script>
 
 	<<if isItemAccessible("tail") && $activeSlave.buttplug != "none">>
-		<br>
-		&nbsp;&nbsp;&nbsp;&nbsp;Anal accessory attachment: ''<span id="buttplugAttach">$activeSlave.buttplugAttachment</span>.''
-		<<link "None">><<set $activeSlave.buttplugAttachment = "none">><<replace "#buttplugAttach">>$activeSlave.buttplugAttachment<</replace>><</link>>
-		<<if $toysBoughtButtPlugTails == 1>>
-			| <<link "Tail">><<set $activeSlave.buttplugAttachment = "tail">><<replace "#buttplugAttach">>$activeSlave.buttplugAttachment<</replace>><</link>>
-			| <<link "Cat tail">><<set $activeSlave.buttplugAttachment = "cat tail">><<replace "#buttplugAttach">>$activeSlave.buttplugAttachment<</replace>><</link>>
-			| <<link "Fox tail">><<set $activeSlave.buttplugAttachment = "fox tail">><<replace "#buttplugAttach">>$activeSlave.buttplugAttachment<</replace>><</link>>
-			| <<link "Cow tail">><<set $activeSlave.buttplugAttachment = "cow tail">><<replace "#buttplugAttach">>$activeSlave.buttplugAttachment<</replace>><</link>>
-		<</if>>
+		<span id="buttplugAttachment"></span>
+		<script>App.UI.Wardrobe.buttplugAttachment(V.activeSlave)</script>
 	<</if>>
 
 	<<if $activeSlave.vagina > -1>>
-- 
GitLab