From fe4cebf84f40357fa2eef5cc0e15849da960a448 Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Sun, 28 Jun 2020 13:10:40 -0400 Subject: [PATCH] more fixes for new structure --- js/003-data/policiesData.js | 34 ++++++++++++++---------- src/interaction/policies/policies.js | 39 ++++++++++------------------ src/interaction/policies/policies.tw | 1 + 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/js/003-data/policiesData.js b/js/003-data/policiesData.js index 49ebf335088..30daa607f33 100644 --- a/js/003-data/policiesData.js +++ b/js/003-data/policiesData.js @@ -603,7 +603,7 @@ App.Data.Policies.Selection = { ], }, RetirementPolicies: { - "policies.retirement.physicalAgePolicy": [ + "policies.retirement.customAgePolicy": [ { title: "Redefined Mandatory Retirement Age", get text() { @@ -848,14 +848,24 @@ App.Data.Policies.Selection = { MenialRetirementPolicies: { "policies.retirement.menial2Citizen": [ { - title: "No Menial Retirement Plan", - text: "without defining a retirement age for menial slaves they will remain slaves until death or freed otherwise.", - hide: {button: 1, ifActivated: 1, ifDeactivated: 0} - } - ], - "policies.retirement.menial2Citizen": [ - { - title: "Redefined Mandatory Menial Retirement Age", + get title() { + const el = new DocumentFragment; + if (V.policies.retirement.menial2Citizen !== 1) { + let div = document.createElement("div"); + let span = document.createElement("span"); + span.style.fontWeight = "bold"; + span.textContent = `No Menial Retirement Plan`; + div.append(span); + + span = document.createElement("span"); + span.style.fontWeight = "normal"; + span.textContent = `: without defining a retirement age for menial slaves they will remain slaves until death or freed otherwise`; + div.append(span); + el.append(div); + } + el.append("Redefined Mandatory Menial Retirement Age"); + return el; + }, get text() { const el = new DocumentFragment; el.append(`you will set your arcology's retirement age for menial slaves at age`); @@ -875,10 +885,8 @@ App.Data.Policies.Selection = { ); return el; }, - hide: {button: 1, ifActivated: 1, ifDeactivated: 0} - } - ], - "policies.retirement.menial2Citizen": [ + hide: {button: 1} + }, { title: "Menial Slave Citizen Retirement", activatedTitle: "Mandatory Menial Retirement Age", diff --git a/src/interaction/policies/policies.js b/src/interaction/policies/policies.js index 128d775a5a4..b4c03bc84ad 100644 --- a/src/interaction/policies/policies.js +++ b/src/interaction/policies/policies.js @@ -112,26 +112,26 @@ globalThis.policies = (function() { */ globalThis.policy = function(category) { const frag = new DocumentFragment; - for (let selectedPolicy of App.Data.Policies.Selection[category]) { - frag.append(policyElement(selectedPolicy)); + for (let policyVariable in App.Data.Policies.Selection[category]) { + frag.append(policyElement(policyVariable)); } return jQuery(`#${category}`).empty().append(frag); - function policyElement(selectedPolicy) { + function policyElement(policyVariable) { let el = document.createElement("p"); let div; let span; let link; - const policyValue = _.get(V, selectedPolicy[0].policy); + const policyValue = _.get(V, policyVariable); + const policyObject = App.Data.Policies.Selection[category][policyVariable]; if (policyValue === 0) { // apply - for (let i = 0; i < selectedPolicy.length; i++) { - const p = selectedPolicy[i]; + for (let i = 0; i < policyObject.length; i++) { + const p = policyObject[i]; const enable = p.enable || 1; - if ((p.hasOwnProperty("hide") && p.hide.ifDeactivated === 1) || (p.hasOwnProperty("requirements") && p.requirements() === false)) { // TODO: may no longer need ifDeactivated and similar + if ((p.hasOwnProperty("hide") && p.hide.ifDeactivated === 1) || (p.hasOwnProperty("requirements") && p.requirements() === false)) { // TODO: may no longer need ifDeactivated and similar continue; } - testArray(p); div = document.createElement("div"); span = document.createElement("span"); @@ -168,13 +168,13 @@ globalThis.policy = function(category) { } else { // repeal let i = 0; - for (const pol in selectedPolicy) { - if (selectedPolicy[pol].hasOwnProperty("enable") && selectedPolicy[pol].enable === policyValue) { + for (const pol in policyObject) { + if (policyObject[pol].hasOwnProperty("enable") && policyObject[pol].enable === policyValue) { i = pol; break; } } - const p = selectedPolicy[i]; + const p = policyObject[i]; if (p.hasOwnProperty("hide")) { if (p.hide.ifActivated === 1) { return el; @@ -193,7 +193,6 @@ globalThis.policy = function(category) { } else { text = p.text; } - testArray(p); div = document.createElement("div"); span = document.createElement("span"); @@ -213,18 +212,6 @@ globalThis.policy = function(category) { return el; - function testArray(p) { - if (!p.hasOwnProperty("title")) { - throw "Title not set up properly for a policy"; - } - if (!p.hasOwnProperty("text")) { - throw `Description not set up properly for policy ${p.text}`; - } - if (!p.hasOwnProperty("policy")) { - throw `Variable not set up properly for policy ${p.text}`; - } - } - function repeal(p) { // repeal let check = canAfford(); @@ -233,7 +220,7 @@ globalThis.policy = function(category) { link = App.UI.DOM.link( "Repeal", () => { - _.set(V, p.policy, 0); + _.set(V, policyVariable, 0); applyCost(); if (p.hasOwnProperty("onRepeal")) { p.onRepeal(); @@ -262,7 +249,7 @@ globalThis.policy = function(category) { link = App.UI.DOM.link( "Implement", () => { - _.set(V, p.policy, enable); + _.set(V, policyVariable, enable); applyCost(); if (p.hasOwnProperty("onImplementation")) { p.onImplementation(); diff --git a/src/interaction/policies/policies.tw b/src/interaction/policies/policies.tw index 1be1fc3e6ce..3bba9638e46 100644 --- a/src/interaction/policies/policies.tw +++ b/src/interaction/policies/policies.tw @@ -138,6 +138,7 @@ policy("RetirementPolicies"); </script> <h1>Menials</h1> + <span id="MenialRetirementPolicies"></span> <script> policy("MenialRetirementPolicies"); -- GitLab