Skip to content

Refactor main orchestration into modular helpers#2

Merged
PJensen merged 1 commit intomasterfrom
codex/refactor-main.js-for-maintainability
Nov 6, 2025
Merged

Refactor main orchestration into modular helpers#2
PJensen merged 1 commit intomasterfrom
codex/refactor-main.js-for-maintainability

Conversation

@PJensen
Copy link
Owner

@PJensen PJensen commented Nov 6, 2025

Summary

  • extract demo scene creation, active spell management, UI wiring, HUD feeds, and world event hooks into dedicated helpers
  • streamline src/main.js to orchestrate the new helpers and rendering responsibilities
  • keep bolt FX, message logging, and HUD updates grouped alongside their corresponding modules for easier future evolution

Testing

  • npm test (fails: ERR_MODULE_NOT_FOUND for src/lib/ecs-js/index.js when running tests)

https://chatgpt.com/codex/tasks/task_e_690b9dbd0ad08333a6ff19a7afddcdaa

Copilot AI review requested due to automatic review settings November 6, 2025 14:12
@PJensen PJensen merged commit 9b986c3 into master Nov 6, 2025
6 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js with 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.js from ~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));
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
world.on("castSpell", ({ actor, spellId, targetId }) => {
const who = nameOfEntity(actor);
const tgt = nameOfEntity(targetId || actor);
const s = getSpell(String(spellId || getActiveSpellId() || ""));
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
const s = getSpell(String(spellId || getActiveSpellId() || ""));
const s = getSpell(String((spellId ?? getActiveSpellId()) ?? ""));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants