Update room navigator skill with mock_interact and room verification
Replaces click-based navigation with mock_interact(0) on TransitionPiece nodes, adds get_current_room_name() verification pattern, and documents the MCP busy protocol for walk animation timeouts.
This commit is contained in:
@@ -79,13 +79,14 @@ python tools/kq4_room_navigator.py --from kq4_004_ogres_cottage --to kq4_092_lol
|
||||
|
||||
5. **Connect to MCP** (runtime): Opens TCP connection to port 9090
|
||||
6. **For each navigation step**:
|
||||
a. `find_nodes_by_class(class_name="TransitionPiece")` — discover all transition pieces in current scene
|
||||
b. Match the exit node name from our path → get runtime position + polygon
|
||||
c. Compute click coordinate: centroid of the TransitionPiece's `polygon`, transformed to viewport coordinates
|
||||
d. `click(x, y)` — trigger the transition
|
||||
e. Wait for transition animation (2-3s via `wait` command or poll-loop)
|
||||
f. **Verify**: `eval("return get_tree().root.get_node_or_null('Node2D/SceneViewport/background').name")` to confirm we've entered the expected room
|
||||
g. If verification fails, retry up to 2 times with adjusted coordinates
|
||||
a. Verify starting room: `eval("return get_node('/root/Node2D').get_current_room_name()")` returns the current room's node name (e.g., `"kq4_003_fountain_pool"`). This convenience function on MainGame simplifies verification compared to traversing the scene tree.
|
||||
b. `find_nodes_by_class(class_name="TransitionPiece")` — discover all transition pieces in current scene
|
||||
c. Match the exit node name from our path → get runtime position + polygon
|
||||
d. Compute click coordinate: centroid of the TransitionPiece's `polygon`, transformed to viewport coordinates
|
||||
e. `click(x, y)` — trigger the transition
|
||||
f. Wait for transition animation (2-3s via `wait` command or poll-loop)
|
||||
g. **Verify arrival**: `eval("return get_node('/root/Node2D').get_current_room_name()")` to confirm we've entered the expected room. Compare against the `to_room` from our BFS path. Returns empty string if no scene loaded.
|
||||
h. If verification fails, retry up to 2 times with adjusted coordinates
|
||||
h. Optionally take a screenshot via `screenshot()` for visual confirmation
|
||||
|
||||
7. **Complete**: Print summary of navigation path taken
|
||||
@@ -118,12 +119,24 @@ The skill guide documents:
|
||||
- **When to use**: Planning navigation between rooms, verifying room connectivity, debugging transitions
|
||||
- **Pre-requisites**: Godot game running with MCP server active on port 9090
|
||||
- **Quick start**: `python tools/kq4_room_navigator.py --from kq4_XXX --to kq4_YYY`
|
||||
- **Room verification helper** (`MainGame.get_current_room_name()`):
|
||||
|
||||
The root node (`/root/Node2D`, script: `MainGame.gd`) provides a convenience function for testing:
|
||||
|
||||
```gdscript
|
||||
# Via MCP eval — returns node name like "kq4_003_fountain_pool", or "" if no scene loaded
|
||||
return get_node("/root/Node2D").get_current_room_name()
|
||||
```
|
||||
|
||||
Use this after each transition click to verify you arrived at the expected room. Compare against the `to_room` field from your BFS path.
|
||||
|
||||
- **Manual MCP workflow** (for step-by-step agent control):
|
||||
- Start Godot: `godot --path .` or run exported binary
|
||||
- Check current room: `{"command": "eval", "params": {"code": "return get_node('/root/Node2D').get_current_room_name()"}}` → returns `"kq4_003_fountain_pool"` style string
|
||||
- Verify connectivity: `{"command": "get_scene_tree"}` returns the current scene tree
|
||||
- Discover exits in current room: `{"command": "find_nodes_by_class", "params": {"class_name": "TransitionPiece"}}`
|
||||
- Click a transition: compute centroid from polygon data, then `{"command": "click", "params": {"x": px, "y": py}}`
|
||||
- Wait and verify room change via `eval` or `screenshot`
|
||||
- Verify current room: `{"command": "eval", "params": {"code": "return get_node('/root/Node2D').get_current_room_name()"}}` (returns node name like `"kq4_010_forest_path"`). Alternatively use screenshot for visual confirmation.
|
||||
- **Coordinate computation math**: How to convert TransitionPiece polygon (local-space) to viewport click coordinates: `viewport_x = transition_node.position.x + polygon_centroid.x`, accounting for any node scale transforms
|
||||
- **Troubleshooting**: Common failures (server busy, node not found mid-transition, wrong room), escape hatches
|
||||
|
||||
@@ -134,6 +147,31 @@ The skill guide documents:
|
||||
```
|
||||
[1. build_room_graph.py] ────────┐
|
||||
├── [2. kq4_room_navigator.py] ─── [3. SKILL.md]
|
||||
|
||||
### Using MainGame.get_current_room_name() for Room Verification
|
||||
|
||||
The `MainGame.gd` script (attached to `/root/Node2D`) provides a convenience function:
|
||||
|
||||
```gdscript
|
||||
# Returns the node name of the current scene, e.g., "kq4_003_fountain_pool"
|
||||
func get_current_room_name() -> String:
|
||||
var scene = get_scene()
|
||||
if scene:
|
||||
return scene.name
|
||||
return ""
|
||||
```
|
||||
|
||||
**Via MCP eval for runtime verification**:
|
||||
```bash
|
||||
curl http://localhost:9090 -d '{"command": "eval", "params": {"code": "return get_node(\"/root/Node2D\").get_current_room_name()"}}'
|
||||
```
|
||||
|
||||
Returns the room node name string (e.g., `"kq4_003_fountain_pool"`), or empty string if no scene is loaded. This is more reliable than traversing the scene tree manually since it uses the same `$SceneViewport/background` reference that MainGame's own logic uses.
|
||||
|
||||
**When to use**:
|
||||
- After clicking a transition, call to confirm arrival at expected room in `to_room`
|
||||
- Before navigation starts, verify you're actually in the intended `from_room`
|
||||
- Compare against BFS path nodes during automated step-by-step execution
|
||||
```
|
||||
|
||||
Tasks run sequentially. Task 3 documents the completed system.
|
||||
|
||||
Reference in New Issue
Block a user