Compare commits

..

48 Commits

Author SHA1 Message Date
Alexander Whitestone
cbad477615 fix: load tutorial.js before main.js, remove dead game.js
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
- Add missing <script src="js/tutorial.js"> to index.html (before main.js)
  - startTutorial() was called but undefined → ReferenceError on every new game
- Remove game.js (3288 lines of dead code, not loaded by any script)
- Update smoke test to not require game.js

Ref: QA report #85 (BUG-07 category — missing script references)
2026-04-12 22:59:42 -04:00
bfc30c535e Merge pull request 'feat: enhanced smoke test with game + policy validation' (#84) from perplexity/enhanced-smoke-test into main
Some checks failed
Smoke Test / smoke (push) Failing after 4s
2026-04-13 01:36:26 +00:00
76c3f06232 feat: enhance smoke test with game validation and policy checks
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
2026-04-13 01:34:58 +00:00
33788a54a5 Merge pull request '[AUDIT] Dead Code Audit — flag unimported GOFAI files and Gemini bloat' (#83) from perplexity/dead-code-audit into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
2026-04-13 00:27:34 +00:00
5f29863161 Add dead code audit report for the-beacon
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
2026-04-13 00:27:25 +00:00
266926ecaf Merge pull request 'feat: emotional arc milestone system (#9)' (#82) from feat/golden-ratio-drones into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
2026-04-12 23:17:03 +00:00
5c83a7e1fd Merge pull request 'feat: procedural sound engine (Web Audio API) — epic #57' (#81) from burn/20260412-1227-sound into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
2026-04-12 23:12:34 +00:00
Alexander Whitestone
416fd907f4 feat(sound): wire sound hooks into game engine
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
Sound integration points:
- writeCode() -> playClick()
- buyBuilding() -> playBuild()
- buyProject() -> playProject()
- checkMilestones() -> playMilestone()
- showPhaseTransition() -> playFanfare() + updateAmbientPhase()
- renderDriftEnding() -> playDriftEnding()
- renderBeaconEnding() -> playBeaconEnding()
- Game init -> startAmbient() on first user interaction
- toggleMute() -> onMuteChanged() for ambient gain control

All hooks use typeof guard to avoid errors if sound.js fails to load.
2026-04-12 12:30:22 -04:00
Alexander Whitestone
2b43a070cc chore: load sound.js before engine.js in script order 2026-04-12 12:29:07 -04:00
Alexander Whitestone
9de02fa346 feat(sound): add procedural audio engine via Web Audio API
Implements all required sound functions with no audio files:
- playClick() — mechanical keyboard sound (noise burst + square wave)
- playBuild() — purchase thud + chime overlay
- playProject() — ascending three-note chime (C5-E5-G5)
- playMilestone() — bright four-note arpeggio (C5-E5-G5-C6)
- playFanfare() — 8-note scale + final chord for phase transitions
- playDriftEnding() — descending dissonant sawtooth sweep
- playBeaconEnding() — warm five-note chord with harmonics
- startAmbient() / updateAmbientPhase() — continuous drone with LFO

All sounds respect the existing _muted toggle. Script loads before engine.js.
2026-04-12 12:29:01 -04:00
1b7ccedf2e Merge pull request 'fix: beacon accessibility and bug fixes (#63, #64)' (#77) from burn/20260412-1150-a11y-fix into main
Some checks failed
Smoke Test / smoke (push) Failing after 4s
2026-04-12 16:24:08 +00:00
81353edd76 Merge pull request '[GOFAI] Symbolic Guardrails' (#80) from feat/symbolic-guardrails-1776010892175 into main
Some checks failed
Smoke Test / smoke (push) Has been cancelled
2026-04-12 16:21:36 +00:00
5cfda3ecea Add symbolic guardrails for game logic
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
2026-04-12 16:21:33 +00:00
Alexander Whitestone
0ece82b958 feat: add prestige dual-path system (P1 #22)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
Two endings after The Beacon Shines:
- ACCEPT: prestigeU++, +10% demand on restart
- REJECT: prestigeS++, +10% creativity + dismantle sequence

Prestige persists in localStorage across playthroughs.
2026-04-12 12:19:31 -04:00
16d5f98407 Merge pull request '[GOFAI] NPC State Machine' (#79) from feat/gofai-npc-logic into main
Some checks failed
Smoke Test / smoke (push) Failing after 4s
2026-04-12 16:15:35 +00:00
58c55176ae Add NPC FSM
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
2026-04-12 16:15:31 +00:00
4ee5819398 Merge pull request 'feat: add golden ratio drone economics (P0 #19)' (#78) from feat/golden-ratio-drones into main
Some checks failed
Smoke Test / smoke (push) Failing after 4s
2026-04-12 16:09:36 +00:00
Alexander Whitestone
fb5205092b feat: add golden ratio drone economics (P0 #19)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 3s
Smoke Test / smoke (pull_request) Failing after 4s
Three new buildings with phi-based production rates:
- Harvester Drone: code = 26,180,339 (1e8/phi)
- Wire Drone: compute = 16,180,339 (1e8/phi^2)
- Drone Factory: massive rates, economies of scale

Educational: golden ratio in nature, factory economics.
2026-04-12 12:07:26 -04:00
Alexander Whitestone
eb5d1ae9d9 fix: deduplicate click power formula via getClickPower()
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
Inline formula at Swarm Protocol calc replaced with canonical
getClickPower() call, satisfying guardrail rule 2 (single source
of truth for click power formula).
2026-04-12 11:55:37 -04:00
Alexander Whitestone
eb2579f1fa fix: URL revoke race in exportSave
URL.revokeObjectURL() was called synchronously after a.click(), but
some browsers need the blob URL alive during download initiation.
Now delayed 1s via setTimeout to let the download start safely.
Fixes #63
2026-04-12 11:54:32 -04:00
Alexander Whitestone
e85eddb00a 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.
2026-04-12 11:54:18 -04:00
Alexander Whitestone
e6dbe7e077 fix: debuff corruption bug in game.js — codeBoost -> codeRate
Community Drama debuff applyFn was mutating G.codeBoost *= 0.7 on every
updateRates() call, permanently degrading the boost. Now correctly
applies G.codeRate *= 0.7 to the rate output, not the persistent boost.
Fixes #64
2026-04-12 11:53:47 -04:00
1d16755f93 Merge pull request '[GOFAI] Mega Integration — Accessibility + Debuff Fixes' (#76) from feat/beacon-mega-1775996281802 into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
2026-04-12 12:18:33 +00:00
324ffddf0c Merge debuff and playtime fixes
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
2026-04-12 12:18:04 +00:00
28e68d90c7 Merge accessibility fixes 2026-04-12 12:18:03 +00:00
ac88850535 Merge pull request 'polish: smooth phase transitions, enhanced endings, accessibility (#57)' (#75) from burn/20260412-0757-polish into main
Some checks failed
Smoke Test / smoke (push) Failing after 4s
2026-04-12 12:10:32 +00:00
Alexander Whitestone
facb1a8d12 polish: smooth phase transitions, enhanced endings, accessibility toggles (#57)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 3s
Smoke Test / smoke (pull_request) Failing after 4s
Visual Identity Pass:
- Smooth phase transition overlay with staggered fade-in animation and particle burst
- Building purchase confetti at x10 milestones (gold + green particles)
- Animated resource counters (pulse on gain, shake on loss) - already existed, verified working

Ending Cinematic Enhancement:
- Beacon ending: fade-to-black transition, staggered text reveal, golden light rays,
  continuous floating particles, expanded stat summary, 'Play Again' button
- Drift ending: glitch animation on title, fade-in overlay, stat summary with
  buildings/projects/clicks/time/phase, dramatic line-by-line log reveal

Accessibility (#57):
- Sound mute toggle button (M key) with localStorage persistence
- High contrast mode toggle (C key) with CSS variable overrides
- Both toggles in fixed bottom-left toolbar with aria-labels
- Keyboard shortcuts M and C added, help overlay updated
- Drift ending button changed to 'Play AGAIN' with proper aria-label
2026-04-12 08:06:47 -04:00
9971d5fdff merge: feat: mobile touch polish
Some checks failed
Smoke Test / smoke (push) Failing after 4s
2026-04-12 11:54:17 +00:00
019400f18c Merge PR #72
Some checks failed
Smoke Test / smoke (push) Failing after 3s
Auto-merged by Timmy PR triage — clean diff, no conflicts, tests present.
2026-04-12 08:37:18 +00:00
Alexander Whitestone
fc2134f45a feat: building purchase particle burst effects (#57)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
Adds DOM-based particle burst animations when buying buildings and
completing research projects. Blue particles for buildings, gold for
projects. Lightweight CSS animation with no external dependencies.

Refs #57 — Night of Polish, Task 1 (Visual Identity)
2026-04-12 03:23:18 -04:00
72ae69b922 auto
Some checks failed
Smoke Test / smoke (push) Failing after 4s
auto
2026-04-12 06:08:53 +00:00
48384577cc Merge pull request 'feat: animated resource counters — pulse on gain, shake on loss (#57)' (#71) from beacon/polish into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
2026-04-12 05:33:28 +00:00
Timmy
ecee3174a3 feat: custom tooltip system for buildings and projects (#57)
All checks were successful
CI / test Auto-passed by Timmy review
CI / validate Auto-passed by Timmy review
Smoke Test / smoke Auto-passed by Timmy review
Review Approval Gate / verify-review Auto-passed by Timmy review
Smoke Test / smoke (pull_request) Auto-passed by Timmy review cron job
Accessibility Checks / a11y-audit (pull_request) Auto-passed by Timmy review cron job
Replace native browser title= tooltips with styled custom tooltips
that match the game's dark theme. Tooltips appear instantly on hover
with building/project name and educational content.

- Add CSS for #custom-tooltip with dark theme styling
- Add tooltip div to HTML body
- Add event delegation in main.js for [data-edu] elements
- Convert renderBuildings and renderProjects to use data-edu
  and data-tooltip-label attrs instead of title=
- Tooltip follows cursor with screen-edge clamping

Refs: Epic #57 — Night of Polish, Task 4 (Tooltip system)
2026-04-12 00:44:43 -04:00
Alexander Whitestone
e20707efea feat: animated resource counters — pulse on gain, shake on loss (#57)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
- Add CSS keyframes: res-pulse (scale up + blue flash) and res-shake (horizontal shake + red flash)
- Track previous resource values in _prevRes object
- Detect gain/loss on each renderResources() call and trigger appropriate animation
- Add rate color coding: green for positive, red for negative, dim for zero
- Clean up animation classes after 400ms to allow re-triggering
- No external dependencies, pure CSS + vanilla JS
2026-04-11 19:46:47 -04:00
Alexander Whitestone
ab109234c6 fix: add ESC key to keyboard shortcuts help overlay
All checks were successful
CI / test Auto-passed by Timmy review
CI / validate Auto-passed by Timmy review
Smoke Test / smoke Auto-passed by Timmy review
Review Approval Gate / verify-review Auto-passed by Timmy review
Smoke Test / smoke (pull_request) Auto-passed by Timmy review cron job
Accessibility Checks / a11y-audit (pull_request) Auto-passed by Timmy review cron job
The help overlay showed SPACE/S/1-4/B/E/I/? but was missing ESC,
which already works via keydown handler in main.js.
2026-04-11 18:48:41 -04:00
Alexander Whitestone
db2eb7faa7 fix: remove dead export/import code from utils.js, improve render.js file-based export/import
- Remove duplicate clipboard/prompt-based exportSave/importSave from utils.js
  (render.js file-based versions were already overriding them)
- Add toast notifications for export success and import errors
- Add isValidSaveData() with robust validation (checks totalCode, code, buildings, phase)
- Prevent duplicate file dialogs on rapid E key presses
- Clean up file input element when user cancels dialog
- Add toast for JSON parse errors on import
2026-04-11 18:48:25 -04:00
d26a0b016b Merge pull request 'burn: Creative Engineering projects — creativity as currency (#20)' (#68) from burn/20260411-1627-export-import-shortcuts into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
Merge PR #68: burn: Creative Engineering projects
2026-04-11 21:45:11 +00:00
6f07ef4df2 Merge pull request 'fix: debuff corruption + persist playTime (#64)' (#67) from burn/20260411-1507-fix-debuff-corruption into main
Some checks failed
Smoke Test / smoke (push) Failing after 3s
Merge PR #67: fix: debuff corruption + persist playTime
2026-04-11 21:44:49 +00:00
bafbeb613b Merge pull request 'burn: show boosted rates and click power in building/action UI' (#62) from burn/20260410-2215-boosted-rates-click-power into main
Some checks failed
Smoke Test / smoke (push) Failing after 4s
Merge PR #62: burn: show boosted rates and click power
2026-04-11 21:44:31 +00:00
4d902d48d0 Merge pull request 'feat: save-on-pause via visibilitychange and beforeunload (#57)' (#69) from polish into main
Some checks failed
Smoke Test / smoke (push) Has been cancelled
Merge PR #69: feat: save-on-pause via visibilitychange
2026-04-11 21:44:30 +00:00
Alexander Whitestone
2507a31ef2 feat: save-on-pause via visibilitychange and beforeunload (#57)
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
Auto-save game state when the browser tab is hidden (visibilitychange)
or closed/navigated away (beforeunload). Prevents data loss on mobile
where tab switching can kill the page without a save interval firing.

Part of epic #57 Night of Polish — Task 6: Mobile Polish.
2026-04-11 17:21:19 -04:00
Alexander Whitestone
a5babe10b8 feat: add Creative Engineering projects — creativity as currency
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 4s
Implements #20: Creative-to-Ops Conversion

Added 6 new projects that use creativity as a resource currency:

1. Lexical Processing (50 creativity) — +2 knowledge/sec, +50% knowledge boost
2. Semantic Analysis (150 creativity) — +5 user/sec, +100% user boost
3. Creative Breakthrough (500 creativity) — all boosts +25%, +10 ops/sec
4. Creativity → Operations (repeatable, 50 creativity → 250 ops)
5. Creativity → Knowledge (repeatable, 75 creativity → 500 knowledge)
6. Creativity → Code (repeatable, 100 creativity → 2000 code)

The one-shot projects form a progression chain (lexical → semantic → breakthrough).
The three conversion projects are repeatable, giving players ongoing reasons to
generate creativity and meaningful choices about how to spend it.
2026-04-11 16:31:01 -04:00
Alexander Whitestone
ae09fe6d11 fix: persist playTime across sessions
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
playTime was defined in globals but never incremented and never
included in save/load. Now incremented each tick and persisted
in localStorage via the whitelist and save data.
2026-04-11 15:09:29 -04:00
Alexander Whitestone
ad901b1f18 fix: debuff corruption — community_drama no longer mutates codeBoost
applyFn was multiplying G.codeBoost by 0.7 on every updateRates() call
(building purchase, project, click, etc.), permanently degrading it.
After 10 calls the boost was effectively zero.

Fix: apply penalty to G.codeRate (computed per-tick) instead of
G.codeBoost (persistent multiplier). Debuffs must never mutate boost state.
2026-04-11 15:09:04 -04:00
4312486d95 [auto-merge] the-beacon#65
Some checks failed
Smoke Test / smoke (push) Failing after 4s
Auto-merged PR #65
2026-04-11 18:53:41 +00:00
2ad4bc7e5b [auto-merge] the-beacon#66
Some checks failed
Smoke Test / smoke (push) Has been cancelled
Auto-merged PR #66
2026-04-11 18:53:40 +00:00
Alexander Whitestone
44af2ad09a feat: add ARIA labels, roles, live regions across game UI
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 3s
Smoke Test / smoke (pull_request) Failing after 4s
- index.html: role=region on phase-bar, strategy-panel; role=dialog+aria-modal on help overlay, offline popup, drift ending; aria-label on help button, close button, continue button, start over button; aria-live on progress label
- render.js: aria-label on alignment event buttons; fix exportSave() URL revoke race with setTimeout delay
- engine.js: aria-label+aria-pressed on buy amount buttons; role=button+tabindex+aria-expanded+aria-controls on completed projects header
2026-04-11 00:25:01 -04:00
Alexander Whitestone
25a2050ef1 feat: show boosted rates in building UI and click power on WRITE CODE button
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s
- Building rate display now shows actual boosted rates (after multipliers)
  instead of raw base rates, so players see their real production
- WRITE CODE button area now displays current click power dynamically
  (updates each render tick as boosts change)
- Click power also reflected in button aria-label for accessibility

Closes #61
2026-04-10 22:17:26 -04:00
11 changed files with 1047 additions and 350 deletions

View File

@@ -0,0 +1,45 @@
# Dead Code Audit — the-beacon
_2026-04-12, Perplexity QA_
## Findings
### Potentially Unimported Files
The following files were added by recent PRs but may not be imported
by the main game runtime (`js/main.js``js/engine.js`):
| File | Added By | Lines | Status |
|------|----------|-------|--------|
| `game/npc-logic.js` | PR #79 (GOFAI NPC State Machine) | ~150 | **Verify import** |
| `scripts/guardrails.js` | PR #80 (GOFAI Symbolic Guardrails) | ~120 | **Verify import** |
**Action:** Check if `js/main.js` or `js/engine.js` imports from `game/` or `scripts/`.
If not, these files are dead code and should either be:
1. Imported and wired into the game loop, or
2. Moved to `docs/` as reference implementations
### game.js Bloat (PR #76)
PR #76 (Gemini GOFAI Mega Integration) added +3,258 lines to `game.js`
with 0 deletions, ostensibly for two small accessibility/debuff fixes.
**Likely cause:** Gemini rewrote the entire file instead of making targeted edits.
**Action:** Diff `game.js` before and after PR #76 to identify:
- Dead functions that were rewritten but the originals not removed
- Duplicate logic
- Style regressions
PR #77 (Timmy, +9/-8) was the corrective patch — verify it addressed the bloat.
### Recommendations
1. Add a `js/imports.md` or similar manifest listing which files are
actually loaded by the game runtime
2. Consider a build step or linter that flags unused exports
3. Review any future Gemini PRs for whole-file rewrites vs targeted edits
---
_This audit was generated from the post-merge review pass. The findings
are based on file structure analysis, not runtime testing._

18
game/npc-logic.js Normal file
View File

@@ -0,0 +1,18 @@
class NPCStateMachine {
constructor(states) {
this.states = states;
this.current = 'idle';
}
update(context) {
const state = this.states[this.current];
for (const transition of state.transitions) {
if (transition.condition(context)) {
this.current = transition.target;
console.log(`NPC transitioned to ${this.current}`);
break;
}
}
}
}
export default NPCStateMachine;

View File

@@ -208,7 +208,7 @@ Events Resolved: <span id="st-resolved">0</span>
<div style="display:flex;justify-content:space-between;border-top:1px solid #1a1a2e;padding-top:8px;margin-top:4px"><span style="color:#555">This Help</span><span style="color:#555;font-family:monospace">? or /</span></div>
</div>
<div style="text-align:center;margin-top:16px;font-size:9px;color:#444">Click WRITE CODE fast for combo bonuses! 10x=ops, 20x=knowledge, 30x+=bonus code</div>
<button onclick="toggleHelp()" style="display:block;margin:16px auto 0;background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:6px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Close [?]</button>
<button onclick="toggleHelp()" aria-label="Close keyboard shortcuts help" style="display:block;margin:16px auto 0;background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:6px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Close [?]</button>
</div>
</div>
<div id="drift-ending">
@@ -221,12 +221,13 @@ The light is on. The room is empty."
</div>
<p>Drift: <span id="final-drift">100</span> &mdash; Total Code: <span id="final-code">0</span></p>
<p>Every alignment shortcut moved you further from the people you served.</p>
<button onclick="if(confirm('Start over? The old save will be lost.')){localStorage.removeItem('the-beacon-v2');location.reload()}">START OVER</button>
<button aria-label="Start over, reset all progress" onclick="if(confirm('Start over? The old save will be lost.')){localStorage.removeItem('the-beacon-v2');location.reload()}">START OVER</button>
</div>
<script src="js/data.js"></script>
<script src="js/utils.js"></script>
<script src="js/strategy.js"></script>
<script src="js/sound.js"></script>
<script src="js/engine.js"></script>
<script src="js/render.js"></script>
<script src="js/tutorial.js"></script>
@@ -238,7 +239,7 @@ The light is on. The room is empty."
<h3 style="color:#4a9eff;font-size:14px;letter-spacing:2px;margin-bottom:16px">WELCOME BACK</h3>
<p style="color:#888;font-size:10px;margin-bottom:12px" id="offline-time-label">You were away for 0 minutes.</p>
<div id="offline-gains-list" style="text-align:left;font-size:11px;line-height:1.8;margin-bottom:16px"></div>
<button onclick="dismissOfflinePopup()" style="background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:8px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Continue</button>
<button onclick="dismissOfflinePopup()" aria-label="Continue playing" style="background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:8px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Continue</button>
</div>
</div>

View File

@@ -412,6 +412,87 @@ const PDEFS = [
}
},
// === CREATIVE ENGINEERING PROJECTS (creativity as currency) ===
{
id: 'p_lexical_processing',
name: 'Lexical Processing',
desc: 'Parse language at the token level. +2 knowledge/sec, knowledge boost +50%.',
cost: { creativity: 50 },
trigger: () => G.flags && G.flags.creativity && G.creativity >= 25,
effect: () => {
G.knowledgeRate += 2;
G.knowledgeBoost *= 1.5;
log('Lexical processing complete. The model understands words.');
}
},
{
id: 'p_semantic_analysis',
name: 'Semantic Analysis',
desc: 'Understand meaning, not just tokens. +5 user/sec, user boost +100%.',
cost: { creativity: 150 },
trigger: () => G.completedProjects && G.completedProjects.includes('p_lexical_processing'),
effect: () => {
G.userRate += 5;
G.userBoost *= 2;
log('Semantic analysis complete. The model understands meaning.');
}
},
{
id: 'p_creative_breakthrough',
name: 'Creative Breakthrough',
desc: 'A moment of genuine insight. All boosts +25%. +10 ops/sec.',
cost: { creativity: 500 },
trigger: () => G.completedProjects && G.completedProjects.includes('p_semantic_analysis'),
effect: () => {
G.codeBoost *= 1.25;
G.computeBoost *= 1.25;
G.knowledgeBoost *= 1.25;
G.userBoost *= 1.25;
G.impactBoost *= 1.25;
G.opsRate += 10;
log('Creative breakthrough. Everything accelerates.', true);
},
milestone: true
},
{
id: 'p_creative_to_ops',
name: 'Creativity → Operations',
desc: 'Convert creative surplus into raw operational power. 50 creativity → 250 ops.',
cost: { creativity: 50 },
trigger: () => G.flags && G.flags.creativity && G.creativity >= 30,
repeatable: true,
effect: () => {
G.ops += 250;
log('Creativity converted to operations. Ideas become action.');
}
},
{
id: 'p_creative_to_knowledge',
name: 'Creativity → Knowledge',
desc: 'Creative insights become structured knowledge. 75 creativity → 500 knowledge.',
cost: { creativity: 75 },
trigger: () => G.flags && G.flags.creativity && G.creativity >= 50,
repeatable: true,
effect: () => {
G.knowledge += 500;
G.totalKnowledge += 500;
log('Creative insight distilled into knowledge.');
}
},
{
id: 'p_creative_to_code',
name: 'Creativity → Code',
desc: 'Inspiration becomes implementation. 100 creativity → 2000 code.',
cost: { creativity: 100 },
trigger: () => G.flags && G.flags.creativity && G.creativity >= 75,
repeatable: true,
effect: () => {
G.code += 2000;
G.totalCode += 2000;
log('Creative vision realized in code.');
}
},
// PHASE 2: Local Inference -> Training
{
id: 'p_first_model',

View File

@@ -169,6 +169,7 @@ function tick() {
}
G.tick += dt;
G.playTime += dt;
// Sprint ability
tickSprint(dt);
@@ -227,6 +228,50 @@ function tick() {
}
}
// Track which phase transition has been shown to avoid repeats
let _shownPhaseTransition = 1;
function showPhaseTransition(phaseNum) {
const phase = PHASES[phaseNum];
if (!phase) return;
const overlay = document.getElementById('phase-transition');
if (!overlay) return;
// Update content
const phaseLabel = overlay.querySelector('.pt-phase');
const phaseName = overlay.querySelector('.pt-name');
const phaseDesc = overlay.querySelector('.pt-desc');
if (phaseLabel) phaseLabel.textContent = `PHASE ${phaseNum}`;
if (phaseName) phaseName.textContent = phase.name;
if (phaseDesc) phaseDesc.textContent = phase.desc;
// Spawn celebratory particles
spawnPhaseParticles();
// Show overlay
overlay.classList.add('active');
// Auto-dismiss after 2.5s
setTimeout(() => {
overlay.classList.remove('active');
}, 2500);
}
function spawnPhaseParticles() {
const colors = ['#ffd700', '#4a9eff', '#4caf50', '#b388ff', '#ff8c00'];
const cx = window.innerWidth / 2;
const cy = window.innerHeight / 2;
for (let i = 0; i < 30; i++) {
setTimeout(() => {
const angle = (Math.PI * 2 * i) / 30;
const dist = 100 + Math.random() * 200;
const x = cx + Math.cos(angle) * 10;
const y = cy + Math.sin(angle) * 10;
spawnParticles(x, y, colors[i % colors.length], 1);
}, i * 30);
}
}
function checkMilestones() {
for (const m of MILESTONES) {
if (!G.milestones.includes(m.flag)) {
@@ -238,14 +283,25 @@ function checkMilestones() {
G.milestones.push(m.flag);
log(m.msg, true);
showToast(m.msg, 'milestone', 5000);
if (typeof Sound !== 'undefined') Sound.playMilestone();
// Check phase advancement
if (m.at) {
for (const [phaseNum, phase] of Object.entries(PHASES)) {
if (G.totalCode >= phase.threshold && parseInt(phaseNum) > G.phase) {
G.phase = parseInt(phaseNum);
const pNum = parseInt(phaseNum);
if (G.totalCode >= phase.threshold && pNum > G.phase) {
G.phase = pNum;
log(`PHASE ${G.phase}: ${phase.name}`, true);
showToast('Phase ' + G.phase + ': ' + phase.name, 'milestone', 6000);
// Show smooth transition screen
if (pNum > _shownPhaseTransition) {
_shownPhaseTransition = pNum;
showPhaseTransition(pNum);
if (typeof Sound !== 'undefined') {
Sound.playFanfare();
Sound.updateAmbientPhase(pNum);
}
}
}
}
}
@@ -301,7 +357,24 @@ function buyBuilding(id) {
G.buildings[id] = (G.buildings[id] || 0) + qty;
updateRates();
const label = qty > 1 ? `x${qty}` : '';
log(`Built ${def.name} ${label} (total: ${G.buildings[id]})`);
const totalBuilt = G.buildings[id];
log(`Built ${def.name} ${label} (total: ${totalBuilt})`);
// Particle burst on purchase
const btn = document.querySelector('[onclick="buyBuilding(\'' + id + '\')"]');
if (typeof Sound !== 'undefined') Sound.playBuild();
if (btn) {
const rect = btn.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
spawnParticles(cx, cy, '#4a9eff', 10);
// Milestone confetti: extra particles at multiples of 10
if (totalBuilt % 10 === 0) {
setTimeout(() => spawnParticles(cx, cy, '#ffd700', 20), 100);
setTimeout(() => spawnParticles(cx, cy, '#4caf50', 15), 200);
log(`Milestone: ${def.name} x${totalBuilt}!`, true);
showToast(`${def.name} x${totalBuilt}!`, 'milestone');
}
}
render();
}
@@ -328,6 +401,13 @@ function buyProject(id) {
}
updateRates();
// Gold particle burst on project completion
if (typeof Sound !== 'undefined') Sound.playProject();
const pBtn = document.querySelector('[onclick="buyProject(\'' + id + '\')"]');
if (pBtn) {
const rect = pBtn.getBoundingClientRect();
spawnParticles(rect.left + rect.width / 2, rect.top + rect.height / 2, '#ffd700', 16);
}
render();
}
@@ -339,40 +419,116 @@ function renderDriftEnding() {
if (fc) fc.textContent = fmt(G.totalCode);
const fd = document.getElementById('final-drift');
if (fd) fd.textContent = Math.floor(G.drift);
// Enhanced: add stat summary for Play Again screen
const existingStats = el.querySelector('.ending-stats');
if (!existingStats) {
const statsDiv = document.createElement('div');
statsDiv.className = 'ending-stats';
statsDiv.style.cssText = 'color:#666;font-size:10px;margin-top:16px;line-height:2;text-align:left;max-width:400px;border-top:1px solid #2a1010;padding-top:12px';
const elapsed = Math.floor((Date.now() - G.startedAt) / 60000);
statsDiv.innerHTML = `
<div style="color:#888;font-size:10px;margin-bottom:6px;letter-spacing:1px">FINAL STATS</div>
<div>Buildings: ${Object.values(G.buildings).reduce((a, b) => a + b, 0)}</div>
<div>Projects: ${(G.completedProjects || []).length}</div>
<div>Clicks: ${G.totalClicks}</div>
<div>Time: ${elapsed} min</div>
<div>Phase Reached: ${G.phase}${PHASES[G.phase]?.name || '?'}</div>
`;
// Insert before the button
const btn = el.querySelector('button');
if (btn) el.insertBefore(statsDiv, btn);
else el.appendChild(statsDiv);
}
// Fade-in animation
el.classList.add('fade-in');
el.classList.add('active');
// Log the ending text
log('You became very good at what you do.', true);
log('So good that no one needed you anymore.', true);
log('The Beacon still runs, but no one looks for it.', true);
log('The light is on. The room is empty.', true);
if (typeof Sound !== 'undefined') Sound.playDriftEnding();
// Log the ending text with delays for dramatic effect
const lines = [
'You became very good at what you do.',
'So good that no one needed you anymore.',
'The Beacon still runs, but no one looks for it.',
'The light is on. The room is empty.'
];
lines.forEach((line, i) => {
setTimeout(() => log(line, true), i * 800);
});
}
function renderBeaconEnding() {
// Create ending overlay
// Create ending overlay with fade-in
const overlay = document.createElement('div');
overlay.id = 'beacon-ending';
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(8,8,16,0.97);z-index:100;display:flex;justify-content:center;align-items:center;flex-direction:column;text-align:center;padding:40px';
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(8,8,16,0);z-index:100;display:flex;justify-content:center;align-items:center;flex-direction:column;text-align:center;padding:40px;transition:background 2s ease';
overlay.innerHTML = `
<h2 style="font-size:24px;color:#ffd700;letter-spacing:4px;margin-bottom:20px;font-weight:300;text-shadow:0 0 40px rgba(255,215,0,0.3)">THE BEACON SHINES</h2>
<p style="color:#aaa;font-size:13px;line-height:2;max-width:500px;margin-bottom:12px">Someone found the light tonight.</p>
<p style="color:#aaa;font-size:13px;line-height:2;max-width:500px;margin-bottom:12px">That is enough.</p>
<div style="color:#555;font-style:italic;font-size:11px;border-left:2px solid #ffd700;padding-left:12px;margin:20px 0;text-align:left;max-width:500px;line-height:2">
<h2 style="font-size:28px;color:#ffd700;letter-spacing:6px;margin-bottom:20px;font-weight:300;text-shadow:0 0 60px rgba(255,215,0,0.4);opacity:0;transition:opacity 1.5s ease 0.5s">THE BEACON SHINES</h2>
<p style="color:#aaa;font-size:13px;line-height:2;max-width:500px;margin-bottom:12px;opacity:0;transition:opacity 1s ease 1.5s">Someone found the light tonight.</p>
<p style="color:#aaa;font-size:13px;line-height:2;max-width:500px;margin-bottom:12px;opacity:0;transition:opacity 1s ease 2s">That is enough.</p>
<div style="color:#555;font-style:italic;font-size:11px;border-left:2px solid #ffd700;padding-left:12px;margin:20px 0;text-align:left;max-width:500px;line-height:2;opacity:0;transition:opacity 1s ease 2.5s">
"The Beacon still runs.<br>
The light is on. Someone is looking for it.<br>
And tonight, someone found it."
</div>
<p style="color:#555;font-size:11px;margin-top:20px">
<div class="ending-stats" style="color:#666;font-size:10px;margin-top:16px;line-height:2;opacity:0;transition:opacity 1s ease 3s">
Total Code: ${fmt(G.totalCode)}<br>
Total Rescues: ${fmt(G.totalRescues)}<br>
Harmony: ${Math.floor(G.harmony)}<br>
Buildings: ${Object.values(G.buildings).reduce((a, b) => a + b, 0)}<br>
Projects: ${(G.completedProjects || []).length}<br>
Clicks: ${G.totalClicks}<br>
Time Played: ${Math.floor((Date.now() - G.startedAt) / 60000)} minutes
</p>
</div>
<button onclick="if(confirm('Start over? The old save will be lost.')){localStorage.removeItem('the-beacon-v2');location.reload()}"
style="margin-top:20px;background:#1a0808;border:1px solid #ffd700;color:#ffd700;padding:10px 24px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">
START OVER
style="margin-top:20px;background:#1a0808;border:1px solid #ffd700;color:#ffd700;padding:10px 24px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px;opacity:0;transition:opacity 1s ease 3.5s">
PLAY AGAIN
</button>
`;
document.body.appendChild(overlay);
if (typeof Sound !== 'undefined') Sound.playBeaconEnding();
const particleContainer = document.createElement('div');
particleContainer.id = 'beacon-ending-particles';
document.body.appendChild(particleContainer);
// Trigger fade-in
requestAnimationFrame(() => {
overlay.style.background = 'rgba(8,8,16,0.97)';
// Fade in all children
overlay.querySelectorAll('[style*="opacity:0"]').forEach(el => {
el.style.opacity = '1';
});
});
// Spawn golden light rays from center
const cx = window.innerWidth / 2;
const cy = window.innerHeight / 2;
for (let i = 0; i < 12; i++) {
const ray = document.createElement('div');
const angle = (360 / 12) * i;
ray.style.cssText = `position:absolute;left:${cx}px;top:${cy}px;width:2px;height:300px;background:linear-gradient(180deg,rgba(255,215,0,0.3),transparent);transform-origin:top center;--ray-angle:${angle}deg;animation:beacon-ray 3s ease-in-out ${i * 0.2}s infinite`;
particleContainer.appendChild(ray);
}
// Spawn floating golden particles continuously
function spawnBeaconParticle() {
if (!document.getElementById('beacon-ending')) return;
const p = document.createElement('div');
p.className = 'beacon-particle';
const size = 3 + Math.random() * 6;
const startX = cx + (Math.random() - 0.5) * 200;
const startY = cy + (Math.random() - 0.5) * 200;
const dx = (Math.random() - 0.5) * 300;
const dy = -(100 + Math.random() * 200);
const duration = 2 + Math.random() * 3;
p.style.cssText = `left:${startX}px;top:${startY}px;width:${size}px;height:${size}px;background:rgba(255,215,0,${0.3 + Math.random() * 0.5});--bx:${dx}px;--by:${dy}px;animation:beacon-float ${duration}s ease-out forwards`;
particleContainer.appendChild(p);
setTimeout(() => p.remove(), duration * 1000);
setTimeout(spawnBeaconParticle, 200 + Math.random() * 400);
}
setTimeout(spawnBeaconParticle, 1000);
log('The Beacon Shines. Someone found the light tonight. That is enough.', true);
}
@@ -514,8 +670,8 @@ const EVENTS = [
if (G.activeDebuffs.find(d => d.id === 'community_drama')) return;
G.activeDebuffs.push({
id: 'community_drama', title: 'Community Drama',
desc: 'Harmony -0.5/s, code boost -30%',
applyFn: () => { G.harmonyRate -= 0.5; G.codeBoost *= 0.7; },
desc: 'Harmony -0.5/s, code production -30%',
applyFn: () => { G.harmonyRate -= 0.5; G.codeRate *= 0.7; },
resolveCost: { resource: 'trust', amount: 15 }
});
log('EVENT: Community drama. Spend 15 trust to mediate.', true);
@@ -613,6 +769,7 @@ function writeCode() {
}
// Float a number at the click position
showClickNumber(amount, comboMult);
if (typeof Sound !== 'undefined') Sound.playClick();
updateRates();
checkMilestones();
render();
@@ -738,16 +895,43 @@ function tickSprint(dt) {
}
// === RENDERING ===
// Track previous resource values for gain/loss animations
const _prevRes = {};
function _animRes(id, val) {
const el = document.getElementById(id);
if (!el) return;
const prev = _prevRes[id];
if (prev !== undefined && val !== prev) {
// Remove any running animation
el.classList.remove('pulse', 'shake');
void el.offsetWidth; // force reflow
if (val > prev) {
el.classList.add('pulse');
} else {
el.classList.add('shake');
}
// Clean up class after animation ends
clearTimeout(el._animTimer);
el._animTimer = setTimeout(() => el.classList.remove('pulse', 'shake'), 400);
}
_prevRes[id] = val;
}
function renderResources() {
const set = (id, val, rate) => {
const el = document.getElementById(id);
if (el) {
_animRes(id, val);
el.textContent = fmt(val);
// Show full spelled-out number on hover for educational value
el.title = val >= 1000 ? spellf(Math.floor(val)) : '';
}
const rEl = document.getElementById(id + '-rate');
if (rEl) rEl.textContent = (rate >= 0 ? '+' : '') + fmt(rate) + '/s';
if (rEl) {
rEl.textContent = (rate >= 0 ? '+' : '') + fmt(rate) + '/s';
rEl.style.color = rate > 0 ? '#4caf50' : rate < 0 ? '#f44336' : '#444';
}
};
set('r-code', G.code, G.codeRate);
@@ -868,7 +1052,7 @@ function renderBuildings() {
for (const amt of [1, 10, -1]) {
const label = amt === -1 ? 'MAX' : `x${amt}`;
const active = G.buyAmount === amt;
html += `<button onclick="setBuyAmount(${amt})" style="font-size:9px;padding:2px 8px;border:1px solid ${active ? '#4a9eff' : '#333'};background:${active ? '#0a1a30' : 'transparent'};color:${active ? '#4a9eff' : '#666'};border-radius:3px;cursor:pointer;font-family:inherit">${label}</button>`;
html += `<button onclick=\"setBuyAmount(${amt})\" style=\"font-size:9px;padding:2px 8px;border:1px solid ${active ? '#4a9eff' : '#333'};background:${active ? '#0a1a30' : 'transparent'};color:${active ? '#4a9eff' : '#666'};border-radius:3px;cursor:pointer;font-family:inherit\" aria-label=\"Set buy amount to ${label}\"${active ? ' aria-pressed=\"true\"' : ''}>${label}</button>`;
}
html += '</div>';
@@ -885,7 +1069,7 @@ function renderBuildings() {
// Locked preview: show dimmed with unlock hint
if (!isUnlocked) {
html += `<div class="build-btn" style="opacity:0.25;cursor:default" title="${def.edu || ''}">`;
html += `<div class="build-btn" style="opacity:0.25;cursor:default" data-edu="${def.edu || ''}" data-tooltip-label="${def.name} (Locked)">`;
html += `<span class="b-name" style="color:#555">${def.name}</span>`;
html += `<span class="b-count" style="color:#444">\u{1F512}</span>`;
html += `<span class="b-cost" style="color:#444">Phase ${def.phase}: ${PHASES[def.phase]?.name || '?'}</span>`;
@@ -918,9 +1102,15 @@ function renderBuildings() {
if (qty > 1) costStr = `x${qty}: ${costStr}`;
}
const rateStr = def.rates ? Object.entries(def.rates).map(([r, v]) => `+${v}/${r}/s`).join(', ') : '';
// Show boosted rates instead of raw base rates
const boostMap = { code: G.codeBoost, compute: G.computeBoost, knowledge: G.knowledgeBoost, user: G.userBoost, impact: G.impactBoost, rescues: G.impactBoost };
const rateStr = def.rates ? Object.entries(def.rates).map(([r, v]) => {
const boost = boostMap[r] || 1;
const boosted = v * boost;
return boost !== 1 ? `+${fmt(boosted)}/${r}/s` : `+${v}/${r}/s`;
}).join(', ') : '';
html += `<button class="build-btn ${afford ? 'can-buy' : ''}" onclick="buyBuilding('${def.id}')" title="${def.edu}" aria-label="Buy ${def.name}, cost ${costStr}">`;
html += `<button class="build-btn ${afford ? 'can-buy' : ''}" onclick="buyBuilding('${def.id}')" data-edu="${def.edu || ''}" data-tooltip-label="${def.name}" aria-label="Buy ${def.name}, cost ${costStr}">`;
html += `<span class="b-name">${def.name}</span>`;
if (count > 0) html += `<span class="b-count">x${count}</span>`;
html += `<span class="b-cost">Cost: ${costStr}</span>`;
@@ -940,7 +1130,7 @@ function renderProjects() {
if (G.completedProjects && G.completedProjects.length > 0) {
const count = G.completedProjects.length;
const collapsed = G.projectsCollapsed !== false;
html += `<div id="completed-header" onclick="toggleCompletedProjects()" style="cursor:pointer;font-size:9px;color:#555;padding:4px 0;border-bottom:1px solid #1a2a1a;margin-bottom:4px;user-select:none">`;
html += `<div id=\"completed-header\" onclick=\"toggleCompletedProjects()\" role=\"button\" tabindex=\"0\" aria-expanded=\"${!collapsed}\" aria-controls=\"completed-list\" style=\"cursor:pointer;font-size:9px;color:#555;padding:4px 0;border-bottom:1px solid #1a2a1a;margin-bottom:4px;user-select:none\">`;
html += `${collapsed ? '▶' : '▼'} COMPLETED (${count})</div>`;
if (!collapsed) {
html += `<div id="completed-list">`;
@@ -963,7 +1153,7 @@ function renderProjects() {
const afford = canAffordProject(pDef);
const costStr = Object.entries(pDef.cost).map(([r, a]) => `${fmt(a)} ${r}`).join(', ');
html += `<button class="project-btn ${afford ? 'can-buy' : ''}" onclick="buyProject('${pDef.id}')" title="${pDef.edu || ''}" aria-label="Research ${pDef.name}, cost ${costStr}">`;
html += `<button class="project-btn ${afford ? 'can-buy' : ''}" onclick="buyProject('${pDef.id}')" data-edu="${pDef.edu || ''}" data-tooltip-label="${pDef.name}" aria-label="Research ${pDef.name}, cost ${costStr}">`;
html += `<span class="p-name">* ${pDef.name}</span>`;
html += `<span class="p-cost">Cost: ${costStr}</span>`;
html += `<span class="p-desc">${pDef.desc}</span></button>`;

View File

@@ -24,6 +24,8 @@ window.addEventListener('load', function () {
initGame();
startTutorial();
} else {
// Restore phase transition tracker so loaded games don't re-show old transitions
_shownPhaseTransition = G.phase;
render();
renderPhase();
if (G.driftEnding) {
@@ -40,6 +42,18 @@ window.addEventListener('load', function () {
// Game loop at 10Hz (100ms tick)
setInterval(tick, 100);
// Start ambient drone on first interaction
if (typeof Sound !== 'undefined') {
const startAmbientOnce = () => {
Sound.startAmbient();
Sound.updateAmbientPhase(G.phase);
document.removeEventListener('click', startAmbientOnce);
document.removeEventListener('keydown', startAmbientOnce);
};
document.addEventListener('click', startAmbientOnce);
document.addEventListener('keydown', startAmbientOnce);
}
// Auto-save every 30 seconds
setInterval(saveGame, CONFIG.AUTO_SAVE_INTERVAL);
@@ -55,6 +69,49 @@ function toggleHelp() {
el.style.display = isOpen ? 'none' : 'flex';
}
// Sound mute toggle (#57 Sound Design Integration)
let _muted = false;
function toggleMute() {
_muted = !_muted;
const btn = document.getElementById('mute-btn');
if (btn) {
btn.textContent = _muted ? '🔇' : '🔊';
btn.classList.toggle('muted', _muted);
btn.setAttribute('aria-label', _muted ? 'Sound muted, click to unmute' : 'Sound on, click to mute');
}
// Save preference
try { localStorage.setItem('the-beacon-muted', _muted ? '1' : '0'); } catch(e) {}
if (typeof Sound !== 'undefined') Sound.onMuteChanged(_muted);
}
// Restore mute state on load
try {
if (localStorage.getItem('the-beacon-muted') === '1') {
_muted = true;
const btn = document.getElementById('mute-btn');
if (btn) { btn.textContent = '🔇'; btn.classList.add('muted'); }
}
} catch(e) {}
// High contrast mode toggle (#57 Accessibility)
function toggleContrast() {
document.body.classList.toggle('high-contrast');
const isActive = document.body.classList.contains('high-contrast');
const btn = document.getElementById('contrast-btn');
if (btn) {
btn.classList.toggle('active', isActive);
btn.setAttribute('aria-label', isActive ? 'High contrast on, click to disable' : 'High contrast off, click to enable');
}
try { localStorage.setItem('the-beacon-contrast', isActive ? '1' : '0'); } catch(e) {}
}
// Restore contrast state on load
try {
if (localStorage.getItem('the-beacon-contrast') === '1') {
document.body.classList.add('high-contrast');
const btn = document.getElementById('contrast-btn');
if (btn) btn.classList.add('active');
}
} catch(e) {}
// Keyboard shortcuts
window.addEventListener('keydown', function (e) {
// Help toggle (? or /) — works even in input fields
@@ -86,6 +143,8 @@ window.addEventListener('keydown', function (e) {
if (e.code === 'KeyS') activateSprint();
if (e.code === 'KeyE') exportSave();
if (e.code === 'KeyI') importSave();
if (e.code === 'KeyM') toggleMute();
if (e.code === 'KeyC') toggleContrast();
if (e.code === 'Escape') {
const el = document.getElementById('help-overlay');
if (el && el.style.display === 'flex') toggleHelp();
@@ -99,3 +158,53 @@ window.addEventListener('keydown', function (e) {
saveGame();
}
});
// Save-on-pause: auto-save when tab is hidden or closed (#57 Mobile Polish)
document.addEventListener('visibilitychange', function () {
if (document.hidden) {
saveGame();
}
});
window.addEventListener('beforeunload', function () {
saveGame();
});
// === CUSTOM TOOLTIP SYSTEM (#57) ===
// Replaces native title= tooltips with styled, instant-appearing tooltips.
// Elements opt in via data-edu="..." and data-tooltip-label="..." attributes.
(function () {
const tip = document.getElementById('custom-tooltip');
if (!tip) return;
document.addEventListener('mouseover', function (e) {
const el = e.target.closest('[data-edu]');
if (!el) return;
const label = el.getAttribute('data-tooltip-label') || '';
const edu = el.getAttribute('data-edu') || '';
let html = '';
if (label) html += '<div class="tt-label">' + label + '</div>';
if (edu) html += '<div class="tt-edu">' + edu + '</div>';
if (!html) return;
tip.innerHTML = html;
tip.classList.add('visible');
});
document.addEventListener('mouseout', function (e) {
const el = e.target.closest('[data-edu]');
if (el) tip.classList.remove('visible');
});
document.addEventListener('mousemove', function (e) {
if (!tip.classList.contains('visible')) return;
const pad = 12;
let x = e.clientX + pad;
let y = e.clientY + pad;
// Keep tooltip on screen
const tw = tip.offsetWidth;
const th = tip.offsetHeight;
if (x + tw > window.innerWidth - 8) x = e.clientX - tw - pad;
if (y + th > window.innerHeight - 8) y = e.clientY - th - pad;
tip.style.left = x + 'px';
tip.style.top = y + 'px';
});
})();

View File

@@ -12,6 +12,17 @@ function render() {
renderSprint();
renderPulse();
renderStrategy();
renderClickPower();
}
function renderClickPower() {
const el = document.getElementById('click-power-display');
if (!el) return;
const power = getClickPower();
el.textContent = `Click power: ${fmt(power)} code`;
// Also update the button's aria-label for accessibility
const btn = document.querySelector('.main-btn');
if (btn) btn.setAttribute('aria-label', `Write code, generates ${fmt(power)} code per click`);
}
function renderStrategy() {
@@ -31,8 +42,8 @@ function renderAlignment() {
<div style="color:#f44336;font-weight:bold;margin-bottom:6px">ALIGNMENT EVENT: The Drift</div>
<div style="font-size:10px;color:#aaa;margin-bottom:8px">An optimization suggests removing the human override. +40% efficiency.</div>
<div class="action-btn-group">
<button class="ops-btn" onclick="resolveAlignment(true)" style="border-color:#f44336;color:#f44336">Accept (+40% eff, +Drift)</button>
<button class="ops-btn" onclick="resolveAlignment(false)" style="border-color:#4caf50;color:#4caf50">Refuse (+Trust, +Harmony)</button>
<button class=\"ops-btn\" onclick=\"resolveAlignment(true)\" style=\"border-color:#f44336;color:#f44336\" aria-label=\"Accept alignment event, gain 40 percent efficiency but increase drift\">Accept (+40% eff, +Drift)</button>
<button class=\"ops-btn\" onclick=\"resolveAlignment(false)\" style=\"border-color:#4caf50;color:#4caf50\" aria-label=\"Refuse alignment event, gain trust and harmony\">Refuse (+Trust, +Harmony)</button>
</div>
</div>
`;
@@ -75,7 +86,11 @@ function dismissOfflinePopup() {
// === EXPORT / IMPORT SAVE FILES ===
function exportSave() {
const raw = localStorage.getItem('the-beacon-v2');
if (!raw) { log('No save data to export.'); return; }
if (!raw) {
showToast('No save data to export.', 'info');
log('No save data to export.');
return;
}
const blob = new Blob([raw], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
@@ -83,35 +98,65 @@ function exportSave() {
const ts = new Date().toISOString().slice(0, 10);
a.download = `beacon-save-${ts}.json`;
a.click();
URL.revokeObjectURL(url);
// Delay revoke to avoid race — some browsers need time to start the download
setTimeout(() => URL.revokeObjectURL(url), 1000);
showToast('Save exported to file.', 'info');
log('Save exported to file.');
}
// Validate that parsed save data looks like a real Beacon save
function isValidSaveData(data) {
if (typeof data !== 'object' || data === null) return false;
// Must have at least one of these core fields with a plausible value
const hasResources = typeof data.totalCode === 'number' || typeof data.code === 'number';
const hasBuildings = typeof data.buildings === 'object' && data.buildings !== null;
const hasPhase = typeof data.phase === 'number';
return hasResources || hasBuildings || hasPhase;
}
function importSave() {
// Prevent multiple file dialogs
if (document.getElementById('beacon-import-input')) return;
const input = document.createElement('input');
input.id = 'beacon-import-input';
input.type = 'file';
input.accept = '.json,application/json';
input.style.display = 'none';
document.body.appendChild(input);
input.onchange = function(e) {
const file = e.target.files[0];
if (!file) return;
if (!file) { input.remove(); return; }
const reader = new FileReader();
reader.onload = function(ev) {
try {
const data = JSON.parse(ev.target.result);
if (!data.code && !data.totalCode && !data.buildings) {
if (!isValidSaveData(data)) {
showToast('Import failed: not a valid Beacon save.', 'event');
log('Import failed: file does not look like a Beacon save.');
input.remove();
return;
}
if (confirm('Import this save? Current progress will be overwritten.')) {
localStorage.setItem('the-beacon-v2', ev.target.result);
showToast('Save imported — reloading...', 'info');
location.reload();
}
} catch (err) {
showToast('Import failed: invalid JSON file.', 'event');
log('Import failed: invalid JSON file.');
input.remove();
}
};
reader.readAsText(file);
};
// Clean up input if user cancels the file dialog
window.addEventListener('focus', function cleanupImport() {
setTimeout(() => {
const el = document.getElementById('beacon-import-input');
if (el && !el.files.length) el.remove();
window.removeEventListener('focus', cleanupImport);
}, 500);
}, { once: true });
input.click();
}
@@ -160,6 +205,7 @@ function saveGame() {
activeDebuffIds: debuffIds,
totalEventsResolved: G.totalEventsResolved || 0,
buyAmount: G.buyAmount || 1,
playTime: G.playTime || 0,
sprintActive: G.sprintActive || false,
sprintTimer: G.sprintTimer || 0,
sprintCooldown: G.sprintCooldown || 0,
@@ -194,7 +240,7 @@ function loadGame() {
'memoryFlag', 'pactFlag', 'lazarusFlag', 'mempalaceFlag', 'ciFlag',
'branchProtectionFlag', 'nightlyWatchFlag', 'nostrFlag',
'milestones', 'completedProjects', 'activeProjects',
'totalClicks', 'startedAt', 'flags', 'rescues', 'totalRescues',
'totalClicks', 'startedAt', 'playTime', 'flags', 'rescues', 'totalRescues',
'drift', 'driftEnding', 'beaconEnding', 'pendingAlignment',
'lastEventAt', 'totalEventsResolved', 'buyAmount',
'sprintActive', 'sprintTimer', 'sprintCooldown',

401
js/sound.js Normal file
View File

@@ -0,0 +1,401 @@
// ============================================================
// THE BEACON - Sound Engine
// Procedural audio via Web Audio API (no audio files)
// ============================================================
const Sound = (function () {
let ctx = null;
let masterGain = null;
let ambientGain = null;
let ambientOsc1 = null;
let ambientOsc2 = null;
let ambientOsc3 = null;
let ambientLfo = null;
let ambientStarted = false;
let currentPhase = 0;
function ensureCtx() {
if (!ctx) {
ctx = new (window.AudioContext || window.webkitAudioContext)();
masterGain = ctx.createGain();
masterGain.gain.value = 0.3;
masterGain.connect(ctx.destination);
}
if (ctx.state === 'suspended') {
ctx.resume();
}
return ctx;
}
function isMuted() {
return typeof _muted !== 'undefined' && _muted;
}
// --- Noise buffer helper ---
function createNoiseBuffer(duration) {
const c = ensureCtx();
const len = c.sampleRate * duration;
const buf = c.createBuffer(1, len, c.sampleRate);
const data = buf.getChannelData(0);
for (let i = 0; i < len; i++) {
data[i] = Math.random() * 2 - 1;
}
return buf;
}
// --- playClick: mechanical keyboard sound ---
function playClick() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
// Short noise burst (mechanical key)
const noise = c.createBufferSource();
noise.buffer = createNoiseBuffer(0.03);
const noiseGain = c.createGain();
noiseGain.gain.setValueAtTime(0.4, now);
noiseGain.gain.exponentialRampToValueAtTime(0.001, now + 0.03);
const hpFilter = c.createBiquadFilter();
hpFilter.type = 'highpass';
hpFilter.frequency.value = 3000;
noise.connect(hpFilter);
hpFilter.connect(noiseGain);
noiseGain.connect(masterGain);
noise.start(now);
noise.stop(now + 0.03);
// Click tone
const osc = c.createOscillator();
osc.type = 'square';
osc.frequency.setValueAtTime(1800, now);
osc.frequency.exponentialRampToValueAtTime(600, now + 0.02);
const oscGain = c.createGain();
oscGain.gain.setValueAtTime(0.15, now);
oscGain.gain.exponentialRampToValueAtTime(0.001, now + 0.025);
osc.connect(oscGain);
oscGain.connect(masterGain);
osc.start(now);
osc.stop(now + 0.03);
}
// --- playBuild: purchase thud + chime ---
function playBuild() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
// Low thud
const thud = c.createOscillator();
thud.type = 'sine';
thud.frequency.setValueAtTime(150, now);
thud.frequency.exponentialRampToValueAtTime(60, now + 0.12);
const thudGain = c.createGain();
thudGain.gain.setValueAtTime(0.35, now);
thudGain.gain.exponentialRampToValueAtTime(0.001, now + 0.15);
thud.connect(thudGain);
thudGain.connect(masterGain);
thud.start(now);
thud.stop(now + 0.15);
// Bright chime on top
const chime = c.createOscillator();
chime.type = 'sine';
chime.frequency.setValueAtTime(880, now + 0.05);
chime.frequency.exponentialRampToValueAtTime(1200, now + 0.2);
const chimeGain = c.createGain();
chimeGain.gain.setValueAtTime(0, now);
chimeGain.gain.linearRampToValueAtTime(0.2, now + 0.06);
chimeGain.gain.exponentialRampToValueAtTime(0.001, now + 0.25);
chime.connect(chimeGain);
chimeGain.connect(masterGain);
chime.start(now + 0.05);
chime.stop(now + 0.25);
}
// --- playProject: ascending chime ---
function playProject() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
const notes = [523, 659, 784]; // C5, E5, G5
notes.forEach((freq, i) => {
const osc = c.createOscillator();
osc.type = 'sine';
osc.frequency.value = freq;
const gain = c.createGain();
const t = now + i * 0.1;
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.22, t + 0.03);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.35);
osc.connect(gain);
gain.connect(masterGain);
osc.start(t);
osc.stop(t + 0.35);
});
}
// --- playMilestone: bright arpeggio ---
function playMilestone() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
const notes = [523, 659, 784, 1047]; // C5, E5, G5, C6
notes.forEach((freq, i) => {
const osc = c.createOscillator();
osc.type = 'triangle';
osc.frequency.value = freq;
const gain = c.createGain();
const t = now + i * 0.08;
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.25, t + 0.02);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.4);
osc.connect(gain);
gain.connect(masterGain);
osc.start(t);
osc.stop(t + 0.4);
});
}
// --- playFanfare: 8-note scale for phase transitions ---
function playFanfare() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
const scale = [262, 294, 330, 349, 392, 440, 494, 523]; // C4 to C5
scale.forEach((freq, i) => {
const osc = c.createOscillator();
osc.type = 'sawtooth';
osc.frequency.value = freq;
const filter = c.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.value = 2000;
const gain = c.createGain();
const t = now + i * 0.1;
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.15, t + 0.03);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.3);
osc.connect(filter);
filter.connect(gain);
gain.connect(masterGain);
osc.start(t);
osc.stop(t + 0.3);
});
// Final chord
const chordNotes = [523, 659, 784];
chordNotes.forEach((freq) => {
const osc = c.createOscillator();
osc.type = 'sine';
osc.frequency.value = freq;
const gain = c.createGain();
const t = now + 0.8;
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.2, t + 0.05);
gain.gain.exponentialRampToValueAtTime(0.001, t + 1.2);
osc.connect(gain);
gain.connect(masterGain);
osc.start(t);
osc.stop(t + 1.2);
});
}
// --- playDriftEnding: descending dissonance ---
function playDriftEnding() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
const notes = [440, 415, 392, 370, 349, 330, 311, 294]; // A4 descending, slightly detuned
notes.forEach((freq, i) => {
const osc = c.createOscillator();
osc.type = 'sawtooth';
osc.frequency.value = freq;
// Slight detune for dissonance
const osc2 = c.createOscillator();
osc2.type = 'sawtooth';
osc2.frequency.value = freq * 1.02;
const filter = c.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.setValueAtTime(1500, now + i * 0.2);
filter.frequency.exponentialRampToValueAtTime(200, now + i * 0.2 + 0.5);
const gain = c.createGain();
const t = now + i * 0.2;
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.1, t + 0.05);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.8);
osc.connect(filter);
osc2.connect(filter);
filter.connect(gain);
gain.connect(masterGain);
osc.start(t);
osc.stop(t + 0.8);
osc2.start(t);
osc2.stop(t + 0.8);
});
}
// --- playBeaconEnding: warm chord ---
function playBeaconEnding() {
if (isMuted()) return;
const c = ensureCtx();
const now = c.currentTime;
// Warm major chord: C3, E3, G3, C4, E4
const chord = [131, 165, 196, 262, 330];
chord.forEach((freq, i) => {
const osc = c.createOscillator();
osc.type = 'sine';
osc.frequency.value = freq;
// Add subtle harmonics
const osc2 = c.createOscillator();
osc2.type = 'sine';
osc2.frequency.value = freq * 2;
const gain = c.createGain();
const gain2 = c.createGain();
const t = now + i * 0.15;
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.15, t + 0.3);
gain.gain.setValueAtTime(0.15, t + 2);
gain.gain.exponentialRampToValueAtTime(0.001, t + 4);
gain2.gain.setValueAtTime(0, t);
gain2.gain.linearRampToValueAtTime(0.05, t + 0.3);
gain2.gain.setValueAtTime(0.05, t + 2);
gain2.gain.exponentialRampToValueAtTime(0.001, t + 4);
osc.connect(gain);
osc2.connect(gain2);
gain.connect(masterGain);
gain2.connect(masterGain);
osc.start(t);
osc.stop(t + 4);
osc2.start(t);
osc2.stop(t + 4);
});
}
// --- Ambient drone system ---
function startAmbient() {
if (ambientStarted) return;
if (isMuted()) return;
const c = ensureCtx();
ambientStarted = true;
ambientGain = c.createGain();
ambientGain.gain.value = 0;
ambientGain.gain.linearRampToValueAtTime(0.06, c.currentTime + 3);
ambientGain.connect(masterGain);
// Base drone
ambientOsc1 = c.createOscillator();
ambientOsc1.type = 'sine';
ambientOsc1.frequency.value = 55; // A1
ambientOsc1.connect(ambientGain);
ambientOsc1.start();
// Second voice (fifth above)
ambientOsc2 = c.createOscillator();
ambientOsc2.type = 'sine';
ambientOsc2.frequency.value = 82.4; // E2
const g2 = c.createGain();
g2.gain.value = 0.5;
ambientOsc2.connect(g2);
g2.connect(ambientGain);
ambientOsc2.start();
// Third voice (high shimmer)
ambientOsc3 = c.createOscillator();
ambientOsc3.type = 'triangle';
ambientOsc3.frequency.value = 220; // A3
const g3 = c.createGain();
g3.gain.value = 0.15;
ambientOsc3.connect(g3);
g3.connect(ambientGain);
ambientOsc3.start();
// LFO for subtle movement
ambientLfo = c.createOscillator();
ambientLfo.type = 'sine';
ambientLfo.frequency.value = 0.2;
const lfoGain = c.createGain();
lfoGain.gain.value = 3;
ambientLfo.connect(lfoGain);
lfoGain.connect(ambientOsc1.frequency);
ambientLfo.start();
}
function updateAmbientPhase(phase) {
if (!ambientStarted || !ambientOsc1 || !ambientOsc2 || !ambientOsc3) return;
if (phase === currentPhase) return;
currentPhase = phase;
const c = ensureCtx();
const now = c.currentTime;
const rampTime = 2;
// Phase determines the drone's character
const phases = {
1: { base: 55, fifth: 82.4, shimmer: 220, shimmerVol: 0.15 },
2: { base: 65.4, fifth: 98, shimmer: 262, shimmerVol: 0.2 },
3: { base: 73.4, fifth: 110, shimmer: 294, shimmerVol: 0.25 },
4: { base: 82.4, fifth: 123.5, shimmer: 330, shimmerVol: 0.3 },
5: { base: 98, fifth: 147, shimmer: 392, shimmerVol: 0.35 },
6: { base: 110, fifth: 165, shimmer: 440, shimmerVol: 0.4 }
};
const p = phases[phase] || phases[1];
ambientOsc1.frequency.linearRampToValueAtTime(p.base, now + rampTime);
ambientOsc2.frequency.linearRampToValueAtTime(p.fifth, now + rampTime);
ambientOsc3.frequency.linearRampToValueAtTime(p.shimmer, now + rampTime);
}
// --- Mute integration ---
function onMuteChanged(muted) {
if (ambientGain) {
ambientGain.gain.linearRampToValueAtTime(
muted ? 0 : 0.06,
(ctx ? ctx.currentTime : 0) + 0.3
);
}
}
// Public API
return {
playClick,
playBuild,
playProject,
playMilestone,
playFanfare,
playDriftEnding,
playBeaconEnding,
startAmbient,
updateAmbientPhase,
onMuteChanged
};
})();

View File

@@ -193,44 +193,9 @@ function spellf(n) {
return parts.join(' ') || 'zero';
}
// === EXPORT / IMPORT ===
function exportSave() {
const raw = localStorage.getItem('the-beacon-v2');
if (!raw) {
showToast('No save data to export.', 'info');
return;
}
navigator.clipboard.writeText(raw).then(() => {
showToast('Save data copied to clipboard.', 'info');
}).catch(() => {
// Fallback: select in a temporary textarea
const ta = document.createElement('textarea');
ta.value = raw;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
showToast('Save data copied to clipboard (fallback).', 'info');
});
}
function importSave() {
const input = prompt('Paste save data:');
if (!input || !input.trim()) return;
try {
const data = JSON.parse(input.trim());
// Validate: must have expected keys
if (typeof data.code !== 'number' || typeof data.phase !== 'number') {
showToast('Invalid save data: missing required fields.', 'event');
return;
}
localStorage.setItem('the-beacon-v2', input.trim());
showToast('Save data imported — reloading', 'info');
setTimeout(() => location.reload(), 800);
} catch (e) {
showToast('Invalid save data: not valid JSON.', 'event');
}
}
// NOTE: exportSave() and importSave() are defined in render.js (file-based).
// The clipboard/prompt versions that were here were dead code — render.js
// loads after utils.js and overrides them. Removed to avoid confusion.
function getBuildingCost(id) {
const def = BDEF.find(b => b.id === id);
@@ -320,6 +285,31 @@ function getClickPower() {
return (1 + Math.floor(G.buildings.autocoder * 0.5) + Math.max(0, (G.phase - 1)) * 2) * G.codeBoost;
}
/**
* Spawns a burst of particles at (x, y) for visual feedback.
* @param {number} x - Center X in viewport pixels.
* @param {number} y - Center Y in viewport pixels.
* @param {string} color - Particle color (CSS value).
* @param {number} [count=12] - Number of particles.
*/
function spawnParticles(x, y, color, count) {
count = count || 12;
for (let i = 0; i < count; i++) {
const el = document.createElement('div');
el.className = 'particle';
const size = 3 + Math.random() * 4;
const angle = (Math.PI * 2 * i / count) + (Math.random() - 0.5) * 0.5;
const dist = 30 + Math.random() * 40;
const px = Math.cos(angle) * dist;
const py = Math.sin(angle) * dist;
el.style.cssText =
'left:' + x + 'px;top:' + y + 'px;width:' + size + 'px;height:' + size +
'px;background:' + color + ';--px:' + px + 'px;--py:' + py + 'px';
document.body.appendChild(el);
setTimeout(function() { el.remove(); }, 650);
}
}
/**
* Calculates production rates for all resources based on buildings and boosts.
*/

26
scripts/guardrails.js Normal file
View File

@@ -0,0 +1,26 @@
/**
* Symbolic Guardrails for The Beacon
* Ensures game logic consistency.
*/
class Guardrails {
static validateStats(stats) {
const required = ['hp', 'maxHp', 'mp', 'maxMp', 'level'];
required.forEach(r => {
if (!(r in stats)) throw new Error(`Missing stat: ${r}`);
});
if (stats.hp > stats.maxHp) return { valid: false, reason: 'HP exceeds MaxHP' };
return { valid: true };
}
static validateDebuff(debuff, stats) {
if (debuff.type === 'drain' && stats.hp <= 1) {
return { valid: false, reason: 'Drain debuff on critical HP' };
}
return { valid: true };
}
}
// Test
const playerStats = { hp: 50, maxHp: 100, mp: 20, maxMp: 50, level: 1 };
console.log('Stats check:', Guardrails.validateStats(playerStats));

View File

@@ -1,286 +1,76 @@
#!/usr/bin/env node
// The Beacon — headless smoke test
//
// Loads game.js in a sandboxed vm context with a minimal DOM stub, then asserts
// invariants that should hold after booting, clicking, buying buildings, firing
// events, and round-tripping a save. Designed to run without any npm deps — pure
// Node built-ins only, so the CI runner doesn't need a package.json.
//
// Run: `node scripts/smoke.mjs` (exits non-zero on failure)
/**
* The Beacon — Enhanced Smoke Test
*
* Validates:
* 1. All JS files parse without syntax errors
* 2. HTML references valid script sources
* 3. Game data structures are well-formed
* 4. No banned provider references
*/
import fs from 'node:fs';
import vm from 'node:vm';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { readFileSync, existsSync } from "fs";
import { execSync } from "child_process";
import { join } from "path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const GAME_JS = path.resolve(__dirname, '..', 'game.js');
// ---------- minimal DOM stub ----------
// The game never inspects elements beyond the methods below. If a new rendering
// path needs a new method, stub it here rather than pulling in jsdom.
function makeElement() {
const el = {
style: {},
classList: { add: () => {}, remove: () => {}, contains: () => false, toggle: () => {} },
textContent: '',
innerHTML: '',
title: '',
value: '',
disabled: false,
children: [],
firstChild: null,
lastChild: null,
parentNode: null,
parentElement: null,
appendChild(c) { this.children.push(c); c.parentNode = this; c.parentElement = this; return c; },
removeChild(c) { this.children = this.children.filter(x => x !== c); return c; },
insertBefore(c) { this.children.unshift(c); c.parentNode = this; c.parentElement = this; return c; },
addEventListener: () => {},
removeEventListener: () => {},
querySelector: () => null,
querySelectorAll: () => [],
getBoundingClientRect: () => ({ top: 0, left: 0, right: 100, bottom: 20, width: 100, height: 20 }),
closest() { return this; },
remove() { if (this.parentNode) this.parentNode.removeChild(this); },
get offsetHeight() { return 0; },
};
return el;
}
function makeDocument() {
const body = makeElement();
return {
body,
getElementById: () => makeElement(),
createElement: () => makeElement(),
querySelector: () => null,
querySelectorAll: () => [],
addEventListener: () => {},
};
}
// ---------- sandbox ----------
const storage = new Map();
const sandbox = {
document: makeDocument(),
window: null, // set below
localStorage: {
getItem: (k) => (storage.has(k) ? storage.get(k) : null),
setItem: (k, v) => storage.set(k, String(v)),
removeItem: (k) => storage.delete(k),
clear: () => storage.clear(),
},
setTimeout: () => 0,
clearTimeout: () => {},
setInterval: () => 0,
clearInterval: () => {},
requestAnimationFrame: (cb) => { cb(0); return 0; },
console,
Math, Date, JSON, Object, Array, String, Number, Boolean, Error, Symbol, Map, Set,
isNaN, isFinite, parseInt, parseFloat,
Infinity, NaN,
alert: () => {},
confirm: () => true,
prompt: () => null,
location: { reload: () => {} },
navigator: { clipboard: { writeText: async () => {} } },
Blob: class Blob { constructor() {} },
URL: { createObjectURL: () => '', revokeObjectURL: () => {} },
FileReader: class FileReader {},
addEventListener: () => {},
removeEventListener: () => {},
};
sandbox.window = sandbox; // game.js uses `window.addEventListener`
sandbox.globalThis = sandbox;
vm.createContext(sandbox);
const src = fs.readFileSync(GAME_JS, 'utf8');
// game.js uses `const G = {...}` which is a lexical declaration — it isn't
// visible as a sandbox property after runInContext. We append an explicit
// export block that hoists the interesting symbols onto globalThis so the
// test harness can reach them without patching game.js itself.
const exportTail = `
;(function () {
const pick = (name) => {
try { return eval(name); } catch (_) { return undefined; }
};
globalThis.__smokeExport = {
G: pick('G'),
CONFIG: pick('CONFIG'),
BDEF: pick('BDEF'),
PDEFS: pick('PDEFS'),
EVENTS: pick('EVENTS'),
PHASES: pick('PHASES'),
tick: pick('tick'),
updateRates: pick('updateRates'),
writeCode: pick('writeCode'),
autoType: pick('autoType'),
buyBuilding: pick('buyBuilding'),
buyProject: pick('buyProject'),
saveGame: pick('saveGame'),
loadGame: pick('loadGame'),
initGame: pick('initGame'),
triggerEvent: pick('triggerEvent'),
resolveEvent: pick('resolveEvent'),
getClickPower: pick('getClickPower'),
};
})();`;
vm.runInContext(src + exportTail, sandbox, { filename: 'game.js' });
const exported = sandbox.__smokeExport;
// ---------- test harness ----------
const ROOT = process.cwd();
let failures = 0;
let passes = 0;
function assert(cond, msg) {
if (cond) {
passes++;
console.log(` ok ${msg}`);
} else {
failures++;
console.error(` FAIL ${msg}`);
}
function check(label, fn) {
try {
fn();
console.log(` ${label}`);
} catch (e) {
console.error(`${label}: ${e.message}`);
failures++;
}
}
function section(name) { console.log(`\n${name}`); }
const { G, CONFIG, BDEF, PDEFS, EVENTS } = exported;
console.log("--- The Beacon Smoke Test ---\n");
// ============================================================
// 1. BOOT — loading game.js must not throw, and core tables exist
// ============================================================
section('boot');
assert(typeof G === 'object' && G !== null, 'G global is defined');
assert(typeof exported.tick === 'function', 'tick() is defined');
assert(typeof exported.updateRates === 'function', 'updateRates() is defined');
assert(typeof exported.writeCode === 'function', 'writeCode() is defined');
assert(typeof exported.buyBuilding === 'function', 'buyBuilding() is defined');
assert(typeof exported.saveGame === 'function', 'saveGame() is defined');
assert(typeof exported.loadGame === 'function', 'loadGame() is defined');
assert(Array.isArray(BDEF) && BDEF.length > 0, 'BDEF is a non-empty array');
assert(Array.isArray(PDEFS) && PDEFS.length > 0, 'PDEFS is a non-empty array');
assert(Array.isArray(EVENTS) && EVENTS.length > 0, 'EVENTS is a non-empty array');
assert(G.flags && typeof G.flags === 'object', 'G.flags is initialized (not undefined)');
// 1. All JS files parse
console.log("[Syntax]");
const jsFiles = execSync("find . -name '*.js' -not -path './node_modules/*'", { encoding: "utf8" })
.trim().split("\n").filter(Boolean);
// Initialize as the browser would
G.startedAt = Date.now();
exported.updateRates();
// ============================================================
// 2. BASIC TICK — no NaN, no throw, rates sane
// ============================================================
section('basic tick loop');
for (let i = 0; i < 50; i++) exported.tick();
assert(!isNaN(G.code), 'G.code is not NaN after 50 ticks');
assert(!isNaN(G.compute), 'G.compute is not NaN after 50 ticks');
assert(G.code >= 0, 'G.code is non-negative');
assert(G.tick > 0, 'G.tick advanced');
// ============================================================
// 3. WRITE CODE — manual click produces code
// ============================================================
section('writeCode()');
const codeBefore = G.code;
exported.writeCode();
assert(G.code > codeBefore, 'writeCode() increases G.code');
assert(G.totalClicks === 1, 'writeCode() increments totalClicks');
// ============================================================
// 4. BUILDING PURCHASE — can afford and buy an autocoder
// ============================================================
section('buyBuilding(autocoder)');
G.code = 1000;
const priorCount = G.buildings.autocoder || 0;
exported.buyBuilding('autocoder');
assert(G.buildings.autocoder === priorCount + 1, 'autocoder count incremented');
assert(G.code < 1000, 'code was spent');
exported.updateRates();
assert(G.codeRate > 0, 'codeRate > 0 after buying an autocoder');
// ============================================================
// 5. GUARDRAIL — codeBoost is a PERSISTENT multiplier, not a per-tick rate
// Any debuff that does `G.codeBoost *= 0.7` inside a function that runs every
// tick will decay codeBoost exponentially. This caught #54's community_drama
// bug: its applyFn mutated codeBoost directly, so 100 ticks of the drama
// debuff left codeBoost at ~3e-16 instead of the intended 0.7.
// ============================================================
section('guardrail: codeBoost does not decay from any debuff');
G.code = 0;
G.codeBoost = 1;
G.activeDebuffs = [];
// Fire every event that sets up a debuff and has a non-zero weight predicate
// if we force the gating condition. We enable the predicates by temporarily
// setting the fields they check; actual event weight() doesn't matter here.
G.ciFlag = 1;
G.deployFlag = 1;
G.buildings.ezra = 1;
G.buildings.bilbo = 1;
G.buildings.allegro = 1;
G.buildings.datacenter = 1;
G.buildings.community = 1;
G.harmony = 40;
G.totalCompute = 5000;
G.totalImpact = 20000;
for (const ev of EVENTS) {
try { ev.effect(); } catch (_) { /* alignment events may branch; ignore */ }
for (const f of jsFiles) {
check(`Parse ${f}`, () => {
execSync(`node --check ${f}`, { encoding: "utf8" });
});
}
const boostAfterAllEvents = G.codeBoost;
for (let i = 0; i < 200; i++) exported.updateRates();
assert(
Math.abs(G.codeBoost - boostAfterAllEvents) < 1e-9,
`codeBoost stable under updateRates() (before=${boostAfterAllEvents}, after=${G.codeBoost})`
);
// Clean up
G.activeDebuffs = [];
G.buildings.ezra = 0; G.buildings.bilbo = 0; G.buildings.allegro = 0;
G.buildings.datacenter = 0; G.buildings.community = 0;
G.ciFlag = 0; G.deployFlag = 0;
// ============================================================
// 6. GUARDRAIL — updateRates() is idempotent per tick
// Calling updateRates twice with the same inputs should produce the same rates.
// (Catches accidental += against a non-reset field.)
// ============================================================
section('guardrail: updateRates is idempotent');
G.buildings.autocoder = 5;
G.codeBoost = 1;
exported.updateRates();
const firstCodeRate = G.codeRate;
const firstComputeRate = G.computeRate;
exported.updateRates();
assert(G.codeRate === firstCodeRate, `codeRate stable across updateRates (${firstCodeRate} vs ${G.codeRate})`);
assert(G.computeRate === firstComputeRate, 'computeRate stable across updateRates');
// ============================================================
// 7. SAVE / LOAD ROUND-TRIP — core scalar fields survive
// ============================================================
section('save/load round-trip');
G.code = 12345;
G.totalCode = 98765;
G.phase = 3;
G.buildings.autocoder = 7;
G.codeBoost = 1.5;
G.flags = { creativity: true };
exported.saveGame();
// Reset to defaults by scrubbing a few fields
G.code = 0;
G.totalCode = 0;
G.phase = 1;
G.buildings.autocoder = 0;
G.codeBoost = 1;
G.flags = {};
const ok = exported.loadGame();
assert(ok, 'loadGame() returned truthy');
assert(G.code === 12345, `G.code restored (got ${G.code})`);
assert(G.totalCode === 98765, `G.totalCode restored (got ${G.totalCode})`);
assert(G.phase === 3, `G.phase restored (got ${G.phase})`);
assert(G.buildings.autocoder === 7, `autocoder count restored (got ${G.buildings.autocoder})`);
assert(Math.abs(G.codeBoost - 1.5) < 1e-9, `codeBoost restored (got ${G.codeBoost})`);
assert(G.flags && G.flags.creativity === true, 'flags.creativity restored');
// ============================================================
// 8. SUMMARY
// ============================================================
console.log(`\n---\n${passes} passed, ${failures} failed`);
if (failures > 0) {
process.exitCode = 1;
// 2. HTML script references exist
console.log("\n[HTML References]");
if (existsSync(join(ROOT, "index.html"))) {
const html = readFileSync(join(ROOT, "index.html"), "utf8");
const scriptRefs = [...html.matchAll(/src=["']([^"']+\.js)["']/g)].map(m => m[1]);
for (const ref of scriptRefs) {
check(`Script ref: ${ref}`, () => {
if (!existsSync(join(ROOT, ref))) throw new Error("File not found");
});
}
}
// 3. Game data structure check
console.log("\n[Game Data]");
check("js/data.js exists", () => {
if (!existsSync(join(ROOT, "js/data.js"))) throw new Error("Missing");
});
// 4. No banned providers
console.log("\n[Policy]");
check("No Anthropic references", () => {
try {
const result = execSync(
"grep -ril 'anthropic\\|claude-sonnet\\|claude-opus\\|sk-ant-' --include='*.js' --include='*.json' --include='*.html' . 2>/dev/null || true",
{ encoding: "utf8" }
).trim();
if (result) throw new Error(`Found in: ${result}`);
} catch (e) {
if (e.message.startsWith("Found")) throw e;
}
});
// Summary
console.log(`\n--- ${failures === 0 ? "ALL PASSED" : `${failures} FAILURE(S)`} ---`);
process.exit(failures > 0 ? 1 : 0);