From 58b1979087d2453ca85b92c65226af32f90e554d Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Tue, 6 Apr 2021 19:10:27 -0400
Subject: [PATCH] add cheat apply to policies

---
 src/cheats/cheatEditArcology.js      | 52 ----------------------------
 src/interaction/policies/policies.js | 21 +++++++++--
 2 files changed, 18 insertions(+), 55 deletions(-)

diff --git a/src/cheats/cheatEditArcology.js b/src/cheats/cheatEditArcology.js
index 3ec614b4639..5e56d8bc272 100644
--- a/src/cheats/cheatEditArcology.js
+++ b/src/cheats/cheatEditArcology.js
@@ -118,58 +118,6 @@ App.UI.Cheat.arcology = function(num) {
 						.addValue("Yes", 1).on()
 						.addValue("No", 0).off();
 				}
-				if (num === 0) {
-					if (arc.hasOwnProperty(`${FS}Decoration`)) {
-						options.addOption(`${App.Data.FutureSociety.records[FS].noun} decoration`, `${FS}Decoration`, arc).showTextBox();
-					}
-					if (arc.hasOwnProperty(`${FS}SMR`)) {
-						options.addOption(`${App.Data.FutureSociety.records[FS].noun} slave market regulations`, `${FS}SMR`, arc)
-							.addValue("Yes", 1).on()
-							.addValue("No", 0).off();
-					}
-					if (arc.hasOwnProperty(`${FS}Law`)) {
-						options.addOption(`${App.Data.FutureSociety.records[FS].noun} law`, `${FS}Law`, arc).showTextBox();
-					}
-					if (arc.hasOwnProperty(`${FS}Law2`)) {
-						options.addOption(`${App.Data.FutureSociety.records[FS].noun} law 2`, `${FS}Law2`, arc).showTextBox();
-					}
-					switch (FS) {
-						case "FSSupremacist":
-							option = options.addOption(`Supremacist race`, `FSSupremacistRace`, arc);
-							for (const [race, capRace] of App.Data.misc.filterRaces) {
-								option.addValue(capRace, race);
-							}
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} law ME`, `FSSupremacistLawME`, arc).showTextBox();
-							break;
-						case "FSSubjugationist":
-							option = options.addOption(`Subjugationist race`, `FSSubjugationistRace`, arc);
-							for (const [race, capRace] of App.Data.misc.filterRaces) {
-								option.addValue(capRace, race);
-							}
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} law ME`, `FSSubjugationistLawME`, arc).showTextBox();
-							break;
-						case "FSHedonistic":
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} diet research`, `FSHedonisticDecadenceDietResearch`, arc).showTextBox();
-							break;
-						case "FSGenderRadicalist":
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} futa law`, `FSGenderRadicalistLawFuta`, arc).showTextBox();
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} beauty law`, `FSGenderRadicalistLawBeauty`, arc).showTextBox();
-							break;
-						case "FSGenderFundamentalist":
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} bimbo law`, `FSGenderFundamentalistLawBimbo`, arc).showTextBox();
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} beauty law`, `FSGenderFundamentalistLawBeauty`, arc).showTextBox();
-							break;
-						case "FSPhysicalIdealist":
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} strong fat`, `FSPhysicalIdealistStrongFat`, arc).showTextBox();
-							break;
-						case "FSChattelReligionist":
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} creed`, `FSChattelReligionistCreed`, arc).showTextBox();
-							break;
-						case "FSNeoImperialist":
-							options.addOption(`${App.Data.FutureSociety.records[FS].noun} law 1`, `FSNeoImperialistLaw1`, arc).showTextBox();
-							break;
-					}
-				}
 
 				el.append(options.render());
 			}
diff --git a/src/interaction/policies/policies.js b/src/interaction/policies/policies.js
index c60e7ae5251..ff007797478 100644
--- a/src/interaction/policies/policies.js
+++ b/src/interaction/policies/policies.js
@@ -38,7 +38,6 @@ globalThis.policy = function(category) {
 		let el = document.createElement("p");
 		let div;
 		let span;
-		let link;
 		const policyValue = _.get(V, policyVariable);
 		/** @type {PolicySelector[]} */
 		const policyObject = App.Data.Policies.Selection[category][policyVariable];
@@ -72,7 +71,7 @@ globalThis.policy = function(category) {
 						if (p.requirements === true) {
 							div.append(implement(p, enable));
 						} else {
-							link = App.UI.DOM.disabledLink("Implement", [`You do not meet the requirements, or passed a conflicting policy already`]);
+							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);
 						}
@@ -139,6 +138,7 @@ globalThis.policy = function(category) {
 		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(
@@ -175,6 +175,8 @@ globalThis.policy = function(category) {
 		function implement(p, enable) {
 			let check = canAfford();
 			const frag = new DocumentFragment;
+			const linkArray = [];
+			let link;
 			if (check === true) {
 				link = App.UI.DOM.link(
 					"Implement",
@@ -194,7 +196,20 @@ globalThis.policy = function(category) {
 				link = App.UI.DOM.disabledLink("Implement", [`You do not have enough ${check}`]);
 				link.style.color = "red";
 			}
-			frag.append(link);
+			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(); // policy(category); We need to make sure all tabs are refreshed, so this policy call is too targeted for now.
+					}
+				));
+			}
+			frag.append(App.UI.DOM.generateLinksStrip(linkArray));
 			if (p.hasOwnProperty("note")) {
 				frag.append(App.UI.DOM.makeElement("div", p.note, ["note", "indent"]));
 			}
-- 
GitLab