fix: exercise routed input and resolve E binding

This commit is contained in:
goose
2026-10-02 16:51:05 -04:00
parent 7f35300b77
commit 314d186bc9
8 changed files with 64 additions and 10 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ Godot 4.2+ is required (verified with Godot 4.5). GUT **9.5.0** is vendored and
"${GODOT_BIN:-$(command -v godot4 || command -v godot)}" --path .
```
Use WASD / arrow keys (and QZC diagonals). The HUD help band uses the French labels `Déplacer : ZQSD / Flèches` and `Interagir : Espace ou E`; both **Space** and **E** are bound to `interact`. All inputs pass through `ActionRouter`: movement and interaction are implemented, while the registered future commands emit a journaled `action_unavailable` event rather than being ignored. The rebindable command vocabulary and defaults are: **.** wait, **F** attack, **R** ranged, **X** cast, **T** talk, **H** rest, **I** inventory, **P** character, **J** quests, **U** audience, **Y** recap, **M** map, and **O** options. `Game.submit_test_action(Vector2i)` and `Game.submit_test_interact()` are deterministic public E2E seams and follow the same action router as keyboard input. Interacting with an adjacent closed door opens it into floor space, logs the action, refreshes FOV, and gives living enemies exactly one normal response. A closed chest is likewise non-walkable; interacting with it replaces it with floor, logs `chest_opened` as `You open the chest.`, refreshes FOV, and gives at most one normal enemy response. It deliberately grants no loot or inventory item. Interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. Interacting while standing on stairs logs `stairs_used`, sets the demonstration exit state, and gives living enemies exactly one normal response.
Use WASD / arrow keys (and QZC diagonals); **keypad 9** moves north-east. The HUD help band explicitly shows `Déplacer : ZQSD / Flèches (nord-est : pavé num. 9)` and `Interagir : Espace ou E`; both **Space** and **E** are bound only to `interact`. All inputs pass through `ActionRouter`: movement and interaction are implemented, while the registered future commands emit a journaled `action_unavailable` event rather than being ignored. The rebindable command vocabulary and defaults are: **.** wait, **F** attack, **R** ranged, **X** cast, **T** talk, **H** rest, **I** inventory, **P** character, **J** quests, **U** audience, **Y** recap, **M** map, and **O** options. `Game.submit_test_action(Vector2i)` and `Game.submit_test_interact()` are deterministic public E2E seams and follow the same action router as keyboard input. Interacting with an adjacent closed door opens it into floor space, logs the action, refreshes FOV, and gives living enemies exactly one normal response. A closed chest is likewise non-walkable; interacting with it replaces it with floor, logs `chest_opened` as `You open the chest.`, refreshes FOV, and gives at most one normal enemy response. It deliberately grants no loot or inventory item. Interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. Interacting while standing on stairs logs `stairs_used`, sets the demonstration exit state, and gives living enemies exactly one normal response.
## Display, grid, and camera
+30
View File
@@ -26,3 +26,33 @@ SCRIPT ERROR: Parse Error: Cannot find member REFERENCE_VIEWPORT in base Game
```
The runner exited with status `1`.
## A5 RED evidence reconstruction — input pipeline and E/north-east conflict
The A5 action-router baseline (`7f35300`) had two test-quality defects: its E2E tests invoked `Game._unhandled_input()` directly rather than exercising Godot's input dispatcher, and the physical **E** binding was assigned to both `interact` and `move_northeast`. The latter made the router's action selection depend on catalog ordering, not on an unambiguous input map.
Before applying the correction, the following minimal contract was run in a detached worktree at `7f35300`. `addons/` was copied into that temporary historical worktree because it is supplied in this checkout but ignored by Git; `godot --headless --path . --import` was run first so GUT class names were registered.
```gdscript
extends GutTest
func test_e_is_reserved_for_interaction_not_northeast_movement() -> void:
var e_key := InputEventKey.new()
e_key.keycode = KEY_E
e_key.physical_keycode = KEY_E
e_key.pressed = true
assert_true(InputMap.action_has_event(&"interact", e_key))
assert_false(InputMap.action_has_event(&"move_northeast", e_key))
```
Command:
```text
/snap/bin/godot4 --headless --path . -s res://addons/gut/gut_cmdln.gd \
-gdir=res://tests/tdd_red -gexit
```
It returned status **1**, with `0/1 passed`, `Failing Tests 1`, and `Asserts 1/2`; the second assertion (line 10) failed because `move_northeast` contained `KEY_E` on the baseline. This is the explicit RED proof for the conflict.
GREEN replaces that north-east binding with `KEY_KP_9`, retaining **E** exclusively for `interact`. `tests/unit/test_action_router.gd` permanently asserts the mutually exclusive E/keypad-9 bindings. The E2E regression test now sends press and release events with `Input.parse_input_event()` and awaits a process frame after each dispatch, thereby testing the real Godot input pipeline rather than calling the handler directly. The HUD and README name keypad 9 as the north-east control.
+1 -1
View File
@@ -30,7 +30,7 @@ move_south={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":83)
move_west={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":65),Object(InputEventKey,"physical_keycode":4194319)]}
move_east={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":68),Object(InputEventKey,"physical_keycode":4194321)]}
move_northwest={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":81)]}
move_northeast={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":69)]}
move_northeast={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":4194447)]}
move_southwest={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":90)]}
move_southeast={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":67)]}
wait={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":46)]}
+1 -1
View File
@@ -214,6 +214,6 @@ grow_horizontal = 2
grow_vertical = 0
theme_override_colors/font_color = Color(0.82, 0.9, 1, 1)
theme_override_font_sizes/font_size = 14
text = "Déplacer : ZQSD / Flèches • Interagir : Espace ou E"
text = "Déplacer : ZQSD / Flèches (nord-est : pavé num. 9) • Interagir : Espace ou E"
horizontal_alignment = 1
vertical_alignment = 1
+1
View File
@@ -18,6 +18,7 @@ func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() ->
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte")
assert_eq(prompt_label.text, "Espace — Ouvrir la porte")
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
assert_string_contains(help_label.text, "nord-est : pavé num. 9")
assert_string_contains(help_label.text, "Interagir : Espace ou E")
var interact_event := InputEventKey.new()
+13 -7
View File
@@ -8,22 +8,22 @@ func before_each() -> void:
add_child_autofree(game)
await get_tree().process_frame
func test_real_keyboard_input_routes_movement_and_interaction_through_action_router() -> void:
func test_input_pipeline_routes_e_interaction_and_movement_through_action_router() -> void:
var state := game.get_game_state()
var start_cell := state.player.cell
game._unhandled_input(_key_event(KEY_SPACE))
await _dispatch_key(KEY_E)
assert_eq(state.map.get_cell(Vector2i(4, 11)), GridMapState.CellKind.FLOOR)
assert_eq(game.get_run_state().recent_events(2)[0].kind, &"door_opened")
game._unhandled_input(_key_event(KEY_DOWN))
await _dispatch_key(KEY_DOWN)
assert_eq(state.player.cell, start_cell + Vector2i.DOWN)
assert_eq(game.get_run_state().recent_events(2)[0].kind, &"moved")
func test_real_future_command_input_records_unavailable_event_in_the_journal_and_hud() -> void:
func test_input_pipeline_routes_unavailable_input_to_the_journal_and_hud() -> void:
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
game._unhandled_input(_key_event(KEY_I))
await _dispatch_key(KEY_I)
var event := game.get_run_state().recent_events(1)[0]
assert_eq(event.kind, &"action_unavailable")
@@ -31,9 +31,15 @@ func test_real_future_command_input_records_unavailable_event_in_the_journal_and
assert_eq(event.turn, 1)
assert_string_contains(event_log.get_parsed_text(), "inventory")
func _key_event(keycode: Key) -> InputEventKey:
func _dispatch_key(keycode: Key) -> void:
Input.parse_input_event(_key_event(keycode, true))
await get_tree().process_frame
Input.parse_input_event(_key_event(keycode, false))
await get_tree().process_frame
func _key_event(keycode: Key, pressed: bool) -> InputEventKey:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
event.pressed = pressed
return event
+16
View File
@@ -11,6 +11,15 @@ func test_every_declared_input_action_is_registered_and_has_user_facing_help() -
assert_gt(InputMap.action_get_events(input_action).size(), 0, "Missing keyboard binding: %s" % input_action)
assert_ne(InputBindings.help_name_for(input_action), "", "Missing help name: %s" % input_action)
func test_interact_and_move_northeast_have_distinct_physical_bindings() -> void:
var interact_e := _key_event(KEY_E)
var northeast_keypad_9 := _key_event(KEY_KP_9)
assert_true(InputMap.action_has_event(&"interact", interact_e))
assert_true(InputMap.action_has_event(&"move_northeast", northeast_keypad_9))
assert_false(InputMap.action_has_event(&"move_northeast", interact_e))
assert_false(InputMap.action_has_event(&"interact", northeast_keypad_9))
func test_action_from_input_maps_the_complete_command_vocabulary() -> void:
var router := ActionRouter.new(null)
var expected := {
@@ -68,3 +77,10 @@ func _action_event(input_action: StringName) -> InputEventAction:
event.action = input_action
event.pressed = true
return event
func _key_event(keycode: Key) -> InputEventKey:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
return event
+1
View File
@@ -13,6 +13,7 @@ func test_help_band_displays_the_exact_control_labels() -> void:
assert_not_null(help_label)
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
assert_string_contains(help_label.text, "nord-est : pavé num. 9")
assert_string_contains(help_label.text, "Interagir : Espace ou E")
func test_hud_uses_viewport_anchored_panels_with_distinct_stats_and_log_zones() -> void: