refactor: Major codebase refactoring for maintainability
All checks were successful
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 3m4s
All checks were successful
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 3m4s
Store refactoring (2138 → 1651 lines, 23% reduction): - Extract computed-stats.ts with 18 utility functions - Extract navigation-slice.ts for floor navigation actions - Extract study-slice.ts for study-related actions - Move fmt/fmtDec to computed-stats, re-export from formatting Page refactoring (2554 → 1695 lines, 34% reduction): - Use existing SpireTab component instead of inline render - Extract ActionButtons component - Extract CalendarDisplay component - Extract CraftingProgress component - Extract StudyProgress component - Extract ManaDisplay component - Extract TimeDisplay component - Create tabs/index.ts for cleaner exports This improves code organization and makes the codebase more maintainable.
This commit is contained in:
131
worklog.md
131
worklog.md
@@ -309,3 +309,134 @@ Stage Summary:
|
||||
- Multi-casting is fully functional
|
||||
- Game compiles and runs without errors
|
||||
- Lint passes with no issues
|
||||
|
||||
---
|
||||
## Task ID: 3 - Component Refactoring
|
||||
### Work Task
|
||||
Refactor `/home/z/my-project/src/app/page.tsx` to use existing tab components and extract new components. The file was ~2500 lines with inline render functions duplicating existing tab components.
|
||||
|
||||
### Work Summary
|
||||
**Components Created:**
|
||||
1. `ActionButtons.tsx` - Extracted from `renderActionButtons()`, handles main action buttons (Meditate, Climb, Study, Convert) and crafting action buttons
|
||||
2. `CalendarDisplay.tsx` - Extracted from `renderCalendar()`, renders the day calendar with incursion indicators
|
||||
3. `CraftingProgress.tsx` - Extracted from `renderCraftingProgress()`, shows design/preparation/application progress bars
|
||||
4. `StudyProgress.tsx` - Extracted from `renderStudyProgress()`, displays current study progress with cancel button
|
||||
5. `ManaDisplay.tsx` - New component for mana/gathering section with progress bar and gather button
|
||||
6. `TimeDisplay.tsx` - New component for day/hour display with pause toggle
|
||||
|
||||
**Tab Components Updated:**
|
||||
- `SpireTab.tsx` - Updated to include all functionality from inline version:
|
||||
- Multi-spell support with activeEquipmentSpells
|
||||
- Individual cast progress bars for each spell
|
||||
- DPS calculation for multiple spells
|
||||
- Parallel study support
|
||||
- Crafting progress display
|
||||
- ComboMeter integration
|
||||
- Known Spells display
|
||||
- Activity Log
|
||||
|
||||
**File Changes:**
|
||||
- `page.tsx` reduced from ~2555 lines to 1695 lines (34% reduction)
|
||||
- Removed inline render functions: `renderCalendar`, `renderActionButtons`, `renderCraftingProgress`, `renderStudyProgress`, `renderSpireTab`, `renderSpellsTab`, `renderLabTab`
|
||||
- Updated imports to use extracted components
|
||||
- Cleaned up unused imports (`MAX_DAY`, `INCURSION_START_DAY`, `MANA_PER_ELEMENT`)
|
||||
- Created `tabs/index.ts` for cleaner tab component exports
|
||||
- Updated `game/index.ts` to export all new components
|
||||
|
||||
**Results:**
|
||||
- All lint checks pass
|
||||
- Functionality preserved - all features working as before
|
||||
- Better code organization with reusable components
|
||||
- Easier maintenance with separated concerns
|
||||
|
||||
---
|
||||
## Task ID: 1 - Code Extraction
|
||||
### Work Task
|
||||
Extract computed stats and utility functions from `/home/z/my-project/src/lib/game/store.ts` into a new file `/home/z/my-project/src/lib/game/computed-stats.ts`. The store.ts was ~2100 lines with functions that could be better organized in a separate module.
|
||||
|
||||
### Work Summary
|
||||
**Created New File:** `computed-stats.ts`
|
||||
|
||||
**Functions Extracted:**
|
||||
1. `DEFAULT_EFFECTS` constant - Default empty effects object for computed effects
|
||||
2. `fmt` and `fmtDec` - Number formatting utilities (K, M, B suffixes)
|
||||
3. `getFloorMaxHP` - Floor HP calculation with guardian and scaling logic
|
||||
4. `getFloorElement` - Floor element determination from cycle
|
||||
5. `getActiveEquipmentSpells` - Helper to get all spells from equipped caster weapons
|
||||
6. `getEffectiveSkillLevel` - Helper for tiered skill level calculation
|
||||
7. `computeMaxMana` - Maximum mana calculation with effects
|
||||
8. `computeElementMax` - Elemental mana capacity calculation
|
||||
9. `computeRegen` - Mana regeneration rate calculation
|
||||
10. `computeEffectiveRegen` - Regen with dynamic special effects
|
||||
11. `computeClickMana` - Click mana gain calculation
|
||||
12. `getElementalBonus` - Elemental damage bonus helper
|
||||
13. `calcDamage` - Damage calculation with skills, pacts, and crits
|
||||
14. `calcInsight` - End-of-loop insight calculation
|
||||
15. `getMeditationBonus` - Meditation multiplier calculation
|
||||
16. `getIncursionStrength` - Time-based incursion penalty
|
||||
17. `canAffordSpellCost` - Check if player can afford spell
|
||||
18. `deductSpellCost` - Deduct spell cost from mana pool
|
||||
|
||||
**Files Updated:**
|
||||
- `store.ts`:
|
||||
- Added imports from computed-stats.ts
|
||||
- Removed duplicate function definitions
|
||||
- Kept local `getElementalBonus` helper (used only in store)
|
||||
- Re-exports `fmt` and `fmtDec` for backward compatibility
|
||||
- `formatting.ts`:
|
||||
- Added re-exports of `fmt` and `fmtDec` from computed-stats.ts
|
||||
|
||||
**Results:**
|
||||
- All lint checks pass
|
||||
- No functionality changed - pure refactoring
|
||||
- Better code organization with computed stats in dedicated module
|
||||
- Easier to test and maintain individual functions
|
||||
- Backward compatible - existing imports still work
|
||||
|
||||
---
|
||||
## Task ID: 2 - Store Slice Refactoring
|
||||
### Work Task
|
||||
Create two new store slices to reduce the size of `/home/z/my-project/src/lib/game/store.ts`:
|
||||
1. `navigation-slice.ts` - Extract navigation-related actions
|
||||
2. `study-slice.ts` - Extract study-related actions
|
||||
|
||||
### Work Summary
|
||||
**Created New Files:**
|
||||
|
||||
**1. `navigation-slice.ts`** - Floor navigation actions:
|
||||
- `NavigationActions` interface defining the action types
|
||||
- `createNavigationSlice()` factory function
|
||||
- `setClimbDirection()` - Set climbing direction (up/down)
|
||||
- `changeFloor()` - Manually change floors with respawn logic
|
||||
|
||||
**2. `study-slice.ts`** - Study system actions:
|
||||
- `StudyActions` interface defining the action types
|
||||
- `createStudySlice()` factory function
|
||||
- `startStudyingSkill()` - Begin studying a skill with prerequisite and cost checks
|
||||
- `startStudyingSpell()` - Begin studying a spell with cost checks
|
||||
- `cancelStudy()` - Cancel current study with progress retention bonus
|
||||
- `startParallelStudySkill()` - Start parallel study (requires Parallel Mind upgrade)
|
||||
- `cancelParallelStudy()` - Cancel parallel study
|
||||
|
||||
**Files Updated:**
|
||||
- `store.ts`:
|
||||
- Added imports for `createNavigationSlice` and `createStudySlice`
|
||||
- Added imports for `NavigationActions` and `StudyActions` interfaces
|
||||
- Updated `GameStore` interface to extend both new action interfaces
|
||||
- Spread the new slices into the store
|
||||
- Removed duplicated action implementations
|
||||
- Added re-exports for computed stats functions (`getFloorElement`, `computeMaxMana`, `computeRegen`, `computeClickMana`, `calcDamage`, `getMeditationBonus`, `getIncursionStrength`, `canAffordSpellCost`, `getFloorMaxHP`)
|
||||
- Added missing imports for `EQUIPMENT_TYPES` and `EquipmentInstance`
|
||||
|
||||
**Pattern Followed:**
|
||||
- Followed existing slice patterns from `familiar-slice.ts` and `crafting-slice.ts`
|
||||
- Used factory function pattern that accepts `set` and `get` from Zustand
|
||||
- Exported both the interface and factory function
|
||||
- Proper TypeScript typing throughout
|
||||
|
||||
**Results:**
|
||||
- All lint checks pass
|
||||
- No functionality changed - pure refactoring
|
||||
- Reduced store.ts size by extracting ~100 lines of action implementations
|
||||
- Better code organization with navigation and study logic in dedicated modules
|
||||
- Easier to maintain and extend individual features
|
||||
|
||||
Reference in New Issue
Block a user