Refactor main orchestration into modular helpers#2
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the main application code by extracting monolithic event handling and scene setup logic into separate, focused modules. The changes improve code organization and maintainability by following separation of concerns principles.
Key changes:
- Extracted world event handlers into
src/main/world/worldEvents.js(bolt FX manager, message logging, entity/item naming) - Moved UI event listeners into
src/main/ui/setupUIEventListeners.js - Created HUD feed updaters in
src/main/ui/hudFeeds.jswith caching logic - Extracted active spell controller into
src/main/spells/activeSpellController.js - Moved demo scene population to
src/main/scene/demoScene.js - Reduced
src/main.jsfrom ~850 lines to ~326 lines by removing inline implementations
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/world/worldEvents.js | New module containing world event handlers, bolt FX manager, message logging, and entity/item name formatting |
| src/main/ui/setupUIEventListeners.js | New module for UI event listeners including inventory, spells, and item interactions |
| src/main/ui/hudFeeds.js | New module providing cached HUD feed updaters for vitals and combat stats |
| src/main/spells/activeSpellController.js | New module managing active spell selection and player mana state |
| src/main/scene/demoScene.js | New module containing demo scene population logic (room building, player setup, item/monster spawning) |
| src/main.js | Significantly reduced by importing and using the new modules; now acts as application orchestrator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }); | ||
|
|
||
| addEventListener("ui:castActiveSpell", () => { | ||
| const handler = resolveRulesDispatcher(world, () => (playerEntity(world)?.id || 0)); |
There was a problem hiding this comment.
The resolveRulesDispatcher function is called multiple times in this file (lines 122, 130, 152, 159, 166) with the same arguments. Consider creating a reusable handler at the module level or in the outer function scope to avoid repeated function creation.
| world.on("castSpell", ({ actor, spellId, targetId }) => { | ||
| const who = nameOfEntity(actor); | ||
| const tgt = nameOfEntity(targetId || actor); | ||
| const s = getSpell(String(spellId || getActiveSpellId() || "")); |
There was a problem hiding this comment.
The fallback to getActiveSpellId() may be unexpected behavior. If spellId is explicitly provided (even if falsy), using the active spell as fallback could lead to confusion. Consider whether this fallback is intentional or if it should only apply when spellId is null/undefined.
| const s = getSpell(String(spellId || getActiveSpellId() || "")); | |
| const s = getSpell(String((spellId ?? getActiveSpellId()) ?? "")); |
Summary
src/main.jsto orchestrate the new helpers and rendering responsibilitiesTesting
https://chatgpt.com/codex/tasks/task_e_690b9dbd0ad08333a6ff19a7afddcdaa