mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
refactor: remove outdated documentation
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
# CRITICAL FIX: Method Removal Bug
|
||||
|
||||
## Issue Found
|
||||
The `remove_methods()` function was not persisting changes to the main file content.
|
||||
|
||||
### Root Cause
|
||||
```python
|
||||
# OLD CODE (line 302)
|
||||
return '\n'.join(updated_lines) # Returns string but doesn't update self.content
|
||||
```
|
||||
|
||||
When `remove_methods()` was called during auto-integrate:
|
||||
1. It would compute the updated lines correctly
|
||||
2. It would return the string
|
||||
3. BUT: It didn't update `self.content` or `self.lines`
|
||||
4. So when `self.content` was written to disk, the methods were STILL THERE
|
||||
|
||||
### The Fix
|
||||
```python
|
||||
# NEW CODE (line 302-305)
|
||||
# Update both self.lines and self.content
|
||||
self.lines = updated_lines
|
||||
self.content = '\n'.join(updated_lines)
|
||||
return self.content
|
||||
```
|
||||
|
||||
This ensures that:
|
||||
1. `self.lines` reflects the current state
|
||||
2. `self.content` is updated with the removed methods
|
||||
3. When written to disk, the methods are actually removed
|
||||
|
||||
## Verification
|
||||
|
||||
Before fix:
|
||||
- Main file still contained all 72 functions (Phase 1 methods removed but Phase 2 methods still there)
|
||||
- lock-graphics.js never created (because removal failed)
|
||||
|
||||
After fix:
|
||||
- `remove_methods()` properly updates internal state
|
||||
- Methods are actually removed from the file
|
||||
- All downstream operations work correctly
|
||||
|
||||
## Testing
|
||||
|
||||
The fix has been applied. Phase 2 extraction can now be run correctly:
|
||||
|
||||
```bash
|
||||
cd /home/cliffe/Files/Projects/Code/BreakEscape/BreakEscape
|
||||
|
||||
python3 scripts/extract_lockpicking_methods.py \
|
||||
--methods "createLockBackground,createTensionWrench,createHookPick" \
|
||||
--output-file "js/minigames/lockpicking/lock-graphics.js" \
|
||||
--class-name "LockGraphics" \
|
||||
--replace-this --auto-integrate \
|
||||
--update-main-file "js/minigames/lockpicking/lockpicking-game-phaser.js" \
|
||||
--module-instance-name "lockGraphics" --show-dependencies
|
||||
```
|
||||
|
||||
Expected behavior:
|
||||
- ✅ lock-graphics.js created with 3 methods
|
||||
- ✅ Import statement added to main file
|
||||
- ✅ Module initialization added to constructor
|
||||
- ✅ 3 methods removed from main file (NOW WORKS!)
|
||||
- ✅ Method calls updated to use this.lockGraphics
|
||||
- ✅ Main file should have 69 functions (72 - 3)
|
||||
@@ -1,191 +0,0 @@
|
||||
# Extraction Script Fixes - Phase 1 Issue Resolution
|
||||
|
||||
## Problem Summary
|
||||
Phase 1 extraction created a working module but had integration issues that required manual fixes:
|
||||
- Methods used `parent.` instead of `this.parent.`
|
||||
- Import statement wasn't added to main file
|
||||
- Method calls weren't updated to use `this.lockConfig`
|
||||
|
||||
## Root Causes Identified
|
||||
|
||||
### Issue 1: Parent Reference Pattern
|
||||
**File**: `scripts/extract_lockpicking_methods.py` (line ~47)
|
||||
**Method**: `MethodExtractor.replace_this_with_parent()`
|
||||
**Problem**: Replaced `this.` with `parent.` (bare reference) instead of `this.parent.`
|
||||
```python
|
||||
# OLD: Bad pattern
|
||||
modified_line = re.sub(r'\bthis\.', 'parent.', modified_line)
|
||||
|
||||
# NEW: Correct pattern
|
||||
modified_line = re.sub(r'\bthis\.', 'this.parent.', modified_line)
|
||||
```
|
||||
**Impact**: Caused `ReferenceError: lockConfig is not defined` because methods couldn't access parent state
|
||||
|
||||
### Issue 2: Import Statement Bug
|
||||
**File**: `scripts/extract_lockpicking_methods.py` (line ~315)
|
||||
**Method**: `MainFileUpdater.add_import()`
|
||||
**Problem**: Used JavaScript method `startsWith()` instead of Python method `startswith()`
|
||||
```python
|
||||
# OLD: Syntax error (JavaScript syntax in Python)
|
||||
if line.startsWith('import '):
|
||||
|
||||
# NEW: Correct Python syntax
|
||||
if line.startswith('import '):
|
||||
```
|
||||
**Impact**: Import statements weren't being added to main file
|
||||
|
||||
### Issue 3: Missing Module Initialization
|
||||
**File**: `scripts/extract_lockpicking_methods.py` (line ~337)
|
||||
**Method**: `MainFileUpdater.add_module_initialization()`
|
||||
**Problem**: Method existed but wasn't being called in auto-integrate flow
|
||||
**Impact**: `this.lockConfig` was never initialized, causing undefined references
|
||||
|
||||
### Issue 4: Incorrect Method Call Replacement
|
||||
**File**: `scripts/extract_lockpicking_methods.py` (line ~386)
|
||||
**Method**: `MainFileUpdater.replace_method_calls()`
|
||||
**Problem**: Replaced `this.method()` with `moduleInstance.method()` instead of `this.moduleInstance.method()`
|
||||
```python
|
||||
# OLD: Missing this. prefix
|
||||
replacement = f'{module_instance}.{method_name}('
|
||||
|
||||
# NEW: Include this. prefix
|
||||
replacement = f'this.{module_instance}.{method_name}('
|
||||
```
|
||||
**Impact**: Method calls wouldn't work because they weren't properly scoped to instance
|
||||
|
||||
### Issue 5: Auto-Integrate Not Using Updater Methods
|
||||
**File**: `scripts/extract_lockpicking_methods.py` (lines ~694-720)
|
||||
**Section**: Main execution auto-integrate block
|
||||
**Problem**: Implemented import/removal inline instead of calling `MainFileUpdater` methods
|
||||
**Impact**: Content updates weren't persisted properly between operations
|
||||
|
||||
## Fixes Applied
|
||||
|
||||
### Fix 1: Parent Reference Pattern ✅
|
||||
```python
|
||||
def replace_this_with_parent(self, code: str, use_parent_keyword: bool = True) -> str:
|
||||
# Replace 'this.' with 'this.parent.' for method bodies
|
||||
modified_line = re.sub(r'\bthis\.', 'this.parent.', modified_line)
|
||||
return '\n'.join(modified_lines)
|
||||
```
|
||||
|
||||
### Fix 2: Python Syntax ✅
|
||||
```python
|
||||
def add_import(self, class_name: str, module_path: str) -> str:
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith('import '): # Python method, not JavaScript
|
||||
insert_idx = i + 1
|
||||
```
|
||||
|
||||
### Fix 3: Module Initialization Called ✅
|
||||
```python
|
||||
if args.auto_integrate:
|
||||
# Now properly calls add_module_initialization
|
||||
main_updater.add_module_initialization(module_instance_name, class_name)
|
||||
print(f" ✓ Added module initialization in constructor")
|
||||
```
|
||||
|
||||
### Fix 4: Correct Method Call Pattern ✅
|
||||
```python
|
||||
def replace_method_calls(self, method_names: List[str], module_instance: str) -> str:
|
||||
for method_name in method_names:
|
||||
pattern = rf'this\.{method_name}\('
|
||||
replacement = f'this.{module_instance}.{method_name}(' # Include this.
|
||||
updated = re.sub(pattern, replacement, updated)
|
||||
```
|
||||
|
||||
### Fix 5: Auto-Integrate Uses Proper Methods ✅
|
||||
```python
|
||||
if args.auto_integrate:
|
||||
print(f"\n 🔧 Auto-integrating...")
|
||||
|
||||
# 1. Add import statement
|
||||
main_updater.add_import(class_name, f'./{import_path}')
|
||||
print(f" ✓ Added import statement")
|
||||
|
||||
# 2. Add module initialization in constructor
|
||||
main_updater.add_module_initialization(module_instance_name, class_name)
|
||||
print(f" ✓ Added module initialization in constructor")
|
||||
|
||||
# 3. Remove old methods from main file
|
||||
main_updater.remove_methods(method_names)
|
||||
print(f" ✓ Removed {len(method_names)} methods from main file")
|
||||
|
||||
# 4. Replace method calls to use module instance
|
||||
main_updater.replace_method_calls(method_names, module_instance_name)
|
||||
print(f" ✓ Updated method calls to use this.{module_instance_name}")
|
||||
```
|
||||
|
||||
### Fix 6: Content Persistence ✅
|
||||
All updater methods now update `self.content` after changes:
|
||||
```python
|
||||
# After each operation
|
||||
self.content = updated_content # Persist for next operation
|
||||
return self.content
|
||||
```
|
||||
|
||||
## Verification Results
|
||||
|
||||
### Documentation Updated
|
||||
- Module generator now correctly documents `this.parent` pattern
|
||||
- All comments reference proper instance access
|
||||
|
||||
### Pattern Consistency
|
||||
✅ Constructor: `constructor(parent) { this.parent = parent; }`
|
||||
✅ Methods: Use `this.parent.property` throughout
|
||||
✅ Main file: Uses `this.lockConfig.method()` for calls
|
||||
✅ Initialization: `this.lockConfig = new LockConfiguration(this);`
|
||||
|
||||
## Testing - Phase 2 Ready
|
||||
|
||||
The fixed script should now:
|
||||
1. ✅ Replace `this.` with `this.parent.` in extracted methods
|
||||
2. ✅ Add import statements correctly
|
||||
3. ✅ Initialize modules in constructor
|
||||
4. ✅ Replace method calls with `this.moduleInstance.method()`
|
||||
5. ✅ Remove old methods from main file
|
||||
6. ✅ Persist all changes properly
|
||||
|
||||
## Next Steps
|
||||
|
||||
### To Use Fixed Script for Phase 2:
|
||||
```bash
|
||||
cd /home/cliffe/Files/Projects/Code/BreakEscape/BreakEscape
|
||||
|
||||
python3 scripts/extract_lockpicking_methods.py \
|
||||
--methods "createLockBackground,createTensionWrench,createHookPick" \
|
||||
--output-file "js/minigames/lockpicking/lock-graphics.js" \
|
||||
--class-name "LockGraphics" \
|
||||
--replace-this --auto-integrate \
|
||||
--update-main-file "js/minigames/lockpicking/lockpicking-game-phaser.js" \
|
||||
--module-instance-name "lockGraphics" --show-dependencies
|
||||
```
|
||||
|
||||
### Expected Output:
|
||||
```
|
||||
✅ Success! Created: js/minigames/lockpicking/lock-graphics.js
|
||||
|
||||
📝 Updating main file: js/minigames/lockpicking/lockpicking-game-phaser.js
|
||||
🔧 Auto-integrating...
|
||||
✓ Added import statement
|
||||
✓ Added module initialization in constructor
|
||||
✓ Removed 3 methods from main file
|
||||
✓ Updated method calls to use this.lockGraphics
|
||||
|
||||
✅ Updated: js/minigames/lockpicking/lockpicking-game-phaser.js
|
||||
```
|
||||
|
||||
## Files Modified
|
||||
- `scripts/extract_lockpicking_methods.py`: All 5 fixes applied
|
||||
- `lock-configuration.js`: Already manually fixed with `this.parent` pattern
|
||||
- `lockpicking-game-phaser.js`: Already manually fixed with proper initialization and calls
|
||||
|
||||
## Safeguards for Future Phases
|
||||
|
||||
✅ **Extraction**: Uses `this.parent` pattern automatically
|
||||
✅ **Initialization**: Added in constructor automatically
|
||||
✅ **Import**: Added to top of file automatically
|
||||
✅ **Method Calls**: Replaced with `this.moduleInstance.method()` automatically
|
||||
✅ **Removal**: Old methods removed from main file automatically
|
||||
|
||||
**Result**: No manual fixes needed for Phases 2-12! 🎉
|
||||
@@ -1,246 +0,0 @@
|
||||
# Phase Execution Quick Reference - UPDATED
|
||||
|
||||
After script fixes, phases now run cleanly with automatic integration!
|
||||
|
||||
## Phase 1: ✅ COMPLETE (Manually Fixed)
|
||||
|
||||
**What was done**: Lock Configuration extracted
|
||||
- Module: `lock-configuration.js` (128 LOC, 7 functions)
|
||||
- Main file updated with import, initialization, and method calls
|
||||
- Status: Working after manual fixes
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Lock Graphics (3 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `createLockBackground` - Creates the lock cylinder background
|
||||
- `createTensionWrench` - Creates tension wrench tool
|
||||
- `createHookPick` - Creates hook pick tool
|
||||
|
||||
**Command**:
|
||||
```bash
|
||||
python3 scripts/extract_lockpicking_methods.py \
|
||||
--methods "createLockBackground,createTensionWrench,createHookPick" \
|
||||
--output-file "js/minigames/lockpicking/lock-graphics.js" \
|
||||
--class-name "LockGraphics" \
|
||||
--replace-this --auto-integrate \
|
||||
--update-main-file "js/minigames/lockpicking/lockpicking-game-phaser.js" \
|
||||
--module-instance-name "lockGraphics" --show-dependencies
|
||||
```
|
||||
|
||||
**Expected Results**:
|
||||
- ✅ File created: `lock-graphics.js`
|
||||
- ✅ Import added to main file
|
||||
- ✅ Initialization added: `this.lockGraphics = new LockGraphics(this)`
|
||||
- ✅ Methods removed from main file
|
||||
- ✅ Method calls updated: `this.lockGraphics.createLockBackground()`
|
||||
- ✅ No manual fixes needed
|
||||
|
||||
**Verification**:
|
||||
```bash
|
||||
python3 scripts/list_js_functions.py --file js/minigames/lockpicking/lockpicking-game-phaser.js --count
|
||||
# Should show 69 functions (72 - 3 extracted)
|
||||
|
||||
python3 scripts/list_js_functions.py --file js/minigames/lockpicking/lock-graphics.js --count
|
||||
# Should show 4 functions (constructor + 3 methods)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 3: Key Data Generator (8 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `generateKeyDataFromPins`
|
||||
- `generateRandomKeyData`
|
||||
- `getKeyDataForPinHeights`
|
||||
- `modifyKeyDataForPinHeights`
|
||||
- `applyKeyDataToLock`
|
||||
- `validateKeyWithLock`
|
||||
- `calculateKeyCorrectness`
|
||||
- `analyzeKeyProfile`
|
||||
|
||||
**Command**:
|
||||
```bash
|
||||
python3 scripts/extract_lockpicking_methods.py \
|
||||
--methods "generateKeyDataFromPins,generateRandomKeyData,getKeyDataForPinHeights,modifyKeyDataForPinHeights,applyKeyDataToLock,validateKeyWithLock,calculateKeyCorrectness,analyzeKeyProfile" \
|
||||
--output-file "js/minigames/lockpicking/key-data-generator.js" \
|
||||
--class-name "KeyDataGenerator" \
|
||||
--replace-this --auto-integrate \
|
||||
--update-main-file "js/minigames/lockpicking/lockpicking-game-phaser.js" \
|
||||
--module-instance-name "keyDataGen" --show-dependencies
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 4: Pin System (13 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `createPinObject`
|
||||
- `calculatePinHeight`
|
||||
- `bindPin`
|
||||
- `setPin`
|
||||
- `resetPin`
|
||||
- `getTensionForPin`
|
||||
- `calculateShearLine`
|
||||
- `checkPinAtShearLine`
|
||||
- `handlePinFeedback`
|
||||
- `updatePinState`
|
||||
- `animatePinMovement`
|
||||
- `getPinBindingOrder`
|
||||
- `validatePinConfiguration`
|
||||
|
||||
---
|
||||
|
||||
## Phase 5: Key Rendering (17 functions) ⚠️ LARGEST
|
||||
|
||||
**Methods to extract**:
|
||||
- `createKey`
|
||||
- `drawKeyWithRenderTexture`
|
||||
- `renderKeyProfile`
|
||||
- `updateKeyPosition`
|
||||
- `updateKeyVisualsForInsertion`
|
||||
- `createKeyGraphics`
|
||||
- `drawKeyShaft`
|
||||
- `drawKeyHead`
|
||||
- `drawKeyCuts`
|
||||
- `drawKeyRidges`
|
||||
- `createKeyOutline`
|
||||
- `applyKeyTexture`
|
||||
- `updateKeyTransform`
|
||||
- `animateKeyInsertion`
|
||||
- `renderKeyInserted`
|
||||
- `createKeyClickZone`
|
||||
- `updateKeyClickZone`
|
||||
|
||||
---
|
||||
|
||||
## Phase 6: Key Selection UI (4 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `showKeySelectionUI`
|
||||
- `createKeySelectionContainer`
|
||||
- `displayAvailableKeys`
|
||||
- `selectKeyFromInventory`
|
||||
|
||||
---
|
||||
|
||||
## Phase 7: Input Handlers (4 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `setupInputHandlers`
|
||||
- `handleMouseDown`
|
||||
- `handleMouseMove`
|
||||
- `handleMouseUp`
|
||||
|
||||
---
|
||||
|
||||
## Phase 8: Completion Handler (2 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `handleLockSuccess`
|
||||
- `handleLockFailure`
|
||||
|
||||
---
|
||||
|
||||
## Phase 9: UI Elements (6 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `updateFeedback`
|
||||
- `createUIElements`
|
||||
- `updatePinVisuals`
|
||||
- `createShearLine`
|
||||
- `highlightBindingPin`
|
||||
- `updateProgressIndicator`
|
||||
|
||||
---
|
||||
|
||||
## Phase 10: Mode Switching (2 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `switchToPickMode`
|
||||
- `switchToKeyMode`
|
||||
|
||||
---
|
||||
|
||||
## Phase 11: Key Insertion/Animation (8 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `insertKey`
|
||||
- `animateKeyInsertion`
|
||||
- `handleKeyInsertion`
|
||||
- `testKeyAgainstLock`
|
||||
- `applyKeyToLock`
|
||||
- `showKeyInsertionFeedback`
|
||||
- `resetKeyInsertion`
|
||||
- `finalizeKeyMode`
|
||||
|
||||
---
|
||||
|
||||
## Phase 12: Utilities & Other (7 functions)
|
||||
|
||||
**Methods to extract**:
|
||||
- `shuffleArray`
|
||||
- `flashWrenchRed`
|
||||
- `start`
|
||||
- `complete`
|
||||
- `cleanup`
|
||||
- And 2 others from remaining functions
|
||||
|
||||
---
|
||||
|
||||
## Running All Phases (Batch)
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
cd /home/cliffe/Files/Projects/Code/BreakEscape/BreakEscape
|
||||
|
||||
# Phase 2
|
||||
python3 scripts/extract_lockpicking_methods.py --methods "..." --output-file "..." --auto-integrate --update-main-file "..."
|
||||
|
||||
# Phase 3
|
||||
python3 scripts/extract_lockpicking_methods.py --methods "..." --output-file "..." --auto-integrate --update-main-file "..."
|
||||
|
||||
# Continue for Phases 4-12...
|
||||
```
|
||||
|
||||
## Progress Tracking
|
||||
|
||||
| Phase | Component | Functions | Status | Manual Fix? |
|
||||
|-------|-----------|-----------|--------|------------|
|
||||
| 1 | Lock Configuration | 6 | ✅ Complete | ⚠️ Manual fixes applied |
|
||||
| 2 | Lock Graphics | 3 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 3 | Key Data Generator | 8 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 4 | Pin System | 13 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 5 | Key Rendering | 17 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 6 | Key Selection UI | 4 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 7 | Input Handlers | 4 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 8 | Completion Handler | 2 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 9 | UI Elements | 6 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 10 | Mode Switching | 2 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 11 | Key Insertion/Animation | 8 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
| 12 | Utilities | 7 | 📋 Ready | ✅ Auto (script fixed) |
|
||||
|
||||
**Total**: 78 functions across 12 phases
|
||||
**Completion**: 6/78 (7.7%)
|
||||
**Time estimate**: ~2-3 hours for all phases (with no manual fixes needed)
|
||||
|
||||
## Key Improvements in Fixed Script
|
||||
|
||||
✅ **Automatic Import Addition** - No need to manually add imports
|
||||
✅ **Automatic Initialization** - Constructor setup handled automatically
|
||||
✅ **Correct Parent Reference** - Uses `this.parent` pattern throughout
|
||||
✅ **Automatic Method Call Updates** - Uses `this.moduleInstance.method()` pattern
|
||||
✅ **Automatic Method Removal** - Old methods deleted from main file
|
||||
✅ **Content Persistence** - All changes properly saved and persisted
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. Run Phase 2 with the fixed script
|
||||
2. Verify: Check function counts match expected
|
||||
3. Test: Reload browser and verify no console errors
|
||||
4. Commit: `git add . && git commit -m "Extract: Lock Graphics module"`
|
||||
5. Repeat for Phases 3-12
|
||||
|
||||
**No manual code fixes needed after Phase 2!** 🎉
|
||||
Reference in New Issue
Block a user