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; +})(); diff --git a/src/neighbor/neighborInteract.js b/src/neighbor/neighborInteract.js index 2010275847a566ca5c972e642037cf2a5af8e1a3..3ef6a2f64f23b4f2bf62790d7f2665adbc17d7e8 100644 --- a/src/neighbor/neighborInteract.js +++ b/src/neighbor/neighborInteract.js @@ -255,7 +255,7 @@ App.Neighbor.Interact = (function() { * @param {string} itemName - the item name to check to see if the player already has this item * @param {string} category - the category to check to see if the player already has this item * @param {string} itemDisplay - a display name for a group of the item; as in, "a shipment of XXX" or "enough XXX" - * @param {function} property - adjusts the global property controlling whether this item has been acquired + * @param {function(): void} property - adjusts the global property controlling whether this item has been acquired * @param {number} [itemPrice] - the price the player should pay for the item; by default, basePrice (computed above) */ function addAcquisitionBlock(fsRequired, itemName, category, itemDisplay, property, itemPrice = basePrice) { @@ -277,8 +277,8 @@ App.Neighbor.Interact = (function() { const link = App.UI.DOM.link(`Divert an outgoing shipment of ${itemDisplay}`, (f) => { property(); cashX(forceNeg(itemPrice), "capEx"); - // replaceDetails(arcID); - cash changed, force passage transition for sidebar update - }, [], "Neighbor Interact"); + replaceDetails(arcID); + }); const div = App.UI.DOM.appendNewElement("div", container, link); App.UI.DOM.appendNewElement("span", div, `Will cost ${cashFormat(itemPrice)}`, "detail"); }