Session 15: Buy Max Prestige Upgrades (bulk-buy for prestige upgrades) + fix missing Stellar Essence spend
This commit is contained in:
+47
-1
@@ -43,6 +43,15 @@ const PrestigeUI = {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Buy Max prestige upgrades button - buy every affordable prestige
|
||||
// upgrade at once, paid from Stellar Essence.
|
||||
const buyMaxBtn = document.getElementById('buy-all-prestige');
|
||||
if (buyMaxBtn) {
|
||||
buyMaxBtn.addEventListener('click', () => {
|
||||
Game.buyMaxPrestigeUpgrades();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -119,7 +128,44 @@ const PrestigeUI = {
|
||||
if (prestigeTab?.classList.contains('active')) {
|
||||
this.renderPrestigeUpgrades();
|
||||
}
|
||||
}
|
||||
|
||||
// Show/hide the "Buy Max" button based on whether any unowned prestige
|
||||
// upgrade is currently affordable with Stellar Essence. Read-only.
|
||||
this.updateBuyMaxPrestigeButton();
|
||||
},
|
||||
|
||||
/**
|
||||
* Show/hide and enable/disable the "Buy Max" prestige-upgrades button
|
||||
* depending on whether at least one unowned, requirement-met prestige
|
||||
* upgrade is currently affordable with Stellar Essence. Read of game state
|
||||
* only; never mutates it. Mirrors Game.buyMaxPrestigeUpgrades /
|
||||
* PRESTIGE.buyUpgrade semantics.
|
||||
*/
|
||||
updateBuyMaxPrestigeButton() {
|
||||
const btn = document.getElementById('buy-all-prestige');
|
||||
if (!btn) return;
|
||||
|
||||
let affordableAny = false;
|
||||
for (const [id, upgrade] of Object.entries(PRESTIGE_UPGRADES)) {
|
||||
if ((Game.state.prestigeUpgrades || []).includes(id)) continue;
|
||||
if ((Game.state.stellarEssence || 0) < upgrade.cost) continue;
|
||||
if (upgrade.requirements) {
|
||||
let met = true;
|
||||
for (const [reqId, reqCount] of Object.entries(upgrade.requirements)) {
|
||||
if ((Game.state.buildings[reqId] || 0) < reqCount) {
|
||||
met = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!met) continue;
|
||||
}
|
||||
affordableAny = true;
|
||||
break;
|
||||
}
|
||||
|
||||
btn.style.display = affordableAny ? '' : 'none';
|
||||
btn.disabled = !affordableAny;
|
||||
},
|
||||
};
|
||||
|
||||
window.PrestigeUI = PrestigeUI;
|
||||
|
||||
Reference in New Issue
Block a user