From ccee1b982b24e4446992bc43a76dca1ecc91f5cd Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Sun, 16 Aug 2020 16:15:29 -0700 Subject: [PATCH] Don't store any profit data in the save, compute it when needed from income and expenses --- js/003-data/gameVariableData.js | 2 -- .../backwardsCompatibility.js | 4 ++-- src/js/economyJS.js | 12 ++-------- src/js/utilsFC.js | 9 ++----- src/uncategorized/brothel.tw | 10 ++++---- src/uncategorized/costsBudget.js | 24 ++++--------------- src/uncategorized/costsBudget.tw | 1 - src/uncategorized/repBudget.tw | 23 +++--------------- 8 files changed, 19 insertions(+), 66 deletions(-) diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index 29919395a4f..b70c19617a1 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -493,10 +493,8 @@ App.Data.resetOnNGPlus = { reminderWeek: "", lastWeeksCashIncome: {}, lastWeeksCashExpenses: {}, - lastWeeksCashProfits: {}, lastWeeksRepIncome: {}, lastWeeksRepExpenses: {}, - lastWeeksRepProfits: {}, lastWeeksGatheredTotals: {}, currentRule: {}, costs: 0, diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js index 4a83fd41880..f33df391add 100644 --- a/src/data/backwardsCompatibility/backwardsCompatibility.js +++ b/src/data/backwardsCompatibility/backwardsCompatibility.js @@ -121,11 +121,11 @@ 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, profits: 0}; + 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, profits: 0}; + V.lastWeeksGatheredTotals[key][subKey] = {income: 0, expenses: 0}; } } } diff --git a/src/js/economyJS.js b/src/js/economyJS.js index 881b547b57f..df410187683 100644 --- a/src/js/economyJS.js +++ b/src/js/economyJS.js @@ -2310,13 +2310,10 @@ globalThis.cashX = function(cost, what, who) { } // gather totals - V.lastWeeksCashProfits[what] += cost; for (const key of Object.keys(CategoryAssociatedGroup)) { if (CategoryAssociatedGroup[key].contains(what)) { V.lastWeeksGatheredTotals[key][what].income += cost; - V.lastWeeksGatheredTotals[key][what].profits += cost; V.lastWeeksGatheredTotals[key].income += cost; - V.lastWeeksGatheredTotals[key].profits += cost; } } } else if (cost < 0) { // EXPENSES @@ -2338,13 +2335,10 @@ globalThis.cashX = function(cost, what, who) { } // gather totals - V.lastWeeksCashProfits[what] += cost; for (const key of Object.keys(CategoryAssociatedGroup)) { if (CategoryAssociatedGroup[key].contains(what)) { V.lastWeeksGatheredTotals[key][what].expenses += cost; - V.lastWeeksGatheredTotals[key][what].profits += cost; V.lastWeeksGatheredTotals[key].expenses += cost; - V.lastWeeksGatheredTotals[key].profits += cost; } } } @@ -2605,15 +2599,14 @@ globalThis.ownershipReport = function({sidebar}) { globalThis.setupLastWeeksCash = function() { V.lastWeeksCashIncome = new App.Data.Records.LastWeeksCash(); V.lastWeeksCashExpenses = new App.Data.Records.LastWeeksCash(); - V.lastWeeksCashProfits = 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, profits: 0}; + 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, profits: 0}; + V.lastWeeksGatheredTotals[key][subKey] = {income: 0, expenses: 0}; } } }; @@ -2621,6 +2614,5 @@ globalThis.setupLastWeeksCash = function() { globalThis.setupLastWeeksRep = function() { V.lastWeeksRepIncome = new App.Data.Records.LastWeeksRep(); V.lastWeeksRepExpenses = new App.Data.Records.LastWeeksRep(); - V.lastWeeksRepProfits = new App.Data.Records.LastWeeksRep(); V.lastWeeksRepErrors = "Errors: "; }; diff --git a/src/js/utilsFC.js b/src/js/utilsFC.js index 42be8f0261f..cde4a6546c6 100644 --- a/src/js/utilsFC.js +++ b/src/js/utilsFC.js @@ -1328,34 +1328,29 @@ globalThis.massFormat = function(s) { globalThis.budgetLine = function(category, title) { let income; let expenses; - let profits; if (passage() === "Rep Budget") { income = "lastWeeksRepIncome"; expenses = "lastWeeksRepExpenses"; - profits = "lastWeeksRepProfits"; if (V[income][category] || V[expenses][category] || V.showAllEntries.repBudget) { - V[profits][category] = V[income][category] + V[expenses][category]; return `<tr>\ <td>${title}</td>\ <td>${repFormat(V[income][category])}</td>\ <td>${repFormat(V[expenses][category])}</td>\ - <td>${repFormat(V[profits][category])}</td>\ + <td>${repFormat(V[income][category] + V[expenses][category])}</td>\ </tr>`; } } else if (passage() === "Costs Budget") { income = "lastWeeksCashIncome"; expenses = "lastWeeksCashExpenses"; - profits = "lastWeeksCashProfits"; if (V[income][category] || V[expenses][category] || V.showAllEntries.costsBudget) { - V[profits][category] = V[income][category] + V[expenses][category]; return `<tr>\ <td>${title}</td>\ <td>${cashFormatColor(V[income][category])}</td>\ <td>${cashFormatColor(-Math.abs(V[expenses][category]))}</td>\ - <td>${cashFormatColor(V[profits][category])}</td>\ + <td>${cashFormatColor(V[income][category] + V[expenses][category])}</td>\ </tr>`; } } diff --git a/src/uncategorized/brothel.tw b/src/uncategorized/brothel.tw index becabde778b..aac3931c860 100644 --- a/src/uncategorized/brothel.tw +++ b/src/uncategorized/brothel.tw @@ -244,11 +244,11 @@ advertises by word of mouth. <</if>> Last week this - <<set $lastWeeksCashProfits.brothelAds = $lastWeeksCashIncome.brothelAds + $lastWeeksCashExpenses.brothelAds>> - <<if $lastWeeksCashProfits.brothelAds > 0>> - made you an extra <span class="cash inc"><<print cashFormat($lastWeeksCashProfits.brothelAds)>>,</span><<if _BL > 1>> as well as increasing business for your whores.<</if>> - <<elseif $lastWeeksCashProfits.brothelAds < 0>> - cost you <span class="cash dec"><<print cashFormat($lastWeeksCashProfits.brothelAds)>>,</span><<if _BL > 1>> but still increased business for your whores.<</if>> + <<set _adsProfit = $lastWeeksCashIncome.brothelAds + $lastWeeksCashExpenses.brothelAds>> + <<if _adsProfit > 0>> + made you an extra <span class="cash inc"><<print cashFormat(_adsProfit)>>,</span><<if _BL > 1>> as well as increasing business for your whores.<</if>> + <<elseif _adsProfit < 0>> + cost you <span class="cash dec"><<print cashFormat(_adsProfit)>>,</span><<if _BL > 1>> but still increased business for your whores.<</if>> <</if>> <div class="choices"> <<link "Manage brothel advertisements" "Brothel Advertisement">> diff --git a/src/uncategorized/costsBudget.js b/src/uncategorized/costsBudget.js index ad38b1d9fc1..6fbad7e4d0a 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 profits = "lastWeeksCashProfits"; const F = V.lastWeeksGatheredTotals; const table = document.createElement("table"); @@ -295,20 +294,7 @@ App.UI.Budget.Cost = function() { cell.append(cashFormatColorDOM(Math.trunc(V.lastWeeksCashExpenses.Total))); cell = row.insertCell(); - - V.lastWeeksCashProfits.Total = (V.lastWeeksCashIncome.Total + V.lastWeeksCashExpenses.Total); - // each "profit" item is calculated on this sheet, and there's two ways to generate a profit total: the - // difference of the income and expense totals, and adding all the profit items. If they aren't the same, I - // probably forgot to properly add an item's profit calculation to this sheet. - const total = hashSum(V.lastWeeksCashProfits) - V.lastWeeksCashProfits.Total; - if (V.lastWeeksCashProfits.Total !== total) { // Profits includes the total number of profits, so we have to subtract it back out - cell.append(cashFormatColorDOM(Math.trunc(total))); - const span = document.createElement('span'); - span.className = "red"; - span.textContent = "Fix profit calc"; - cell.append(span); - } - cell.append(cashFormatColorDOM(Math.trunc(V.lastWeeksCashProfits.Total))); + cell.append(cashFormatColorDOM(Math.trunc(V.lastWeeksCashIncome.Total + V.lastWeeksCashExpenses.Total))); flipColors(row); row = table.insertRow(); @@ -329,7 +315,7 @@ App.UI.Budget.Cost = function() { flipColors(row); row = table.insertRow(); - if ((V.cash - V.cashLastWeek) === V.lastWeeksCashProfits.Total) { + if ((V.cash - V.cashLastWeek) === (V.lastWeeksCashIncome.Total + V.lastWeeksCashExpenses.Total)) { cell = row.insertCell(); const span = document.createElement('span'); span.className = "green"; @@ -341,7 +327,7 @@ App.UI.Budget.Cost = function() { cell = row.insertCell(); cell = row.insertCell(); cell = row.insertCell(); - cell.append(cashFormatColorDOM((V.cash - V.cashLastWeek) - V.lastWeeksCashProfits.Total)); + cell.append(cashFormatColorDOM((V.cash - V.cashLastWeek) - (V.lastWeeksCashIncome.Total + V.lastWeeksCashExpenses.Total))); } flipColors(row); } @@ -376,7 +362,7 @@ App.UI.Budget.Cost = function() { cell.append(cashFormatColorDOM(-Math.abs(V[expenses][category]))); flipColors(row); cell = row.insertCell(); - cell.append(cashFormatColorDOM(V[profits][category])); + cell.append(cashFormatColorDOM(V[income][category] + V[expenses][category])); return row; } } @@ -393,7 +379,7 @@ App.UI.Budget.Cost = function() { cell = row.insertCell(); cell.append(cashFormatColorDOM(F[group].expenses, null)); cell = row.insertCell(); - cell.append(cashFormatColorDOM(F[group].profits, null)); + cell.append(cashFormatColorDOM(F[group].income + F[group].expenses, null)); return row; } } diff --git a/src/uncategorized/costsBudget.tw b/src/uncategorized/costsBudget.tw index 2e99762aa14..82e4afb5dc5 100644 --- a/src/uncategorized/costsBudget.tw +++ b/src/uncategorized/costsBudget.tw @@ -5,7 +5,6 @@ <<if def $lastWeeksCashIncome>> <<set $lastWeeksCashIncome.Total = 0>> <<set $lastWeeksCashExpenses.Total = 0>> - <<set $lastWeeksCashProfits.Total = 0>> <</if>> <<if ndef $showAllEntries>> diff --git a/src/uncategorized/repBudget.tw b/src/uncategorized/repBudget.tw index b07dae6ff9c..0d7fc6ae55d 100644 --- a/src/uncategorized/repBudget.tw +++ b/src/uncategorized/repBudget.tw @@ -7,10 +7,6 @@ <<set $lastWeeksRepIncome.Total = hashSum($lastWeeksRepIncome)>> <<set $lastWeeksRepExpenses.Total = hashSum($lastWeeksRepExpenses)>> -<<if def $lastWeeksRepProfits.Total>> - <<set $lastWeeksRepProfits.Total = 0>> -<</if>> - <<if ndef $showAllEntries>> <<set $showAllEntries = {costsBudget: 0, repBudget: 0}>> <</if>> @@ -31,12 +27,6 @@ Financial data currently unavailable. <<else>> -<<script>> -for (var i = 0; i < State.variables.lastWeeksRepIncome.length; i++){ - State.variables.lastWeeksRepProfits[i] = (State.variables.lastWeeksRepIncome[i] + State.variables.lastWeeksRepExpenses[i]); -} -<</script>> - <style> table.finances { /*table-layout: fixed;*/ @@ -182,18 +172,11 @@ for (var i = 0; i < State.variables.lastWeeksRepIncome.length; i++){ <td> <<print repFormat(Math.trunc($lastWeeksRepIncome.Total))>> </td> - <td> <<print repFormat(Math.trunc($lastWeeksRepExpenses.Total))>> </td> <td> - <<set $lastWeeksRepProfits.Total = ($lastWeeksRepIncome.Total + $lastWeeksRepExpenses.Total)>> - /* each "profit" item is calculated on this sheet, and there's two ways to generate a profit total: the difference of the income and expense totals, and adding all the profit items. If they aren't the same, I probably forgot to properly add an item's profit calculation to this sheet.*/ - <<if $lastWeeksRepProfits.Total != hashSum($lastWeeksRepProfits) - $lastWeeksRepProfits.Total>>/* The profits object includes the total number of profits, so we have to subtract it back out */ - <<print (num(Math.trunc(hashSum($lastWeeksRepProfits)-$lastWeeksRepProfits.Total)))>><br> - @@.red;Fix profit calc<br>@@ - <</if>> - <<print repFormat(Math.trunc($lastWeeksRepProfits.Total))>> + <<print repFormat(Math.trunc($lastWeeksRepIncome.Total + $lastWeeksRepExpenses.Total))>> </td> </tr> @@ -209,7 +192,7 @@ for (var i = 0; i < State.variables.lastWeeksRepIncome.length; i++){ <</if>></td> </tr> - <<if ($rep-$repLastWeek) == $lastWeeksRepProfits.Total>> + <<if ($rep-$repLastWeek) == $lastWeeksRepIncome.Total + $lastWeeksRepExpenses.Total>> <tr> @@.green;The books are balanced, <<= properTitle()>>!@@ </tr> @@ -219,7 +202,7 @@ for (var i = 0; i < State.variables.lastWeeksRepIncome.length; i++){ <td></td> <td></td> <td> - <<print repFormat(Math.trunc(($rep-$repLastWeek) - $lastWeeksRepProfits.Total))>> + <<print repFormat(Math.trunc(($rep-$repLastWeek) - ($lastWeeksRepIncome.Total + $lastWeeksRepExpenses.Total)))>> </td> </tr> <</if>> -- GitLab