From 26a3b659ed51f9ed288baf54e7d0ee4e2597c090 Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Sun, 16 Aug 2020 18:53:10 -0700 Subject: [PATCH] Eliminate $lastWeeksGatheredTotals --- js/003-data/gameVariableData.js | 1 - .../backwardsCompatibility.js | 11 -------- src/js/economyJS.js | 25 ------------------- src/uncategorized/costsBudget.js | 16 +++++++----- 4 files changed, 10 insertions(+), 43 deletions(-) diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index b70c19617a1..70c9dcb22e3 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -495,7 +495,6 @@ App.Data.resetOnNGPlus = { lastWeeksCashExpenses: {}, lastWeeksRepIncome: {}, lastWeeksRepExpenses: {}, - lastWeeksGatheredTotals: {}, currentRule: {}, costs: 0, seeBuilding: 0, diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js index f33df391add..4a2b6f872cd 100644 --- a/src/data/backwardsCompatibility/backwardsCompatibility.js +++ b/src/data/backwardsCompatibility/backwardsCompatibility.js @@ -119,17 +119,6 @@ App.Update.backwardsCompatibility = function() { }; App.Update.globalVariables = function(node) { - for (const key of Object.keys(CategoryAssociatedGroup)) { - if(!V.lastWeeksGatheredTotals[key]) { - V.lastWeeksGatheredTotals[key] = {income: 0, expenses: 0}; - } - for (const subKey of Object.keys(new App.Data.Records.LastWeeksCash())) { - if(!V.lastWeeksGatheredTotals[key][subKey]) { - V.lastWeeksGatheredTotals[key][subKey] = {income: 0, expenses: 0}; - } - } - } - if (Array.isArray(V.nationalities)) { V.nationalities = weightedArray2HashMap(V.nationalities); } diff --git a/src/js/economyJS.js b/src/js/economyJS.js index df410187683..2f791dedcd5 100644 --- a/src/js/economyJS.js +++ b/src/js/economyJS.js @@ -2308,14 +2308,6 @@ globalThis.cashX = function(cost, what, who) { who.lastWeeksCashIncome += cost; who.lifetimeCashIncome += cost; } - - // gather totals - for (const key of Object.keys(CategoryAssociatedGroup)) { - if (CategoryAssociatedGroup[key].contains(what)) { - V.lastWeeksGatheredTotals[key][what].income += cost; - V.lastWeeksGatheredTotals[key].income += cost; - } - } } else if (cost < 0) { // EXPENSES // record the action if (typeof V.lastWeeksCashExpenses[what] !== 'undefined') { @@ -2333,14 +2325,6 @@ globalThis.cashX = function(cost, what, who) { who.lifetimeCashExpenses += cost; } } - - // gather totals - for (const key of Object.keys(CategoryAssociatedGroup)) { - if (CategoryAssociatedGroup[key].contains(what)) { - V.lastWeeksGatheredTotals[key][what].expenses += cost; - V.lastWeeksGatheredTotals[key].expenses += cost; - } - } } App.Utils.scheduleSidebarRefresh(); @@ -2600,15 +2584,6 @@ globalThis.setupLastWeeksCash = function() { V.lastWeeksCashIncome = new App.Data.Records.LastWeeksCash(); V.lastWeeksCashExpenses = new App.Data.Records.LastWeeksCash(); V.lastWeeksCashErrors = "Errors: "; - - // Here we reset our tracked totals on week end, and add the default categories to all objects - V.lastWeeksGatheredTotals = {}; - for (const key of Object.keys(CategoryAssociatedGroup)){ - V.lastWeeksGatheredTotals[key] = {income: 0, expenses: 0}; - for (const subKey of Object.keys(new App.Data.Records.LastWeeksCash())) { - V.lastWeeksGatheredTotals[key][subKey] = {income: 0, expenses: 0}; - } - } }; globalThis.setupLastWeeksRep = function() { diff --git a/src/uncategorized/costsBudget.js b/src/uncategorized/costsBudget.js index 6fbad7e4d0a..7d4b53daaa9 100644 --- a/src/uncategorized/costsBudget.js +++ b/src/uncategorized/costsBudget.js @@ -4,7 +4,6 @@ App.UI.Budget.Cost = function() { // Set up object to track calculated displays const income = "lastWeeksCashIncome"; const expenses = "lastWeeksCashExpenses"; - const F = V.lastWeeksGatheredTotals; const table = document.createElement("table"); table.classList.add("budget"); @@ -367,19 +366,24 @@ App.UI.Budget.Cost = function() { } } - function generateRowGroup(title, group) { - if (F[group].income || F[group].expenses || V.showAllEntries.costsBudget) { + function generateRowGroup(title, name) { + /** @type {string[]} */ + const members = CategoryAssociatedGroup[name]; + const groupIn = members.map((k) => V[income][k]).reduce((acc, cur) => acc + cur); + const groupEx = members.map((k) => V[expenses][k]).reduce((acc, cur) => acc + cur); + + if (groupIn || groupEx || V.showAllEntries.costsBudget) { const row = table.insertRow(); let cell = row.insertCell(); const headline = document.createElement('h3'); headline.textContent = title; cell.append(headline); cell = row.insertCell(); - cell.append(cashFormatColorDOM(F[group].income, null)); + cell.append(cashFormatColorDOM(groupIn)); cell = row.insertCell(); - cell.append(cashFormatColorDOM(F[group].expenses, null)); + cell.append(cashFormatColorDOM(groupEx)); cell = row.insertCell(); - cell.append(cashFormatColorDOM(F[group].income + F[group].expenses, null)); + cell.append(cashFormatColorDOM(groupIn + groupEx)); return row; } } -- GitLab