diff --git a/src/interaction/policies/policies.js b/src/interaction/policies/policies.js index 4ce8bbfc749d4f3585b456ba09b5bff59a2de924..6ef1341ffbdfb6440bdeb349ddf877b7c7b438c4 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 074594e69a210d70c30f6b1648ec21411bd29f50..3b520bae0e84b9b2b8219c3a4a4b6c8d289f72ed 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 78e753189fa6a97d5c7ea1f6e0287a9ea01f108e..42be8f0261f54d552690c62f43936d56d61a3e20 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; +})();