From b91dea1454a01a35bd42f2308c608b5e7c1d5199 Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Fri, 7 May 2021 20:50:34 -0400 Subject: [PATCH] now working with new data structure --- .../bodyModification/bodyModification.js | 38 +++++++++++-------- src/js/utilsSlave.js | 11 ------ 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/facilities/bodyModification/bodyModification.js b/src/facilities/bodyModification/bodyModification.js index 80c5483420e..9b729f790ad 100644 --- a/src/facilities/bodyModification/bodyModification.js +++ b/src/facilities/bodyModification/bodyModification.js @@ -884,7 +884,7 @@ App.UI.bodyModification = function(slave, cheat = false) { r = []; if (["exotic", "menacing"].includes(V.scarDesign.local) && !V.scarTarget.local.endsWith("cheek")) { r.push(`"${capFirstChar(V.scarDesign.local)}" scars can only be applied to cheeks.`); - } else if (findBodyPart(V.scarTarget.local).isPair) { + } else if (App.Data.Slave.body.get(App.UI.bodyPartRoot(V.scarTarget.local)).isPair) { r.push(`Choose a side to scar.`); } else { if (slave.scar.hasOwnProperty(V.scarTarget.local)) { @@ -996,7 +996,7 @@ App.UI.bodyModification = function(slave, cheat = false) { if (slave.brand[V.brandTarget.local] === V.brandDesign.local) { p.append(`${He} already has ${V.brandDesign.local} on ${his} ${V.brandTarget.local}.`); - } else if (findBodyPart(V.brandTarget.local).isPair) { + } else if (App.Data.Slave.body.get(App.UI.bodyPartRoot(V.brandTarget.local)).isPair) { p.append(`Choose a side to brand.`); } else { p.append( @@ -1100,12 +1100,8 @@ App.UI.brandSelect = function(category, slave, cheat = false) { App.UI.DOM.makeElement("div", `One 'welcome' for a new slave is to have them branded. Where would you like such brands to be applied?`), App.UI.bodyPartSelector(V.brandTarget, "primary", true) ); - if ( - !findBodyPart(V.brandTarget.primary).isPair && ( - findBodyPart(V.brandTarget.primary.replace(/left /g, "")).canAmp || - findBodyPart(V.brandTarget.primary.replace(/right /g, "")).canAmp - ) - ) { + const bodyPartRoot = App.UI.bodyPartRoot(V.brandTarget.primary); + if (!App.Data.Slave.body.get(bodyPartRoot).isPair && (App.Data.Slave.body.get(bodyPartRoot)).hasOwnProperty("requirements")) { r.push(`It's possible that <strong>${V.brandTarget.primary}</strong> may be missing from a slave. Choose a fallback in case it is not available: Current backup is <strong>${V.brandTarget.secondary}</strong>:`); App.Events.addNode(el, r, "div"); r = []; @@ -1214,12 +1210,8 @@ App.UI.scarSelect = function(category, slave, cheat = false) { App.UI.DOM.makeElement("div", `One 'welcome' for a new slave is to have them scarred. Where would you like such scars to be applied?`), App.UI.bodyPartSelector(V.scarTarget, "primary", true) ); - if ( - !findBodyPart(V.scarTarget.primary).isPair && ( - findBodyPart(V.scarTarget.primary.replace(/left /g, "")).canAmp || - findBodyPart(V.scarTarget.primary.replace(/right /g, "")).canAmp - ) - ) { + const bodyPartRoot = App.UI.bodyPartRoot(V.scarTarget.primary); + if (!App.Data.Slave.body.get(bodyPartRoot).isPair && (App.Data.Slave.body.get(bodyPartRoot)).hasOwnProperty("requirements")) { r.push(`It's possible that <strong>${V.scarTarget.primary}</strong> may be missing from a slave. Choose a fallback in case it is not available: Current backup is <strong>${V.scarTarget.secondary}</strong>:`); App.Events.addNode(el, r, "div"); r = []; @@ -1269,11 +1261,11 @@ App.UI.bodyPartSelector = function(variable, property, selector) { } } for (const category in links) { - App.UI.DOM.appendNewElement("div", el, App.UI.DOM.generateLinksStrip(links[category]), "choices") + App.UI.DOM.appendNewElement("div", el, App.UI.DOM.generateLinksStrip(links[category]), "choices"); } // Choose a side - if (findBodyPart(variable[property]).isPair) { + if (App.Data.Slave.body.get(App.UI.bodyPartRoot(variable[property])).isPair) { const linkArray = []; for (const side of ["left", "right"]) { linkArray.push(App.UI.DOM.link(capFirstChar(side), () => { @@ -1300,3 +1292,17 @@ App.UI.bodyPartSelector = function(variable, property, selector) { return el; }; + +/** + * + * @param {string} bodyPart + * @returns {string} + */ +App.UI.bodyPartRoot = function(bodyPart) { + if (bodyPart.startsWith("left")) { + bodyPart = (bodyPart.replace(/left /g, "")); + } else if (bodyPart.startsWith("right")) { + bodyPart = (bodyPart.replace(/right /g, "")); + } + return bodyPart; +}; diff --git a/src/js/utilsSlave.js b/src/js/utilsSlave.js index f95955f2193..113bb8d6663 100644 --- a/src/js/utilsSlave.js +++ b/src/js/utilsSlave.js @@ -3565,14 +3565,3 @@ globalThis.addPartner = function(slave, partner) { partnerState.partners.add(slave.ID); } }; - -globalThis.findBodyPart = function(part) { - for (const value of App.Data.Slave.body.values()) { - for (const key in value) { - if (key === part) { - return value[key]; - } - } - } - return {}; -}; -- GitLab