3.3 KiB
AGENTS.md — Zelda Dungeon Quest
Run Commands
- Browser dev:
npm run dev→npx serve . -p 3000, openhttp://localhost:3000 - Electron:
npm start(requires--no-sandboxon Linux, orELECTRON_DISABLE_SANDBOX=1) - Node tests:
node test-full-node.js(VM-based, simulates browser env) - Regenerate bosses:
node generate-bosses.js(rewritessrc/data/bosses.js)
Module System — Critical
This project uses a custom browser polyfill (src/browser-polyfill.js) that makes Node-style module.exports / require() work in the browser. Every source file must follow this pattern:
-
Export via
module.exportsat the end of each file:if (typeof module !== 'undefined' && module.exports) { module.exports = { exportedName1, exportedName2 }; } -
Symbols go to
window— the polyfill'smodule.exportssetter mirrors all exported properties towindow. Cross-module access reads fromwindow. -
moduleKeysregistry —src/browser-polyfill.jsmaintains amoduleKeysmap that tellsrequire()whichwindowkeys belong to each module path. When you add new exports to any module, you MUST add them to the matching entry inmoduleKeys, orrequire()will not return them. -
Script load order —
index.htmlloads scripts in a strict sequence. The polyfill loads first, then modules in dependency order. Adding a new script requires inserting it at the correct position inindex.html.
File Architecture
renderer.js ← Legacy prototype (3-room, standalone). NOT used by index.html.
src/app.js ← Bootstrap: init, game loop, screen switching
src/browser-polyfill.js ← CommonJS polyfill (moduleKeys registry)
src/core/ ← Constants, RNG, utilities (loaded first)
src/data/ ← Static definitions: themes, dungeons(100), enemies(22), weapons(12), bosses(100), items
src/generator/ ← Procedural generation: dungeon layout, rooms, puzzles, placement
src/game/ ← Engine: state, movement, combat, AI, items, transitions
src/input/ ← Keyboard tracking, action bindings
src/rendering/ ← Canvas rendering: tiles, entities, HUD, effects
src/menu/ ← Title screen, dungeon select, inventory overlay, end screens
src/save/ ← localStorage save/load
Grid: 32×24 tiles, 32px each. Canvas: 640×480.
Known Bug
src/app.js:390 — The init() function's closing } appears before lines that should be inside it (screen setup, game loop start, debug logging). Lines 392-406 are outside the function scope. Move the closing brace to after line 406 to fix.
Conventions
- All source files start with
'use strict' - Constants live in
src/core/constants.js; other modules import viarequire gameStateandinputSystemare module-level globals exposed towindowbyapp.jsctx,debugCtx,menuOverlayare exposed towindowbyapp.jsfor cross-module rendering- Screen states use string constants:
SCREEN_TITLE,SCREEN_DUNGEON_SELECT, etc. - Debug mode: append
?debug=1to URL;F1toggles overlay in-game - Console API (browser):
_genDungeon(id),spawnEnemy(type),giveWeapon(name),teleportToRoom(idx),dumpState()