diff --git a/src/interaction/policies/policies.js b/src/interaction/policies/policies.js index 9b86a64e689eb4f6abc63cbd73508f26a7f0781b..362f40479843985d8598f46b145a8bb194c900c9 100644 --- a/src/interaction/policies/policies.js +++ b/src/interaction/policies/policies.js @@ -27,216 +27,204 @@ globalThis.policies = (function() { globalThis.policy = function(category) { const policyArray = []; for (let policyVariable in App.Data.Policies.Selection[category]) { - policyArray.push(policyElement(policyVariable)); + policyElement(policyVariable); } + console.log(policyArray); return policyArray; - /** - * @param {string} policyVariable - * @returns {Node} el - */ - function policyElement(policyVariable) { - const container = document.createElement("div"); - container.append(fillContainer()); - return container; - /** - * @returns {HTMLElement} el - */ - function fillContainer() { - let el = document.createElement("p"); - let div; - let span; - const policyValue = _.get(V, policyVariable); - /** @type {PolicySelector[]} */ - const policyObject = App.Data.Policies.Selection[category][policyVariable]; - if (policyValue === 0) { - // apply - for (let i = 0; i < policyObject.length; i++) { - const p = policyObject[i]; - const enable = p.enable || 1; - if (p.hasOwnProperty("requirements") && p.requirements === false) { - continue; - } - div = document.createElement("div"); - span = document.createElement("span"); - // title - span.style.fontWeight = "bold"; - if (p.hasOwnProperty("titleClass")) { - span.classList.add(p.titleClass); - } - span.append(p.title); - div.append(span); - div.append(`: `); - - // Description text - div.append(p.text); - div.append(` `); - - // link - if (!(p.hasOwnProperty("hide") && p.hide.button === 1)) { - if (p.hasOwnProperty("requirements")) { - if (p.requirements === true) { - div.append(implement(p, enable)); - } else { - const link = App.UI.DOM.disabledLink("Implement", [`You do not meet the requirements, or passed a conflicting policy already`]); - link.style.color = "white"; - div.append(link); - } - } else { - div.append(implement(p, enable)); - } - } - el.append(div); - } - } else if (typeof policyValue === "string" || typeof policyValue === "number") { - // repeal - let i = 0; - for (const pol in policyObject) { - if (policyObject[pol].hasOwnProperty("enable") && policyObject[pol].enable === policyValue) { - i = pol; - break; - } - } + /** @param {string} policyVariable */ + function policyElement(policyVariable) { + let el; + let span; + const policyValue = _.get(V, policyVariable); + /** @type {PolicySelector[]} */ + const policyObject = App.Data.Policies.Selection[category][policyVariable]; + if (policyValue === 0) { + // apply + for (let i = 0; i < policyObject.length; i++) { const p = policyObject[i]; - if (p.hasOwnProperty("hide")) { - if (p.hide.ifActivated === 1) { - return el; - } + const enable = p.enable || 1; + if (p.hasOwnProperty("requirements") && p.requirements === false) { + continue; } - - let title; - if (p.hasOwnProperty("activatedTitle")) { - title = p.activatedTitle; - } else { - title = p.title; - } - let text; - if (p.hasOwnProperty("activatedText")) { - text = p.activatedText; - } else { - text = p.text; - } - div = document.createElement("div"); + el = document.createElement("p"); span = document.createElement("span"); // title span.style.fontWeight = "bold"; - span.append(title); - div.append(span); - div.append(`: `); + if (p.hasOwnProperty("titleClass")) { + span.classList.add(p.titleClass); + } + span.append(p.title); + el.append(span); + el.append(`: `); // Description text - div.append(text); - div.append(` `); + el.append(p.text); + el.append(` `); // link - div.append(repeal(p)); - el.append(div); - } else { - throw `V.${policyVariable} not initialized properly, "${policyValue}"`; - } - - return el; - - /** - * @param {PolicySelector} p The data object that describes the policy being considered. - * @returns {Node} Link to repeal. - */ - function repeal(p) { - const frag = new DocumentFragment; - let check = canAfford(); - let link; if (!(p.hasOwnProperty("hide") && p.hide.button === 1)) { - if (check === true) { - link = App.UI.DOM.link( - "Repeal", - () => { - if (V.rep >= 1000) { - _.set(V, policyVariable, 0); - applyCost(); - if (p.hasOwnProperty("onRepeal")) { - p.onRepeal(); - } - } - jQuery(container).empty().append(fillContainer(policyVariable)); - } - ); - link.style.color = "yellow"; + if (p.hasOwnProperty("requirements")) { + if (p.requirements === true) { + el.append(implement(p, enable)); + } else { + const link = App.UI.DOM.disabledLink("Implement", [`You do not meet the requirements, or passed a conflicting policy already`]); + link.style.color = "white"; + el.append(link); + } } else { - link = App.UI.DOM.disabledLink("Repeal", [`You do not have enough ${check}`]); - link.style.color = "red"; + el.append(implement(p, enable)); } - frag.append(link); } - - if (p.hasOwnProperty("activatedNote")) { - frag.append(App.UI.DOM.makeElement("div", p.activatedNote, ["note", "indent"])); + policyArray.push(el); + } + } else if (typeof policyValue === "string" || typeof policyValue === "number") { + // repeal + let i = 0; + for (const pol in policyObject) { + if (policyObject[pol].hasOwnProperty("enable") && policyObject[pol].enable === policyValue) { + i = pol; + break; + } + } + const p = policyObject[i]; + if (p.hasOwnProperty("hide")) { + if (p.hide.ifActivated === 1) { + return; } - return frag; } - /** - * @param {PolicySelector} p The data object that describes the policy being considered. - * @param {number|string} enable value to set the policy to in order to switch it on. - * @returns {Node} Link to implement. - */ - function implement(p, enable) { - let check = canAfford(); - const frag = new DocumentFragment; - const linkArray = []; - let link; + + let title; + if (p.hasOwnProperty("activatedTitle")) { + title = p.activatedTitle; + } else { + title = p.title; + } + let text; + if (p.hasOwnProperty("activatedText")) { + text = p.activatedText; + } else { + text = p.text; + } + el = document.createElement("p"); + span = document.createElement("span"); + + // title + span.style.fontWeight = "bold"; + span.append(title); + el.append(span); + el.append(`: `); + + // Description text + el.append(text); + el.append(` `); + + // link + el.append(repeal(p)); + policyArray.push(el); + } else { + throw `V.${policyVariable} not initialized properly, "${policyValue}"`; + } + + /** + * @param {PolicySelector} p The data object that describes the policy being considered. + * @returns {Node} Link to repeal. + */ + function repeal(p) { + const frag = new DocumentFragment; + let check = canAfford(); + let link; + if (!(p.hasOwnProperty("hide") && p.hide.button === 1)) { if (check === true) { link = App.UI.DOM.link( - "Implement", + "Repeal", () => { if (V.rep >= 1000) { - _.set(V, policyVariable, enable); + _.set(V, policyVariable, 0); applyCost(); - if (p.hasOwnProperty("onImplementation")) { - p.onImplementation(); + if (p.hasOwnProperty("onRepeal")) { + p.onRepeal(); } } App.UI.reload(); } ); - link.style.color = "green"; + link.style.color = "yellow"; } else { - link = App.UI.DOM.disabledLink("Implement", [`You do not have enough ${check}`]); + link = App.UI.DOM.disabledLink("Repeal", [`You do not have enough ${check}`]); link.style.color = "red"; } - linkArray.push(link); - if (V.cheatMode) { - linkArray.push(App.UI.DOM.link( - "Cheat apply", - () => { + frag.append(link); + } + + if (p.hasOwnProperty("activatedNote")) { + frag.append(App.UI.DOM.makeElement("div", p.activatedNote, ["note", "indent"])); + } + return frag; + } + /** + * @param {PolicySelector} p The data object that describes the policy being considered. + * @param {number|string} enable value to set the policy to in order to switch it on. + * @returns {Node} Link to implement. + */ + function implement(p, enable) { + let check = canAfford(); + const frag = new DocumentFragment; + const linkArray = []; + let link; + if (check === true) { + link = App.UI.DOM.link( + "Implement", + () => { + if (V.rep >= 1000) { _.set(V, policyVariable, enable); + applyCost(); if (p.hasOwnProperty("onImplementation")) { p.onImplementation(); } - App.UI.reload(); } - )); - } - frag.append(App.UI.DOM.generateLinksStrip(linkArray)); - if (p.hasOwnProperty("note")) { - frag.append(App.UI.DOM.makeElement("div", p.note, ["note", "indent"])); - } - return frag; + App.UI.reload(); + } + ); + link.style.color = "green"; + } else { + link = App.UI.DOM.disabledLink("Implement", [`You do not have enough ${check}`]); + link.style.color = "red"; } + linkArray.push(link); + if (V.cheatMode) { + linkArray.push(App.UI.DOM.link( + "Cheat apply", + () => { + _.set(V, policyVariable, enable); + if (p.hasOwnProperty("onImplementation")) { + p.onImplementation(); + } + App.UI.reload(); + } + )); + } + frag.append(App.UI.DOM.generateLinksStrip(linkArray)); + if (p.hasOwnProperty("note")) { + frag.append(App.UI.DOM.makeElement("div", p.note, ["note", "indent"])); + } + return frag; + } - function canAfford() { - if (V.cash < 5000) { - return "cash"; - } else if (V.rep < 1000 && !["EducationPolicies"].includes(category)) { - return "reputation"; - } - return true; + function canAfford() { + if (V.cash < 5000) { + return "cash"; + } else if (V.rep < 1000 && !["EducationPolicies"].includes(category)) { + return "reputation"; } + return true; + } - function applyCost() { - cashX(-5000, "policies"); - if (!["EducationPolicies"].includes(category)) { - repX(-1000, "policies"); - } + function applyCost() { + cashX(-5000, "policies"); + if (!["EducationPolicies"].includes(category)) { + repX(-1000, "policies"); } } } diff --git a/src/interaction/policies/policiesPassage.js b/src/interaction/policies/policiesPassage.js index 299691d765bc0e73da28aa7824e0c7f254572b49..a8992d3a31cf064841b3ebc06a0b0d94a6b0e9a7 100644 --- a/src/interaction/policies/policiesPassage.js +++ b/src/interaction/policies/policiesPassage.js @@ -71,32 +71,10 @@ App.UI.policies = function() { const frag = new DocumentFragment(); policy("FutureSocietiesTab").forEach(p => frag.append(p)); for (const FS in App.Data.FutureSociety.records) { - const apply = () => { - const policies = policy(FS); - if (policies.length > 0) { - App.UI.DOM.appendNewElement("h2", frag, App.Data.FutureSociety.records[FS].adj); - policies.forEach(p => frag.append(p)); - } - }; - if (FS === "FSGenderFundamentalist") { - if (V.arcologies[0].FSGenderFundamentalist > 20) { - apply(); - } - } else if (FS === "FSGenderRadicalist") { - if (V.arcologies[0].FSGenderRadicalist > 20 && !(V.arcologies[0].FSGenderFundamentalist > 20)) { - apply(); - } - } else if (FS === "FSRestart") { - if (V.arcologies[0][FS] > 40 || V.propOutcome !== 0) { - if (V.propOutcome) { - r.push(`<strong>Elite Breeder Eligibility:</strong> Societal Elite may use eligible slaves as breeders.`); - } else if (V.propOutcome === -1) { - r.push(`<strong>Elite Breeder Eligibility:</strong> The Societal Elite have rejected your breeding proposal.`); - } - apply(); - } - } else if (V.arcologies[0][FS] > 40) { - apply(); + const policies = policy(FS); + if (policies.length > 0) { + App.UI.DOM.appendNewElement("h2", frag, App.Data.FutureSociety.records[FS].adj); + policies.forEach(p => frag.append(p)); } } return frag;