fix: bulkCost variable scoping in renderBuildings

bulkCost was declared with const inside if/else blocks but referenced
in the outer scope at line 2150 for ETA calculation. Hoisted the
declaration to the function scope so it's accessible throughout.
Fixes smoke test ReferenceError crash.
This commit is contained in:
Alexander Whitestone
2026-04-12 11:54:18 -04:00
parent e6dbe7e077
commit e85eddb00a

View File

@@ -2102,19 +2102,20 @@ function renderBuildings() {
let qty = G.buyAmount;
let afford = false;
let costStr = '';
let bulkCost = {};
if (qty === -1) {
const maxQty = getMaxBuyable(def.id);
afford = maxQty > 0;
if (maxQty > 0) {
const bulkCost = getBulkCost(def.id, maxQty);
bulkCost = getBulkCost(def.id, maxQty);
costStr = Object.entries(bulkCost).map(([r, a]) => `${fmt(a)} ${r}`).join(', ');
costStr = `x${maxQty}: ${costStr}`;
} else {
const singleCost = getBuildingCost(def.id);
costStr = Object.entries(singleCost).map(([r, a]) => `${fmt(a)} ${r}`).join(', ');
bulkCost = getBuildingCost(def.id);
costStr = Object.entries(bulkCost).map(([r, a]) => `${fmt(a)} ${r}`).join(', ');
}
} else {
const bulkCost = getBulkCost(def.id, qty);
bulkCost = getBulkCost(def.id, qty);
afford = true;
for (const [resource, amount] of Object.entries(bulkCost)) {
if ((G[resource] || 0) < amount) { afford = false; break; }