From 7f35300b773d25bcadd1b5b1697ca192baf8223e Mon Sep 17 00:00:00 2001 From: goose Date: Fri, 2 Oct 2026 16:29:14 -0400 Subject: [PATCH 1/3] feat: add unified player action router --- README.md | 2 +- project.godot | 13 ++++ scripts/game/action_router.gd | 24 ++++++ scripts/game/action_router.gd.uid | 1 + scripts/game/game.gd | 61 ++++++++++----- scripts/game/input_bindings.gd | 77 +++++++++++++++++++ scripts/game/input_bindings.gd.uid | 1 + tests/e2e/test_input_action_router_e2e.gd | 39 ++++++++++ tests/e2e/test_input_action_router_e2e.gd.uid | 1 + tests/unit/test_action_router.gd | 70 +++++++++++++++++ tests/unit/test_action_router.gd.uid | 1 + 11 files changed, 269 insertions(+), 21 deletions(-) create mode 100644 scripts/game/action_router.gd create mode 100644 scripts/game/action_router.gd.uid create mode 100644 scripts/game/input_bindings.gd create mode 100644 scripts/game/input_bindings.gd.uid create mode 100644 tests/e2e/test_input_action_router_e2e.gd create mode 100644 tests/e2e/test_input_action_router_e2e.gd.uid create mode 100644 tests/unit/test_action_router.gd create mode 100644 tests/unit/test_action_router.gd.uid diff --git a/README.md b/README.md index 1326cd0..62c240d 100644 --- a/README.md +++ b/README.md @@ -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`. `Game.submit_test_action(Vector2i)` and `Game.submit_test_interact()` are deterministic public E2E seams and follow the same processors 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). 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. ## Display, grid, and camera diff --git a/project.godot b/project.godot index d5fac00..7e8b42b 100644 --- a/project.godot +++ b/project.godot @@ -33,3 +33,16 @@ move_northwest={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode" move_northeast={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":69)]} 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)]} +attack={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":70)]} +ranged={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":82)]} +cast={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":88)]} +talk={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":84)]} +rest={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":72)]} +inventory={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":73)]} +character={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":80)]} +quest={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":74)]} +audience={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":85)]} +recap={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":89)]} +map={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":77)]} +options={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":79)]} diff --git a/scripts/game/action_router.gd b/scripts/game/action_router.gd new file mode 100644 index 0000000..3b9114a --- /dev/null +++ b/scripts/game/action_router.gd @@ -0,0 +1,24 @@ +class_name ActionRouter +extends RefCounted + +const InputBindingsType = preload("res://scripts/game/input_bindings.gd") +const PlayerActionType = preload("res://scripts/domain/run/player_action.gd") + +var _game: Game + +func _init(game: Game) -> void: + _game = game + +func action_from_input(event: InputEvent) -> PlayerAction: + for input_action in InputBindingsType.input_actions(): + if event.is_action_pressed(input_action): + return PlayerActionType.new( + InputBindingsType.player_action_for(input_action), + InputBindingsType.direction_for(input_action) + ) + return null + +func submit(action: PlayerAction) -> Array[GameEvent]: + if _game == null: + return [] + return _game.submit_player_action(action) diff --git a/scripts/game/action_router.gd.uid b/scripts/game/action_router.gd.uid new file mode 100644 index 0000000..c8d49dd --- /dev/null +++ b/scripts/game/action_router.gd.uid @@ -0,0 +1 @@ +uid://ce4dlu81er111 diff --git a/scripts/game/game.gd b/scripts/game/game.gd index 8090e36..ca71fff 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -8,6 +8,8 @@ const ActorStateType = preload("res://scripts/domain/actor_state.gd") const GameStateType = preload("res://scripts/domain/game_state.gd") const RunStateType = preload("res://scripts/domain/run/run_state.gd") const GameEventType = preload("res://scripts/domain/run/game_event.gd") +const PlayerActionType = preload("res://scripts/domain/run/player_action.gd") +const ActionRouterType = preload("res://scripts/game/action_router.gd") const ActorViewType = preload("res://scripts/presentation/actor_view.gd") @onready var event_presenter: EventPresenter = $EventPresenter @onready var map_renderer: MapRenderer = $World/MapRenderer @@ -20,10 +22,12 @@ var game_state: GameState var run_state: RunState var enemy_views: Dictionary[StringName, ActorView] = {} var last_turn_results: Array[TurnResult] = [] +var action_router: ActionRouter func _ready() -> void: game_state = _create_initial_state() run_state = RunStateType.new("demo-run") + action_router = ActionRouterType.new(self) event_presenter.set_actor_lookup(_get_actor_view) event_presenter.event_presented.connect(_on_event_presented) map_renderer.set_map(game_state.map) @@ -66,30 +70,47 @@ func _prepare_exit_capture_state() -> void: _sync_camera_to_player() func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"interact"): - last_turn_results = submit_test_interact() - elif event.is_action_pressed(&"move_north"): - last_turn_results = _process_action(Vector2i.UP) - elif event.is_action_pressed(&"move_south"): - last_turn_results = _process_action(Vector2i.DOWN) - elif event.is_action_pressed(&"move_west"): - last_turn_results = _process_action(Vector2i.LEFT) - elif event.is_action_pressed(&"move_east"): - last_turn_results = _process_action(Vector2i.RIGHT) - elif event.is_action_pressed(&"move_northwest"): - last_turn_results = _process_action(Vector2i(-1, -1)) - elif event.is_action_pressed(&"move_northeast"): - last_turn_results = _process_action(Vector2i(1, -1)) - elif event.is_action_pressed(&"move_southwest"): - last_turn_results = _process_action(Vector2i(-1, 1)) - elif event.is_action_pressed(&"move_southeast"): - last_turn_results = _process_action(Vector2i(1, 1)) + var action := action_router.action_from_input(event) + if action != null: + action_router.submit(action) func submit_test_action(direction: Vector2i) -> Array[TurnResult]: - return _process_action(direction) + action_router.submit(PlayerActionType.new(&"move", direction)) + return last_turn_results func submit_test_interact() -> Array[TurnResult]: - return _process_interact() + action_router.submit(PlayerActionType.new(&"interact")) + return last_turn_results + +func submit_player_action(action: PlayerAction) -> Array[GameEvent]: + match action.kind: + &"move": + last_turn_results = _process_action(action.direction) + return run_state.recent_events(last_turn_results.size()) + &"interact": + last_turn_results = _process_interact() + return run_state.recent_events(last_turn_results.size()) + _: + last_turn_results = [] + return _record_unavailable_action(action) + +func _record_unavailable_action(action: PlayerAction) -> Array[GameEvent]: + var event := GameEventType.new( + run_state.next_turn(), + run_state.current_floor, + &"action_unavailable", + {"action": action.kind}, + "Action unavailable: %s." % action.kind, + &"player", + &"", + game_state.player.cell + ) + var events: Array[GameEvent] = [event] + run_state.append_events(events) + event_presenter.enqueue(events) + event_presenter.present_next() + hud.refresh(game_state, run_state.recent_events(run_state.log.size())) + return events func get_game_state() -> GameState: return game_state diff --git a/scripts/game/input_bindings.gd b/scripts/game/input_bindings.gd new file mode 100644 index 0000000..4910e80 --- /dev/null +++ b/scripts/game/input_bindings.gd @@ -0,0 +1,77 @@ +class_name InputBindings +extends RefCounted + +# The Input Map owns physical bindings; this catalog gives every rebindable action +# its stable identifier, player command and user-facing French help name. +const ACTIONS: Array[StringName] = [ + &"interact", + &"move_north", + &"move_south", + &"move_west", + &"move_east", + &"move_northwest", + &"move_northeast", + &"move_southwest", + &"move_southeast", + &"wait", + &"attack", + &"ranged", + &"cast", + &"talk", + &"rest", + &"inventory", + &"character", + &"quest", + &"audience", + &"recap", + &"map", + &"options", +] + +const HELP_NAMES := { + &"move_north": "Déplacer vers le nord", + &"move_south": "Déplacer vers le sud", + &"move_west": "Déplacer vers l’ouest", + &"move_east": "Déplacer vers l’est", + &"move_northwest": "Déplacer vers le nord-ouest", + &"move_northeast": "Déplacer vers le nord-est", + &"move_southwest": "Déplacer vers le sud-ouest", + &"move_southeast": "Déplacer vers le sud-est", + &"wait": "Attendre", + &"interact": "Interagir", + &"attack": "Attaquer", + &"ranged": "Attaque à distance", + &"cast": "Lancer un sort", + &"talk": "Parler", + &"rest": "Se reposer", + &"inventory": "Inventaire", + &"character": "Personnage", + &"quest": "Quêtes", + &"audience": "Audience", + &"recap": "Récapitulatif", + &"map": "Carte", + &"options": "Options", +} + +const MOVE_DIRECTIONS := { + &"move_north": Vector2i.UP, + &"move_south": Vector2i.DOWN, + &"move_west": Vector2i.LEFT, + &"move_east": Vector2i.RIGHT, + &"move_northwest": Vector2i(-1, -1), + &"move_northeast": Vector2i(1, -1), + &"move_southwest": Vector2i(-1, 1), + &"move_southeast": Vector2i(1, 1), +} + +static func input_actions() -> Array[StringName]: + return ACTIONS.duplicate() + +static func help_name_for(input_action: StringName) -> String: + return HELP_NAMES.get(input_action, "") + +static func direction_for(input_action: StringName) -> Vector2i: + return MOVE_DIRECTIONS.get(input_action, Vector2i.ZERO) + +static func player_action_for(input_action: StringName) -> StringName: + return &"move" if MOVE_DIRECTIONS.has(input_action) else input_action diff --git a/scripts/game/input_bindings.gd.uid b/scripts/game/input_bindings.gd.uid new file mode 100644 index 0000000..c0d2539 --- /dev/null +++ b/scripts/game/input_bindings.gd.uid @@ -0,0 +1 @@ +uid://c7e22jfm2l137 diff --git a/tests/e2e/test_input_action_router_e2e.gd b/tests/e2e/test_input_action_router_e2e.gd new file mode 100644 index 0000000..4270bb8 --- /dev/null +++ b/tests/e2e/test_input_action_router_e2e.gd @@ -0,0 +1,39 @@ +extends GutTest + +const GameScene = preload("res://scenes/Game.tscn") +var game: Game + +func before_each() -> void: + game = GameScene.instantiate() + add_child_autofree(game) + await get_tree().process_frame + +func test_real_keyboard_input_routes_movement_and_interaction_through_action_router() -> void: + var state := game.get_game_state() + var start_cell := state.player.cell + + game._unhandled_input(_key_event(KEY_SPACE)) + 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)) + 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: + var event_log := game.get_node("HUD/EventLog") as RichTextLabel + + game._unhandled_input(_key_event(KEY_I)) + + var event := game.get_run_state().recent_events(1)[0] + assert_eq(event.kind, &"action_unavailable") + assert_eq(event.payload, {"action": &"inventory"}) + assert_eq(event.turn, 1) + assert_string_contains(event_log.get_parsed_text(), "inventory") + +func _key_event(keycode: Key) -> InputEventKey: + var event := InputEventKey.new() + event.keycode = keycode + event.physical_keycode = keycode + event.pressed = true + return event diff --git a/tests/e2e/test_input_action_router_e2e.gd.uid b/tests/e2e/test_input_action_router_e2e.gd.uid new file mode 100644 index 0000000..b21ed34 --- /dev/null +++ b/tests/e2e/test_input_action_router_e2e.gd.uid @@ -0,0 +1 @@ +uid://ky15sj26s431 diff --git a/tests/unit/test_action_router.gd b/tests/unit/test_action_router.gd new file mode 100644 index 0000000..dd114b4 --- /dev/null +++ b/tests/unit/test_action_router.gd @@ -0,0 +1,70 @@ +extends GutTest + +const ActionRouter = preload("res://scripts/game/action_router.gd") +const InputBindings = preload("res://scripts/game/input_bindings.gd") +const PlayerAction = preload("res://scripts/domain/run/player_action.gd") +const GameScene = preload("res://scenes/Game.tscn") + +func test_every_declared_input_action_is_registered_and_has_user_facing_help() -> void: + for input_action in InputBindings.input_actions(): + assert_true(InputMap.has_action(input_action), "Missing Input Map action: %s" % input_action) + 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_action_from_input_maps_the_complete_command_vocabulary() -> void: + var router := ActionRouter.new(null) + var expected := { + &"move_north": [&"move", Vector2i.UP], + &"move_south": [&"move", Vector2i.DOWN], + &"move_west": [&"move", Vector2i.LEFT], + &"move_east": [&"move", Vector2i.RIGHT], + &"move_northwest": [&"move", Vector2i(-1, -1)], + &"move_northeast": [&"move", Vector2i(1, -1)], + &"move_southwest": [&"move", Vector2i(-1, 1)], + &"move_southeast": [&"move", Vector2i(1, 1)], + &"wait": [&"wait", Vector2i.ZERO], + &"interact": [&"interact", Vector2i.ZERO], + &"attack": [&"attack", Vector2i.ZERO], + &"ranged": [&"ranged", Vector2i.ZERO], + &"cast": [&"cast", Vector2i.ZERO], + &"talk": [&"talk", Vector2i.ZERO], + &"rest": [&"rest", Vector2i.ZERO], + &"inventory": [&"inventory", Vector2i.ZERO], + &"character": [&"character", Vector2i.ZERO], + &"quest": [&"quest", Vector2i.ZERO], + &"audience": [&"audience", Vector2i.ZERO], + &"recap": [&"recap", Vector2i.ZERO], + &"map": [&"map", Vector2i.ZERO], + &"options": [&"options", Vector2i.ZERO], + } + + for input_action in expected: + var action: PlayerAction = router.action_from_input(_action_event(input_action)) + assert_not_null(action, "No player action for %s" % input_action) + assert_eq(action.kind, expected[input_action][0], "Incorrect kind for %s" % input_action) + assert_eq(action.direction, expected[input_action][1], "Incorrect direction for %s" % input_action) + +func test_unmapped_input_returns_no_player_action() -> void: + var router := ActionRouter.new(null) + assert_null(router.action_from_input(_action_event(&"not_a_game_action"))) + +func test_submit_unimplemented_action_records_action_unavailable_event() -> void: + var game := GameScene.instantiate() as Game + add_child_autofree(game) + await get_tree().process_frame + var router := ActionRouter.new(game) + + var events: Array[GameEvent] = router.submit(PlayerAction.new(&"inventory")) + + assert_eq(events.size(), 1) + assert_eq(events[0].kind, &"action_unavailable") + assert_eq(events[0].payload, {"action": &"inventory"}) + assert_eq(events[0].turn, 1) + assert_eq(game.get_run_state().recent_events(1)[0], events[0]) + assert_eq(game.get_game_state().player.cell, Vector2i(4, 12)) + +func _action_event(input_action: StringName) -> InputEventAction: + var event := InputEventAction.new() + event.action = input_action + event.pressed = true + return event diff --git a/tests/unit/test_action_router.gd.uid b/tests/unit/test_action_router.gd.uid new file mode 100644 index 0000000..400dc78 --- /dev/null +++ b/tests/unit/test_action_router.gd.uid @@ -0,0 +1 @@ +uid://w66kxy6qx633 From 314d186bc9ca38e9ab066484a5c4e88548f59643 Mon Sep 17 00:00:00 2001 From: goose Date: Fri, 2 Oct 2026 16:51:05 -0400 Subject: [PATCH 2/3] fix: exercise routed input and resolve E binding --- README.md | 2 +- S4_ROUND_2_REPORT.md | 30 +++++++++++++++++++++++ project.godot | 2 +- scenes/Game.tscn | 2 +- tests/e2e/test_hud_prompts_e2e.gd | 1 + tests/e2e/test_input_action_router_e2e.gd | 20 +++++++++------ tests/unit/test_action_router.gd | 16 ++++++++++++ tests/unit/test_hud_layout.gd | 1 + 8 files changed, 64 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 62c240d..85af66a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/S4_ROUND_2_REPORT.md b/S4_ROUND_2_REPORT.md index 45da073..eff6dd2 100644 --- a/S4_ROUND_2_REPORT.md +++ b/S4_ROUND_2_REPORT.md @@ -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. diff --git a/project.godot b/project.godot index 7e8b42b..a4b7563 100644 --- a/project.godot +++ b/project.godot @@ -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)]} diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 3a8e6fd..8e72e75 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -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 diff --git a/tests/e2e/test_hud_prompts_e2e.gd b/tests/e2e/test_hud_prompts_e2e.gd index c9e0669..9f5b8cb 100644 --- a/tests/e2e/test_hud_prompts_e2e.gd +++ b/tests/e2e/test_hud_prompts_e2e.gd @@ -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() diff --git a/tests/e2e/test_input_action_router_e2e.gd b/tests/e2e/test_input_action_router_e2e.gd index 4270bb8..56fef65 100644 --- a/tests/e2e/test_input_action_router_e2e.gd +++ b/tests/e2e/test_input_action_router_e2e.gd @@ -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 diff --git a/tests/unit/test_action_router.gd b/tests/unit/test_action_router.gd index dd114b4..6a97fad 100644 --- a/tests/unit/test_action_router.gd +++ b/tests/unit/test_action_router.gd @@ -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 diff --git a/tests/unit/test_hud_layout.gd b/tests/unit/test_hud_layout.gd index 2bff9d8..9f8ae21 100644 --- a/tests/unit/test_hud_layout.gd +++ b/tests/unit/test_hud_layout.gd @@ -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: From be439c1475fce895c800f8e44616b1e0b3ab6e58 Mon Sep 17 00:00:00 2001 From: goose Date: Fri, 2 Oct 2026 17:20:31 -0400 Subject: [PATCH 3/3] docs: remove A5 evidence from S4 report --- S4_ROUND_2_REPORT.md | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/S4_ROUND_2_REPORT.md b/S4_ROUND_2_REPORT.md index eff6dd2..45da073 100644 --- a/S4_ROUND_2_REPORT.md +++ b/S4_ROUND_2_REPORT.md @@ -26,33 +26,3 @@ 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.