File size: 5,389 Bytes
ea1996a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Debug Scenario Feature - Implementation Summary

## βœ… Completed

### What Was Built
A debug mode system for manual testing of combat scenarios in the Gradio web interface.

### Implementation Details

**1. Debug Scenarios Defined** (`web/app_gradio.py` lines 70-81)
```python
DEBUG_SCENARIOS = [
    ("Random Start", None, [], []),
    ("Goblin Fight", "Goblin Cave Entrance", ["Goblin"], []),
    ("Goblin with Treasure", "Goblin Cave Entrance", ["Goblin"], ["Hidden Chest"]),
    ("Wolf Pack", "Dark Forest Clearing", ["Wolf", "Wolf"], []),
    ("Skeleton Guardian", "Ancient Ruins", ["Skeleton"], ["Ancient Sword"]),
    ("Dragon Encounter", "Dragon's Lair Approach", ["Young Red Dragon"], ["Dragon Hoard"]),
    ("Safe Inn", "The Prancing Pony Inn", ["Innkeeper Butterbur"], ["Healing Potion"]),
    ("Shopping District", "The Market Square", ["Merchant", "Blacksmith"], []),
]
```

**2. UI Dropdown Added** (`web/app_gradio.py` lines 1117-1124)
- Dropdown appears after character selection
- Only visible when `settings.DEBUG_MODE = True`
- Populated with scenario names from `DEBUG_SCENARIOS` list
- Clear label: "πŸ§ͺ Debug Scenario (Optional)"

**3. Routing Function Created** (`web/app_gradio.py` lines 379-470)
- `load_character_with_debug()` intelligently routes to normal or debug loading
- If scenario selected: Loads character at specific location with pre-spawned NPCs/items
- If no scenario: Normal character load with random location
- Sets GM context with full character stats
- Returns welcome message with scenario info

**4. Load Button Updated** (`web/app_gradio.py` line 1367)
- Now accepts both character and scenario inputs
- Passes both to `load_character_with_debug()` function
- Outputs: character sheet, message input, chat history, character image

**5. Documentation Created**
- `docs/DEBUG_MODE.md` - Full documentation (3669 chars)
  - How to enable debug mode
  - Complete scenario list with purposes
  - Implementation details
  - Adding new scenarios
  - Use cases (combat testing, NPC hallucination testing, etc.)
- `README.md` - Added debug mode section
  - Quick overview in Commands Reference section
  - Links to full documentation

### Files Modified
1. `web/app_gradio.py`
   - Added `DEBUG_SCENARIOS` list (8 scenarios)
   - Added `debug_scenario_dropdown` UI component
   - Replaced `load_debug_scenario()` with `load_character_with_debug()` wrapper
   - Updated `load_btn.click()` to use new wrapper with 2 inputs

2. `dnd_rag_system/config/settings.py`
   - Temporarily set `DEBUG_MODE = True` for testing
   - Reverted to `DEBUG_MODE = False` (must be manually enabled)

3. `README.md`
   - Added "πŸ§ͺ Debug Mode - Testing Scenarios" section
   - Documented enable steps, features, and scenarios
   - Linked to full documentation

### Files Created
1. `docs/DEBUG_MODE.md` - Comprehensive debug mode documentation
2. `docs/DEBUG_SCENARIO_IMPLEMENTATION.md` - This summary file

## How to Use

### For End Users
1. Enable debug mode: Edit `dnd_rag_system/config/settings.py`, set `DEBUG_MODE = True`
2. Start Gradio: `python web/app_gradio.py`
3. Open browser: http://localhost:7860
4. Select character (Thorin or Elara)
5. Select debug scenario from dropdown (or leave blank for random start)
6. Click "Load Character"
7. Game starts in specific scenario with NPCs/items pre-spawned

### For Developers - Adding Scenarios
Edit `DEBUG_SCENARIOS` in `web/app_gradio.py`:
```python
DEBUG_SCENARIOS = [
    ...
    ("My Test Scenario", "Location Name", ["NPC1", "NPC2"], ["Item1"]),
]
```

Format: `(scenario_name, location_name, npcs_list, items_list)`

## Testing Status

βœ… **Syntax Check**: Python compilation successful
βœ… **Unit Tests**: All tests pass (location extraction, NPC filtering)
βœ… **Gradio Startup**: App starts successfully with debug mode enabled
βœ… **UI Visibility**: Dropdown only visible when `DEBUG_MODE = True`
βœ… **Code Review**: Clean implementation, no duplication

## Use Cases

This feature addresses the request for manual testing capabilities:

1. **Combat Testing** - Quickly test specific monster encounters without RNG
2. **Location Bug Testing** - Verify location doesn't teleport during combat
3. **NPC Hallucination Testing** - Test GM uses correct monster names (e.g., spawns Goblin, says "Goblin" not "Wolf")
4. **Shop System Testing** - Instant access to merchant NPCs
5. **Regression Testing** - Verify bug fixes work in controlled scenarios

## Next Steps (Optional)

Future enhancements could include:
- Load/save custom scenarios from JSON files
- Multi-step scripted scenarios (spawn enemy after 3 turns)
- HP/gold overrides for edge case testing
- Scenario victory conditions
- Character state presets (wounded, low on spells, etc.)

## Related Context

This feature completes the work interrupted in the previous session:
- **Previous**: DEBUG_SCENARIOS defined, `load_debug_scenario()` started
- **This Session**: UI integrated, routing logic completed, fully documented
- **Bug Fixes**: Works alongside location extraction and NPC hallucination filtering

## Summary

**Status**: βœ… COMPLETE

The debug scenario feature is fully implemented, tested, and documented. Users can now enable DEBUG_MODE to access predefined test scenarios via a dropdown in the Gradio UI. The feature integrates seamlessly with existing character loading and does not affect normal gameplay when disabled.