- JavaScript 69.9%
- HTML 29.1%
- Python 1%
The Renderer used to insert auto-buy buttons via renderGeneratorCards(), but on hydration that path is skipped. The SSR template was missing the auto-buy button entirely, so users saw Buy buttons but no Auto toggle. Fix: - SSR template now renders [data-auto] and [data-auto-prestige] buttons next to the Buy/Prestige buttons, with current automation state from game.state.automations - Renderer.attachListeners() also updates the button visuals immediately on toggle (matches the non-hydration tick handler) - Auto-prestige listener added to attachListeners (was missing) Tests: 156/156 + test-auto-buy-buttons |
||
|---|---|---|
| scripts | ||
| src | ||
| test | ||
| vendor | ||
| .gitignore | ||
| index.html | ||
| main.mjs | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
Idle Scaffold — Reference Architecture
A working browser idle game skeleton with the fifteen systems every idle game needs. v6 adds the AutoPrestigeManager (per-layer "double-or-nothing" automation, with cascade support across multi-layer prestige).
| Module | What it does |
|---|---|
utils/Decimal.js |
Big-number math (break_infinity.js) + number formatter |
core/EventBus.js |
Pub/sub so systems don't couple to each other |
core/GameState.js |
Single source of truth, with serialization |
core/GameLoop.js |
rAF-driven master tick |
generators/Generator.js |
Cost formula, production formula, max-affordable math |
prestige/PrestigeLayer.js |
Reset logic + currency earn preview |
achievements/AchievementSystem.js |
Mechanically-meaningful achievements (CC milk-upgrade pattern) |
synergies/SynergyRegistry.js |
Sparse, asymmetric, conditional cross-system bonuses |
upgrades/UpgradeSystem.js |
Three-shape upgrades (multiply / percentage / additive) with stack caps |
buffs/BuffSystem.js |
Temporary multiplicative buffs (Frenzy, Click Frenzy, etc.) |
events/GoldenCookie.js |
Random spawner with rarity-weighted buff kinds |
iap/TimeSkipManager.js |
Premium skip + ad-rewarded full-offline claim |
automation/AutoBuyManager.js |
Per-generator automated purchasing (1Hz decisions) |
automation/AutoPrestigeManager.js |
Per-layer "double-or-nothing" auto-prestige, with cascade |
offline/OfflineSimulator.js |
simulateSimple (constant-rate) + simulateAccurate (compressed-tick) |
saves/SaveManager.js |
localStorage autosave with dirty-count + debounce |
ui/Renderer.js |
Framework-free DOM rendering |
main.js |
Wires it all together with sample content |
Run it
cd idle-scaffold
python3 -m http.server 5173
# open http://localhost:5173
You'll see a 4-generator economy (Lemonade Stand, Newspaper, Pizza, Shrimp),
two prestige layers ("Hire Angels" → "Enter Eternity"), 6 achievements, and
3 synergies. Open DevTools console — window.__idle exposes the game state
for poking.
Tests
node test/smoke.mjs
132/132 passing, covering:
- Generator cost scaling (exponential)
- Max-affordable geometric-series formula
- Production with multiplicative multipliers
- Prestige sqrt scaling (Angels)
- Big-number precision past JS Number limit
- Achievement system — event-driven unlock, idempotency, cumulative bonus math
- Synergy registry — sparse, asymmetric, conditional multipliers
- Two-layer prestige — Angels gate, reset, Eternity gate, reset, re-gating
- Upgrade system — three shapes, maxStack enforcement, cost scaling, insufficient-funds check, fullBonus aggregator shape
- Buff system — Frenzy/Click-Frenzy/Lucky multiplicative stacking, expiry via tick, prestige clears
- Golden Cookie — random spawn with rarity weights, 13s lifetime, click-to-collect, expire-on-tick, prestige clears
- Time-skip IAP — gem cost calculation, deducts premium currency, offline-cap enforcement, ad-rewarded 2x full-offline
- AutoBuyManager — toggle, plan(), check-interval throttle, bulk geometric-sum purchase, stats tracking, disableAll
- simulateAccurate — compressed-tick simulation, auto-buy integration, cap enforcement, transition counting
- AutoPrestigeManager — toggle, double-or-nothing decision, cooldown, cascade across layers, disableAll
Architecture decisions
-
No framework. Vanilla JS + a small render loop. Idle UIs update at most every 50-100ms — a 5kb renderer is enough. Migrate to Svelte/React when you have 50+ components, not before.
-
Event bus over direct calls. Every cross-system update goes through
EventBus.emit(). Achievement system, UI, saves, and analytics stay decoupled. This is the difference between an idle codebase that scales to 10 prestige layers and one that doesn't. -
Decimal everywhere.
break_infinity.js(Patashu) — fast, scales to 1e9e15. For 10^^N numbers (Antimatter Dimensions late game) swap tobreak_eternity.js. Don't use raw JS Number — you lose precision at 1e16 and overflow at 1.79e308. -
rAF-driven tick, clamped to 1s. Tabs in the background throttle rAF to ~1Hz. We clamp
dtto 1000ms so a 30-minute background tab doesn't credit 30 minutes of production in one frame. -
Save debouncing on events, not on wall-clock. The save manager listens to GENERATOR_BOUGHT / UPGRADE_BOUGHT / PRESTIGE events and marks dirty. Autosave fires every 10s OR after 5 mutations. This gives burst protection (rapid clicking won't lose data) without thrashing localStorage.
-
Offline simulation is decoupled.
OfflineSimulatortakes the current state and a time delta, returns a report. Swap in thesimulateAccurate()implementation later without touching the game loop or state code. -
Achievements are mechanically meaningful. Cookie Clicker's milk upgrades tie to achievement % — we follow the same pattern. Each achievement contributes a small multiplicative bonus (1-10%) so the cumulative effect of 50+ achievements is the "achievement bonus." Cosmetic achievements are wasted design space in a no-failure-state game.
-
Synergies are sparse and asymmetric. 5-8 meaningful ones, not 20+. Each is a function from state → multiplier. Conditional ones ("only while you have >50 newspaper") force active management and create the "feed" pattern of A-boosts-B-boosts-C.
Multiplier stack
All bonuses combine multiplicatively into a single multipliers Decimal that
gets multiplied into production. The formula:
production = ( base * owned + upgAdd ) *
(1 + 0.02 * angels) ← Layer 0 passive
* (1 + 0.05 * eternity_points) ← Layer 1 passive
* achievementBonus() ← All unlocked achievements
* synergyBonus(state) ← All active synergies
* upgMultiply ← All stackable multiply upgrades
* buffBonus ← Active Golden Cookie buffs
* (1 + (upgPct + otherPct) / 100) ← Sum-of-percentages bucket
This is the single most important property of the architecture: one math formula, one source of truth, every system contributes by multiplying.
Pitfalls the scaffold handles for you
- ✅ Decimal precision (1e9e15+)
- ✅ Save format versioning
- ✅ Save errors don't crash the game loop
- ✅ Tab-backgrounding doesn't trigger massive catch-up
- ✅ EventBus exceptions don't kill the loop
- ✅ Number formatting across all size regimes
- ✅ Achievement idempotency (re-check doesn't double-fire)
- ✅ Multi-layer prestige with re-gating after reset
- ✅ AutoBuy / AutoPrestige with check-interval throttling and cascade
What to add next
- Cloud saves — drop in a
CloudSaveManagerthat mirrorsSaveManager. - IAP / real-money monetization — requires app-store SDKs, not in scaffold.
- Random-event offline — weighted random outcomes during offline sim (Tideward's "found a rare ore!" pattern).
- Multi-generator auto-buy strategies — highest-mult-per-cost, by-rate-of-
return, etc. Scaffold ships with cheapest-affordable; pluggable via the
strategyconstructor arg. - Auto-prestige integration with offline sim —
simulateAccurateshould fire auto-prestige during the simulated window when both are enabled.