diff --git a/src/interaction/siWardrobe.js b/src/interaction/siWardrobe.js index 11659c0b6c4f20934017d168b00c382342b1f0bb..56d6db6a332ddb568f55015b6367c34eda9773f6 100644 --- a/src/interaction/siWardrobe.js +++ b/src/interaction/siWardrobe.js @@ -42,7 +42,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.clothes !== `choosing her own clothes`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` Let ${him} choose`, updateSlave: {clothes: `choosing her own clothes`, choosesOwnClothes: 1}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "clothes", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "clothes", false, refresh)); } el.appendChild(label); @@ -85,14 +85,14 @@ App.UI.SlaveInteract.wardrobe = function(slave) { links = document.createElement('div'); links.className = "choices"; links.append(`Nice: `); - links.appendChild(App.UI.SlaveInteract.generateRows(niceOptionsArray, slave, "clothes", true, refresh)); + links.appendChild(generateRows(niceOptionsArray, slave, "clothes", true, refresh)); el.appendChild(links); // Harsh options links = document.createElement('div'); links.className = "choices"; links.append(`Harsh: `); - links.appendChild(App.UI.SlaveInteract.generateRows(harshOptionsArray, slave, "clothes", true, refresh)); + links.appendChild(generateRows(harshOptionsArray, slave, "clothes", true, refresh)); el.appendChild(links); } if (slave.fuckdoll !== 0 || slave.clothes === "restrictive latex" || slave.clothes === "a latex catsuit" || slave.clothes === "a cybersuit" || slave.clothes === "a comfortable bodysuit") { @@ -123,7 +123,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.collar !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {collar: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "collar", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "collar", false, refresh)); } el.appendChild(label); @@ -159,14 +159,14 @@ App.UI.SlaveInteract.wardrobe = function(slave) { let links = document.createElement('div'); links.className = "choices"; links.append(`Nice: `); - links.appendChild(App.UI.SlaveInteract.generateRows(niceOptionsArray, slave, "collar", true, refresh)); + links.appendChild(generateRows(niceOptionsArray, slave, "collar", true, refresh)); el.appendChild(links); // Harsh options links = document.createElement('div'); links.className = "choices"; links.append(`Harsh: `); - links.appendChild(App.UI.SlaveInteract.generateRows(harshOptionsArray, slave, "collar", true, refresh)); + links.appendChild(generateRows(harshOptionsArray, slave, "collar", true, refresh)); el.appendChild(links); return el; @@ -186,7 +186,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.faceAccessory !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {faceAccessory: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "faceAccessory", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "faceAccessory", false, refresh)); } el.appendChild(label); @@ -208,7 +208,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(array, slave, "faceAccessory", true, refresh)); + links.appendChild(generateRows(array, slave, "faceAccessory", true, refresh)); el.appendChild(links); if (slave.eyewear === "corrective glasses" || slave.eyewear === "glasses" || slave.eyewear === "blurring glasses" || slave.faceAccessory === "porcelain mask") { @@ -241,7 +241,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.mouthAccessory !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {mouthAccessory: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "mouthAccessory", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "mouthAccessory", false, refresh)); } el.appendChild(label); @@ -264,7 +264,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(array, slave, "mouthAccessory", true, refresh)); + links.appendChild(generateRows(array, slave, "mouthAccessory", true, refresh)); el.appendChild(links); return el; @@ -286,7 +286,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Choose her own if (slave.armAccessory !== "none") { array.push({text: ` None`, updateSlave: {armAccessory: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(array, slave, "armAccessory", false, refresh)); + label.appendChild(generateRows(array, slave, "armAccessory", false, refresh)); } el.appendChild(label); @@ -297,7 +297,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { {text: "Hand gloves", updateSlave: {armAccessory: "hand gloves"}}, {text: "Elbow gloves", updateSlave: {armAccessory: "elbow gloves"}} ]; - links.appendChild(App.UI.SlaveInteract.generateRows(array, slave, "armAccessory", false, refresh)); + links.appendChild(generateRows(array, slave, "armAccessory", false, refresh)); el.appendChild(links); return el; @@ -318,7 +318,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.shoes !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: `None`, updateSlave: {shoes: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "shoes", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "shoes", false, refresh)); } */ el.appendChild(label); @@ -341,7 +341,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "shoes", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "shoes", true, refresh)); el.appendChild(links); if (V.seeImages === 1 && V.imageChoice === 1 && slave.shoes !== "none") { @@ -371,7 +371,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Choose her own if (slave.legAccessory !== "none") { array.push({text: ` None`, updateSlave: {legAccessory: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(array, slave, "legAccessory", false, refresh)); + label.appendChild(generateRows(array, slave, "legAccessory", false, refresh)); } el.appendChild(label); @@ -382,7 +382,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { {text: "Short stockings", updateSlave: {legAccessory: "short stockings"}}, {text: "Long stockings", updateSlave: {legAccessory: "long stockings"}} ]; - links.appendChild(App.UI.SlaveInteract.generateRows(array, slave, "legAccessory", false, refresh)); + links.appendChild(generateRows(array, slave, "legAccessory", false, refresh)); el.appendChild(links); return el; @@ -420,7 +420,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Choose her own if (slave.bellyAccessory !== `none`) { - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "bellyAccessory", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "bellyAccessory", false, refresh)); } el.appendChild(label); @@ -428,7 +428,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "bellyAccessory", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "bellyAccessory", true, refresh)); if (slave.pregKnown === 1) { let note = document.createElement('span'); note.className = "note"; @@ -454,7 +454,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.buttplug !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {buttplug: `none`, buttplugAttachment: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "buttplug", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "buttplug", false, refresh)); } el.appendChild(label); @@ -479,7 +479,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "buttplug", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "buttplug", true, refresh)); el.appendChild(links); return el; @@ -501,7 +501,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.buttplugAttachment !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {buttplugAttachment: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "buttplugAttachment", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "buttplugAttachment", false, refresh)); } el.appendChild(label); @@ -526,7 +526,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "buttplugAttachment", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "buttplugAttachment", true, refresh)); el.appendChild(links); return el; @@ -547,7 +547,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.vaginalAccessory !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {vaginalAccessory: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "vaginalAccessory", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "vaginalAccessory", false, refresh)); } el.appendChild(label); @@ -572,7 +572,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "vaginalAccessory", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "vaginalAccessory", true, refresh)); el.appendChild(links); return el; @@ -594,7 +594,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.vaginalAttachment !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {vaginalAttachment: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "vaginalAttachment", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "vaginalAttachment", false, refresh)); } el.appendChild(label); @@ -619,7 +619,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "vaginalAttachment", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "vaginalAttachment", true, refresh)); el.appendChild(links); return el; @@ -638,7 +638,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { if (slave.dickAccessory !== `none`) { let choiceOptionsArray = []; choiceOptionsArray.push({text: ` None`, updateSlave: {dickAccessory: `none`}}); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "dickAccessory", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "dickAccessory", false, refresh)); } el.appendChild(label); @@ -663,7 +663,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "dickAccessory", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "dickAccessory", true, refresh)); el.appendChild(links); return el; @@ -713,7 +713,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { chastityVagina: 0 } }); - label.appendChild(App.UI.SlaveInteract.generateRows(choiceOptionsArray, slave, "chastity", false, refresh)); + label.appendChild(generateRows(choiceOptionsArray, slave, "chastity", false, refresh)); } el.appendChild(label); @@ -739,7 +739,7 @@ App.UI.SlaveInteract.wardrobe = function(slave) { // Options let links = document.createElement('div'); links.className = "choices"; - links.appendChild(App.UI.SlaveInteract.generateRows(optionsArray, slave, "chastity", true, refresh)); + links.appendChild(generateRows(optionsArray, slave, "chastity", true, refresh)); el.appendChild(links); return el; @@ -975,4 +975,81 @@ App.UI.SlaveInteract.wardrobe = function(slave) { } } } + /** @typedef RowItem + * @type {object} + * @property {FC.FutureSociety} [FS] - FS requirement, if any + * @property {string} [text] - link text + * @property {object} [updateSlave] - properties to be merged onto the slave + * @property {object} [update] - properties to be merged into global state + * @property {string} [disabled] - text indicating why the option is unavailable + * @property {string} [note] + * @property {string} [slutty] + * @property {string} [humiliating] + */ + + /** Generate a row of choices + * @param {RowItem[]} array + * @param {App.Entity.SlaveState} slave + * @param {string} [category] - should be in the form of slave.category, the thing we want to update. + * @param {boolean} [accessCheck=false] + * @param {Function} refresh + * @returns {HTMLSpanElement} + */ + function generateRows(array, slave, category, accessCheck = false, refresh) { + const linkArray = []; + for (const item of array) { + let link; + // Some items will never be in App.Data.slaveWear, especially "none" if it falls in between harsh and nice data sets. Trying to look it up would cause an error, which is what access check works around. + const itemName = (category === "chastity") ? item.text.toLowerCase() : item.updateSlave[category]; // Yucky. Category name does not match for chastity (since it sets multiple kinds of chastity at once). Compare using a lowercase name instead. + const unlocked = (accessCheck === true) ? isItemAccessible.entry(itemName, category, slave) : false; + if (accessCheck === false || unlocked) { + // is it just text? + if (item.disabled) { + link = App.UI.DOM.disabledLink(item.text, [item.disabled]); + } else if (typeof unlocked === 'string') { + link = App.UI.DOM.disabledLink(item.text, [unlocked]); + } else { + link = document.createElement('span'); + + // Set up the link + link.appendChild( + App.UI.DOM.link( + `${item.text} `, + () => { click(item); }, + [], + "", + clothTooltip(itemName) + ) + ); + + if (item.FS) { + let FS = App.UI.DOM.disabledLink(`FS`, [FutureSocieties.displayAdj(item.FS)]); + FS.style.fontStyle = "italic"; + link.appendChild(FS); + } + + // add a note node if required + if (item.note) { + link.appendChild(App.UI.DOM.makeElement('span', ` ${item.note}`, 'note')); + } + } + linkArray.push(link); + } + } + + return App.UI.DOM.generateLinksStrip(linkArray); + + /** @param {RowItem} arrayOption */ + function click(arrayOption) { + if (arrayOption.updateSlave) { + for (const slaveProperty in arrayOption.updateSlave) { + _.set(slave, slaveProperty, arrayOption.updateSlave[slaveProperty]); + } + } + if (arrayOption.update) { + Object.assign(V, arrayOption.update); + } + refresh(); + } + } };