This document outlines the remaining 5 files (5,275 lines) that need to be refactored to break them into smaller, more manageable modules. This is a continuation of the large file refactoring task.
Status: 80% Complete (8 of 10 files refactored)
| File | Lines | Target Split | Status |
|---|---|---|---|
| src/world/generation.ts | 1078 | 4 files | ✅ DONE |
| src/systems/region-manager.ts | 1064 | 3 files | ✅ DONE |
| src/ui/loading-screen.ts | 1063 | 3 files | ✅ DONE |
| src/audio/audio-system.ts | 1047 | 3 files | ✅ DONE |
| src/ui/analytics-debug.ts | 1023 | 3 files | ✅ DONE |
| TOTAL | 5,275 | 16 files | ⏳ 0% |
Current Structure:
- Type definitions (MapEntity, ObstacleData, WorldObjects, WeatherSystem)
- Constants (DEFAULT_MAP_CHUNK_SIZE, LAKE_BOUNDS, LAKE_ISLAND, ARPEGGIO_GROVE)
- Helper functions (getUnifiedGroundHeight, isPositionValid)
- Main functions (initWorld, safeAddFoliage, processMapEntity)
- Population functions (populateArpeggioGrove, populateLakeIsland, populateProceduralExtras)
- Public functions (spawnNearbyFoliage, initCriticalWorld, initWorldCritical, initWorldContent)
Split Plan:
Contains helper functions and utilities:
getUnifiedGroundHeight()- Ground height calculation with lake/island modifiersisPositionValid()- Position validation helper- Constants: LAKE_BOUNDS, LAKE_ISLAND, ARPEGGIO_GROVE
- Type definitions: MapEntity, ObstacleData
Contains population/decoration functions:
populateArpeggioGrove()- Grove population with musical florapopulateLakeIsland()- Lake island populationpopulateProceduralExtras()- Procedural extras generation
Contains core world generation:
initWorld()- Main world initializationsafeAddFoliage()- Safe foliage addition with validationprocessMapEntity()- Map entity processing logicinitCriticalWorld()/initWorldCritical()- Critical initialization
Re-exports all from split modules:
export * from './generation-utils.ts';
export * from './generation-decorators.ts';
export * from './generation-core.ts';Key Imports to Maintain:
import * as THREE from 'three';
import { updateProgress } from '../ui/index.ts';
import { createIntegratedFireflies, ... } from '../particles/index.ts';
import { CONFIG } from '../core/config.ts';
import { foliageGroup, ... } from './state.ts';Current Structure:
- RegionManager class with 30+ methods
- LOD management (setQuality, transitionLOD)
- Streaming management (updateVisibility, updateStreaming)
- Region culling and management
Split Plan:
Contains RegionManager class core:
- Constructor and initialization
- Core properties (regions, cellSize, lodManager, etc.)
- Basic region management methods
- Streaming queue management
- Public API: getCell, setQuality, getVisibleRegions
Contains LOD-related functionality:
transitionLOD()- LOD quality transitionsupdateVisibility()- Visibility cullingupdateStreaming()- Streaming updates- Distance-based LOD calculations
- Quality level management
Re-exports:
export * from './region-manager-core.ts';
export * from './region-manager-lod.ts';
export { RegionManager } from './region-manager-core.ts';Key Considerations:
- RegionManager is a large class - split methods logically
- Maintain all private properties and helper methods
- Keep imports consistent
Current Structure:
- LoadingScreen class
- UI rendering methods
- Progress tracking
- Phase management
- Animation and styling
Split Plan:
Contains UI rendering and DOM manipulation:
show()/hide()- Visibility controlcreateUI()- DOM creation- CSS/styling updates
- Animation frame updates
- DOM element references and setup
Contains progress tracking and phases:
updateProgress()- Progress updates- Phase management (trackPhase, reportPhase)
- Progress calculation
- Phase history tracking
- Statistics gathering
Re-exports all:
export * from './loading-screen-ui.ts';
export * from './loading-screen-progress.ts';Current Structure:
- AudioSystem class (large)
- Playback controls
- Volume/EQ management
- Playlist handling
- Beat sync integration
Split Plan:
Contains AudioSystem initialization:
- Constructor
- Initialization methods
- Core properties
- Web Audio API setup
- Context creation
Contains playback functionality:
play()/pause()/stop()- Playback controlsetVolume()/setEQ()- Audio parameter control- Playlist management
- Track switching
- Duration and time tracking
Re-exports:
export * from './audio-system-core.ts';
export * from './audio-system-playback.ts';
export { AudioSystem } from './audio-system-core.ts';Current Structure:
- AnalyticsDebug class
- UI rendering and visualization
- Event handling
- Data processing and display
- Inspector overlay
Split Plan:
Contains UI rendering:
createUI()- DOM creation- Visual rendering (canvas, charts)
- Layout and styling
- DOM update methods
- Display formatting
Contains event handling and logic:
- Event listeners
- Data processing
- State management
- Inspector logic
- Update handlers
Re-exports:
export * from './analytics-debug-ui.ts';
export * from './analytics-debug-handlers.ts';
export { AnalyticsDebug } from './analytics-debug-ui.ts';For each file, follow these steps:
-
Analyze Structure
- Read through the entire file
- Identify logical groupings
- Note interdependencies
-
Create Split Files
- Extract code into new modules
- Add JSDoc @file comments
- Maintain all imports
-
Update Imports/Exports
- Update import statements
- Ensure all exports are present
- Create barrel re-export file
-
Verify Functionality
- Check for circular imports
- Verify all types are accessible
- Run any available tests
-
Clean Up
- Remove unused imports
- Fix any linting issues
- Add module documentation
After completing each file:
-
Build Check
npm run build
-
Import Verification
- Search for imports from refactored files
- Verify no import paths break
- Check barrel exports work
-
Type Checking
- Verify TypeScript compiles
- Check for any type errors
-
Functional Testing
- Run relevant smoke tests
- Manual testing if needed
After all 5 files are refactored:
-
Run full test suite:
npm run test -
Build production:
npm run build
-
Verify no breaking changes:
- Check all imports resolve
- Verify functionality unchanged
- No new errors in console
✅ Improved code organization ✅ Easier navigation in IDEs ✅ Better separation of concerns ✅ Reduced cognitive load per file ✅ Easier for teams to work in parallel ✅ Maintained backward compatibility throughout
- Remaining Work: 5,275 lines across 5 files
- Target Split: 16 new modules + 5 barrel files
- Expected Result: All files under 750 lines
- Completion Time: ~2-3 hours of focused work
- Breaking Changes: None (100% backward compatible)
Next Steps:
- Start with generation.ts (largest remaining)
- Follow the split plan exactly as outlined
- Test each file after splitting
- Commit after each file is complete
- Run full test suite at the end