From 23d4dc42c2799ce5caa75b7ab10785a59702dfb2 Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Sun, 14 Mar 2021 17:59:06 -0700 Subject: [PATCH] Improve bulk decoration behavior. Make only one capEx charge for bulk changes. Do not charge for unchanged facilities when using Distribute Evenly. Do not display Distribute Evenly if there are no FS decorations available. --- src/futureSocieties/fsDecoration.js | 51 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/futureSocieties/fsDecoration.js b/src/futureSocieties/fsDecoration.js index a8521b78cbf..7861241d48a 100644 --- a/src/futureSocieties/fsDecoration.js +++ b/src/futureSocieties/fsDecoration.js @@ -65,33 +65,40 @@ App.UI.facilityRedecoration = function() { // dummy variable to make sure the first option is selected by default const currentSelected = {value: "none"}; - options.addOption(`The decoration style of ${name} is`, "value", currentSelected) + let option = options.addOption(`Set decoration value for all facilities to`, "value", currentSelected) .addValue("(Select option)", "none") - .addValue("Standard", "standard") - .addValueList(decorationNames) - .addValue("Distribute Evenly", "even") - .addCallbackToEach(value => { - console.log(value); - if (value === "even") { // Cycles through the list of available FS decorations, and distributes them to facilities round robin style. - let i = 0; - for (const decoration of activeFacilities.values()) { - cashX(-5000, "capEx"); + .addValue("Standard", "standard"); + if (decorationNames.length > 0) { + option.addValueList(decorationNames) + .addValue("Distribute Evenly", "even"); + } + option.addCallbackToEach(value => { + console.log(value); + let totalCost = 0; + if (value === "even") { // Cycles through the list of available FS decorations, and distributes them to facilities round robin style. + let i = 0; + for (const decoration of activeFacilities.values()) { + if (V[decoration] !== decorationNames[i]) { + totalCost += 5000; V[decoration] = decorationNames[i]; - i++; - if (i >= decorationNames.length) { - i = 0; - } } - } else { - for (const decoration of activeFacilities.values()) { - if (value !== "standard") { - cashX(-5000, "capEx"); - } - V[decoration] = value; + i++; + if (i >= decorationNames.length) { + i = 0; + } + } + } else if (value !== "none") { + for (const decoration of activeFacilities.values()) { + if (value !== "standard") { + totalCost += 5000; } + V[decoration] = value; } - }) - .pulldown(); + } + if (totalCost > 0) { + cashX(forceNeg(totalCost), "capEx"); + } + }).pulldown(); for (const [name, decoration] of activeFacilities) { options.addOption(`The decoration style of ${name} is`, decoration) -- GitLab