From 7063822241857d6ebe094cd17ed457f335abdb0f Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Thu, 13 Aug 2020 17:32:19 -0700 Subject: [PATCH] Reflect all reputation and cash changes immediately in the sidebar --- src/interaction/policies/policies.js | 1 - src/js/economyJS.js | 5 +++++ src/js/utilsFC.js | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/interaction/policies/policies.js b/src/interaction/policies/policies.js index 4ce8bbfc749..6ef1341ffbd 100644 --- a/src/interaction/policies/policies.js +++ b/src/interaction/policies/policies.js @@ -210,7 +210,6 @@ globalThis.policy = function(category) { if (!["EducationPolicies"].includes(category)) { repX(-1000, "policies"); } - UIBar.update(); } } }; diff --git a/src/js/economyJS.js b/src/js/economyJS.js index 074594e69a2..3b520bae0e8 100644 --- a/src/js/economyJS.js +++ b/src/js/economyJS.js @@ -2343,6 +2343,9 @@ globalThis.cashX = function(cost, what, who) { } } } + + App.Utils.scheduleSidebarRefresh(); + return cost; }; @@ -2401,6 +2404,8 @@ globalThis.repX = function(rep, what, who) { V.rep = 0; } + App.Utils.scheduleSidebarRefresh(); + return rep; }; diff --git a/src/js/utilsFC.js b/src/js/utilsFC.js index 78e753189fa..42be8f0261f 100644 --- a/src/js/utilsFC.js +++ b/src/js/utilsFC.js @@ -3442,3 +3442,25 @@ globalThis.deflate = function(slave) { slave.cumSource = 0; SetBellySize(slave); }; + +/** Notify the game that the sidbar needs to be refreshed as soon as possible, but do not do it immediately. + * This allows us to call this function repeatedly without impacting performance (for example, from repX() and cashX()). + * The game will redraw the sidebar exactly once, as soon as all the scripts have finished executing. + */ +App.Utils.scheduleSidebarRefresh = (function() { + let refresh = false; + + function updateSidebar() { + refresh = false; + UIBar.update(); + } + + function schedule() { + if (!refresh) { + refresh = true; + setTimeout(updateSidebar, 0); + } + } + + return schedule; +})(); -- GitLab