Session 16: Global 'Buy All Buildings' bulk-buy feature Added

Adds a global Buy All button to the Buildings panel that purchases as many
of every building type the player can afford at once, bringing Plants in line
with the Upgrades (Buy All) and Prestige (Buy Max) panels.

- game.js: Game.buyAllBuildings() loops buyMaxBuilding() per building type
- ui.js: UI.updateBuyAllBuildings() shows/hides + enables/disables live each tick
- index.html: Buy All button in Buildings panel header (reuses .upgrades-header/.buy-all-btn)
- Added headless test buy-all-buildings-test.mjs (31/31 pass); all existing suites green
This commit is contained in:
2026-08-24 18:00:27 +00:00
parent 44f55f0d24
commit cc1fa6bc4d
4 changed files with 96 additions and 1 deletions
+29
View File
@@ -131,6 +131,35 @@ const UI = {
card.classList.toggle('locked', locked);
}
// Toggle the global "Buy All buildings" button: show it once at least
// one building type is currently affordable, and disable it otherwise.
this.updateBuyAllBuildings();
},
/**
* Show/hide and enable/disable the global "Buy All buildings" button based
* on whether at least one building type is currently affordable (at least
* one unit). Read of game state only; never mutates it. Mirrors
* Game.buyAllBuildings / buyMaxBuilding semantics.
*/
updateBuyAllBuildings() {
const btn = document.getElementById('buy-all-buildings');
if (!btn) return;
let affordableAny = false;
for (const buildingId of Object.keys(BUILDINGS)) {
const count = Game.state.buildings[buildingId] || 0;
const locked = Game.state.totalStardust < BUILDINGS[buildingId].unlockAt && count === 0;
if (locked) continue;
if (Game.getMaxAffordable(buildingId) > 0) {
affordableAny = true;
break;
}
}
btn.style.display = affordableAny ? '' : 'none';
btn.disabled = !affordableAny;
},
/**