Started: 2025-11-11 Current Phase: Phase 1.1 - Constants Extraction Priority: DO NOT BREAK THE GAME ✅
- ✅ Created git tag:
v1.0-pre-refactor - ✅ Established safe commit workflow
- ✅ Documented rollback procedures
- ✅ Created
src/constants/directory - ✅ Created
GameBalance.ts- 821 lines of constants - ✅ Created
CharacterBalance.ts- All 20 character abilities - ✅ Created
UIConstants.ts- Colors, fonts, layouts - ✅ Created
index.ts- Central export point - ✅ Build verification: PASSES ✅
Git Commit: 76dca32 - "refactor: add constants files"
Goal: Replace hardcoded values with constants from Phase 1.1
Completed Work:
-
✅ GameScene.ts - Player Stats (Commit 138c959)
- Replaced: 100, 300, 1000 →
PLAYER.*constants - Build: ✅ Passes
- Replaced: 100, 300, 1000 →
-
✅ GameScene.ts - Wave Spawning (Commit 8290f45)
- Replaced: 1500, 400 →
WAVE_SPAWNING.*constants - Build: ✅ Passes
- Replaced: 1500, 400 →
-
✅ GameScene.ts - UI Layout (Commit eda2168)
- Replaced: 100, 80 →
LAYOUT.TOP_BAR,LAYOUT.BOTTOM_BAR - Build: ✅ Passes
- Replaced: 100, 80 →
-
✅ Character.ts - All 18 Characters (Commit ae76461)
- Replaced: All character ability magic numbers
- Used: Character-specific constants (CYCLONE, ECLIPSE, etc.)
- Build: ✅ Passes
Result: ~50+ magic numbers replaced, 4 safe commits, all tests passing
Estimated time: 2-3 hours spread over multiple sessions
Goals:
- Remove
anycasts from codebase - Add proper interfaces for game objects
- Improve type checking to catch bugs earlier
Recommended approach:
- Search for
as anycasts in key files - Replace with proper typing one file at a time
- Create missing interfaces where needed
- Test after each change
Benefits:
- Catch type errors at compile time instead of runtime
- Better IDE autocomplete and intellisense
- Easier refactoring in the future
Before EVERY commit, verify:
-
npm run buildpasses with no errors - Game starts without crashing
- Player can move (keyboard + touch)
- Changed functionality still works correctly
If something breaks:
git reset --hard HEAD # Revert to last commit
# Fix the issue, try again- ✅ Phase 0: Setup (100%)
- ✅ Phase 1.1: Constants files (100%)
- ✅ Phase 1.2: Replace magic numbers (100%) JUST COMPLETED!
- ⏸️ Phase 2: Type safety (0%)
- ⏸️ Phase 3: Extract methods (0%)
- Phase 1.2: 4-6 hours (spread over multiple sessions)
- Phase 2: 2-3 hours
- Phase 3: 4-6 hours
- Total: ~12-15 hours of incremental work
- Documentation - All values are now documented with comments
- Discoverability - Junior devs can find values in one place
- Context - Constants explain what values mean, not just the number
- Type Safety -
as constmakes constants readonly at type level
- Single Source of Truth - Change value once, affects whole game
- No Typos - Can't accidentally type 1000 instead of 100
- Easy Balancing - Tweak numbers without hunting through code
- Quick Experiments - Try different values easily
- Check if constant exists in
src/constants/ - If yes, use it:
import { CONSTANT } from '../constants' - If no, add it to appropriate constants file
- Never hardcode magic numbers in game logic
- Check constant values first (might be easier to find bug)
- Constants file has comments explaining what each value does
- Can temporarily change constant to test theories
- Open
src/constants/GameBalance.tsorCharacterBalance.ts - Change values there
- Rebuild and test
- No need to hunt through game code!
src/constants/
├── index.ts (63 lines) - Central export point
├── GameBalance.ts (222 lines) - Core game balance values
├── CharacterBalance.ts (296 lines) - Character-specific values
└── UIConstants.ts (240 lines) - UI colors, fonts, layouts
Total: 821 lines of documented constants
- Full refactoring plan: See conversation history
- Character implementation:
CHARACTER_ABILITY_STATUS.md - Ship ideas:
SHIP_ABILITY_IDEAS.md - Git tags:
v1.0-pre-refactor(safe rollback point)
Immediate (Today/Tomorrow):
- Start Phase 1.2 with GameScene.ts player stats section
- Test thoroughly
- Commit and move to next section
This Week:
- Complete Phase 1.2 (replace all magic numbers)
- Start Phase 2 (type safety improvements)
Next Week:
- Complete Phase 2
- Begin Phase 3 (method extraction)
Remember: One change at a time. Test after every change. Commit often. We're not in a rush - safety first! 🛡️