diff --git a/game.js b/game.js index 328c298..3c391b3 100644 --- a/game.js +++ b/game.js @@ -866,32 +866,26 @@ function setBuyAmount(amt) { function getMaxBuyable(id) { const def = BDEF.find(b => b.id === id); if (!def) return 0; - let count = G.buildings[id] || 0; + const count = G.buildings[id] || 0; + // Simulate purchases WITHOUT mutating G — read-only calculation + let tempResources = {}; + for (const r of Object.keys(def.baseCost)) { + tempResources[r] = G[r] || 0; + } let bought = 0; + let simCount = count; while (true) { - const cost = {}; - for (const [resource, amount] of Object.entries(def.baseCost)) { - cost[resource] = Math.floor(amount * Math.pow(def.costMult, count)); - } let canAfford = true; - for (const [resource, amount] of Object.entries(cost)) { - if ((G[resource] || 0) < amount) { canAfford = false; break; } + for (const [resource, amount] of Object.entries(def.baseCost)) { + const cost = Math.floor(amount * Math.pow(def.costMult, simCount)); + if ((tempResources[resource] || 0) < cost) { canAfford = false; break; } } if (!canAfford) break; - // Spend from temporary copy - for (const [resource, amount] of Object.entries(cost)) { - G[resource] -= amount; - } - count++; - bought++; - } - // Refund: add back what we spent - let count2 = G.buildings[id] || 0; - for (let i = 0; i < bought; i++) { for (const [resource, amount] of Object.entries(def.baseCost)) { - G[resource] += Math.floor(amount * Math.pow(def.costMult, count2)); + tempResources[resource] -= Math.floor(amount * Math.pow(def.costMult, simCount)); } - count2++; + simCount++; + bought++; } return bought; } @@ -2417,7 +2411,7 @@ function initGame() { log('Click WRITE CODE or press SPACE to start.'); log('Build AutoCode for passive production.'); log('Watch for Research Projects to appear.'); - log('Keys: SPACE=Code S=Sprint 1-4=Ops B=Buy x1/10/MAX E=Export I=Import Ctrl+S=Save'); + log('Keys: SPACE=Code S=Sprint 1-4=Ops B=Buy x1/10/MAX E=Export I=Import Ctrl+S=Save ?=Help'); log('Tip: Click fast for combo bonuses! 10x=ops, 20x=knowledge, 30x+=bonus code.'); } @@ -2448,8 +2442,27 @@ window.addEventListener('load', function () { setInterval(updateEducation, 10000); }); +// Help overlay +function toggleHelp() { + const el = document.getElementById('help-overlay'); + if (!el) return; + const isOpen = el.style.display === 'flex'; + el.style.display = isOpen ? 'none' : 'flex'; +} + // Keyboard shortcuts window.addEventListener('keydown', function (e) { + // Help toggle (? or /) — works even in input fields + if (e.key === '?' || e.key === '/') { + // Only trigger ? when not typing in an input + if (e.target === document.body || e.key === '?') { + if (e.key === '?' || (e.key === '/' && e.target === document.body)) { + e.preventDefault(); + toggleHelp(); + return; + } + } + } if (e.code === 'Space' && e.target === document.body) { e.preventDefault(); writeCode(); @@ -2468,6 +2481,10 @@ window.addEventListener('keydown', function (e) { if (e.code === 'KeyS') activateSprint(); if (e.code === 'KeyE') exportSave(); if (e.code === 'KeyI') importSave(); + if (e.code === 'Escape') { + const el = document.getElementById('help-overlay'); + if (el && el.style.display === 'flex') toggleHelp(); + } }); // Ctrl+S to save (must be on keydown to preventDefault) diff --git a/index.html b/index.html index 4a190b7..58e26a2 100644 --- a/index.html +++ b/index.html @@ -170,6 +170,27 @@ Events Resolved: 0
+You became very good at what you do.