From b469c6decb98a4aef34272ebd9deab696a9bdfe4 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 15:53:07 -0400 Subject: [PATCH 1/2] feat: implement door interaction --- README.md | 4 +- scripts/domain/game_state.gd | 7 +++ scripts/domain/interaction_resolver.gd | 42 +++++++++++++++ scripts/domain/turn_resolver.gd | 6 +-- scripts/game/game.gd | 19 +++++-- scripts/run-visual-check.sh | 2 +- task-1-report.md | 51 ++++++++++++++++++ tests/e2e/test_door_interaction_e2e.gd | 50 +++++++++++++++++ tests/e2e/test_hud_prompts_e2e.gd | 7 +-- tests/unit/test_door_interaction.gd | 75 ++++++++++++++++++++++++++ 10 files changed, 249 insertions(+), 14 deletions(-) create mode 100644 scripts/domain/interaction_resolver.gd create mode 100644 task-1-report.md create mode 100644 tests/e2e/test_door_interaction_e2e.gd create mode 100644 tests/unit/test_door_interaction.gd diff --git a/README.md b/README.md index 8dcda06..535d660 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)` is the deterministic public E2E seam and follows the same action processor as keyboard input. +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; interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. ## Display, grid, and camera @@ -60,7 +60,7 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/run-visual-check.sh GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh ``` -`run-visual-check.sh` runs the actual project with `--capture`, waits for it to render, logs output to `artifacts/visual-check.log`, and requires the project-owned capture at `artifacts/visual-check.png` to be a valid **1280×720** PNG. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture. +`run-visual-check.sh` runs the actual project with `--capture-door`, opens the initial closed door before rendering, logs output to `artifacts/visual-check.log`, and requires the project-owned capture at `artifacts/visual-check.png` to be a valid **1280×720** PNG. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture. For a direct headless startup check: diff --git a/scripts/domain/game_state.gd b/scripts/domain/game_state.gd index 24d2474..f262863 100644 --- a/scripts/domain/game_state.gd +++ b/scripts/domain/game_state.gd @@ -2,6 +2,7 @@ class_name GameState extends RefCounted const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd") +const InteractionResolverType = preload("res://scripts/domain/interaction_resolver.gd") var player: ActorState var enemies: Dictionary[StringName, ActorState] @@ -31,6 +32,12 @@ func try_player_action(direction: Vector2i) -> Array[TurnResult]: update_exploration() return results +func try_interact() -> Array[TurnResult]: + var results := InteractionResolverType.resolve(self) + if results[0].kind != &"nothing_to_interact": + update_exploration() + return results + func compute_visible_cells(game_map: GridMapState, origin: Vector2i, radius: int) -> Dictionary[Vector2i, bool]: var visible: Dictionary[Vector2i, bool] = {} for y in range(origin.y - radius, origin.y + radius + 1): diff --git a/scripts/domain/interaction_resolver.gd b/scripts/domain/interaction_resolver.gd new file mode 100644 index 0000000..a09bb5e --- /dev/null +++ b/scripts/domain/interaction_resolver.gd @@ -0,0 +1,42 @@ +class_name InteractionResolver +extends RefCounted + +const TurnResolverType = preload("res://scripts/domain/turn_resolver.gd") +const TurnResultType = preload("res://scripts/domain/turn_result.gd") + +const TARGET_OFFSETS: Array[Vector2i] = [ + Vector2i.ZERO, + Vector2i.UP, + Vector2i.RIGHT, + Vector2i.DOWN, + Vector2i.LEFT, + Vector2i(1, -1), + Vector2i(1, 1), + Vector2i(-1, 1), + Vector2i(-1, -1), +] + +static func resolve(state: GameState) -> Array[TurnResult]: + var results: Array[TurnResult] = [] + if state.map.get_cell(state.player.cell) == GridMapState.CellKind.STAIRS: + state.exit_reached = true + results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, "You descend the stairs.")) + TurnResolverType.append_enemy_response(state, results) + return results + + var door_cell := _find_closed_door(state) + if door_cell.x >= 0: + state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR) + results.append(TurnResultType.new(state.player.id, &"door_opened", state.player.cell, door_cell, &"", 0, "You open the door.")) + TurnResolverType.append_enemy_response(state, results) + return results + + results.append(TurnResultType.new(state.player.id, &"nothing_to_interact", state.player.cell, state.player.cell, &"", 0, "Nothing to interact with.")) + return results + +static func _find_closed_door(state: GameState) -> Vector2i: + for offset in TARGET_OFFSETS: + var cell := state.player.cell + offset + if state.map.get_cell(cell) == GridMapState.CellKind.CLOSED_DOOR: + return cell + return Vector2i(-1, -1) diff --git a/scripts/domain/turn_resolver.gd b/scripts/domain/turn_resolver.gd index 1abc52a..3d71ba1 100644 --- a/scripts/domain/turn_resolver.gd +++ b/scripts/domain/turn_resolver.gd @@ -17,7 +17,7 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra state.enemies.erase(enemy.id) results.append(TurnResultType.new(enemy.id, &"enemy_defeated", enemy.cell, enemy.cell, player.id, 0, "The goblin is defeated.")) else: - _append_enemy_response(state, results) + append_enemy_response(state, results) return results if not state.map.is_walkable(destination): results.append(TurnResultType.new(player.id, &"blocked", player.cell, destination, &"", 0, "Your way is blocked.")) @@ -25,7 +25,7 @@ static func resolve_player_action(state: GameState, direction: Vector2i) -> Arra var from: Vector2i = player.cell player.cell = destination results.append(TurnResultType.new(player.id, &"moved", from, destination, &"", 0, "You move to (%d, %d)." % [destination.x, destination.y])) - _append_enemy_response(state, results) + append_enemy_response(state, results) return results static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState: @@ -34,7 +34,7 @@ static func _enemy_at(state: GameState, cell: Vector2i) -> ActorState: return enemy return null -static func _append_enemy_response(state: GameState, results: Array[TurnResult]) -> void: +static func append_enemy_response(state: GameState, results: Array[TurnResult]) -> void: for enemy: ActorState in state.enemies.values(): var delta: Vector2i = state.player.cell - enemy.cell if abs(delta.x) + abs(delta.y) == 1: diff --git a/scripts/game/game.gd b/scripts/game/game.gd index 45163d3..c7455ba 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -25,7 +25,10 @@ func _ready() -> void: _sync_enemy_views() hud.refresh(game_state) audio_library.set_ambience_context("exploration") - if "--capture" in OS.get_cmdline_user_args(): + var user_args := OS.get_cmdline_user_args() + if "--capture-door" in user_args: + submit_test_interact() + if "--capture" in user_args or "--capture-door" in user_args: _capture_visual_check() func _capture_visual_check() -> void: @@ -62,7 +65,7 @@ func submit_test_action(direction: Vector2i) -> Array[TurnResult]: return _process_action(direction) func submit_test_interact() -> Array[TurnResult]: - return _refresh_hud_for_context() + return _process_interact() func get_game_state() -> GameState: return game_state @@ -74,9 +77,15 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2: return enemy_views[actor_id].get_cell_rect() return Rect2() -func _refresh_hud_for_context() -> Array[TurnResult]: - hud.refresh(game_state) - return [] +func _process_interact() -> Array[TurnResult]: + var results := game_state.try_interact() + _sync_map_renderer_visibility() + player_view.refresh() + _sync_enemy_views() + _show_damage_feedback(results) + _dispatch_audio(results) + hud.refresh(game_state, results) + return results func _process_action(direction: Vector2i) -> Array[TurnResult]: var results := game_state.try_player_action(direction) diff --git a/scripts/run-visual-check.sh b/scripts/run-visual-check.sh index 36e3f35..1776d4c 100755 --- a/scripts/run-visual-check.sh +++ b/scripts/run-visual-check.sh @@ -28,7 +28,7 @@ if [[ -z "${DISPLAY:-}" ]]; then fi set +e -timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture >"$log_path" 2>&1 +timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture-door >"$log_path" 2>&1 status=$? set -e if (( status != 0 )); then diff --git a/task-1-report.md b/task-1-report.md new file mode 100644 index 0000000..8a9a543 --- /dev/null +++ b/task-1-report.md @@ -0,0 +1,51 @@ +# S5.3 — Task 1: Door interaction report + +**Worktree:** `/home/hectelyon/Documents/Projects/ProjetsPersos/DungeonCrawlerWorld/.worktrees/s5-3` + +**Branch:** `slice/s5-3-door-interaction` +**Date:** 2026-10-01 + +## Delivered + +- Added the dedicated domain `InteractionResolver` and public `GameState.try_interact()`. +- The resolver uses the frozen target order: player cell, N, E, S, W, NE, SE, SW, NW. +- A closed door becomes `FLOOR`, produces `door_opened`, and triggers the existing enemy-response mechanism exactly once. +- Stairs under the player produce `stairs_used` and set `exit_reached`. +- No target produces exactly `nothing_to_interact`, with no player/enemy state change and no enemy turn. +- Valid interaction refreshes FOV/exploration. Presentation refreshes map visibility, actor views, HUD prompt, and event log through the shared `Game` path. +- `submit_test_interact()` and configured `InputEvent` interaction both converge through `_process_interact()` into `GameState.try_interact()`. +- Extended the project-owned visual check to capture the real application after opening its initial door (`--capture-door`). +- Updated README interaction and capture documentation. + +## TDD evidence + +1. Added door unit/E2E specifications before domain implementation. +2. **Red:** `./scripts/test-unit.sh` failed as intended because `GameState.try_interact` did not exist (4 new tests failed with `Nonexistent function 'try_interact'`). +3. **Green:** implemented the resolver and shared game path; all unit and E2E checks passed. + +## Automated verification + +Executed from this worktree using Godot 4.5 and GUT 9.5: + +| Command | Result | +|---|---| +| `./scripts/test-unit.sh` | PASS — 25 tests, 108 assertions | +| `./scripts/test-e2e.sh` | PASS — 9 tests, 105 assertions | +| `env -u DISPLAY ./scripts/run-visual-check.sh` | PASS — actual app launched through Xvfb; `artifacts/visual-check.png` is 1280×720 | +| `./scripts/verify.sh` | PASS — unit, E2E, visual checks | +| `git diff --check` | PASS | + +The new real-scene E2E test verifies configured Space and E events, the `submit_test_interact()` seam, door opening, confirmation log/prompt refresh, and walking through the former door cell. Unit tests verify order, no-op behavior, FOV recalculation, one enemy response, and stairs precedence. + +## Visual proof + +- Capture: `artifacts/visual-check.png` (ignored/generated artifact) +- Log: `artifacts/visual-check.log` (ignored/generated artifact) +- Run used Xvfb because `DISPLAY` was explicitly unset. +- Capture was inspected and shows the initial north door rendered as floor, the prompt cleared, and the event log containing `You open the door.` + +## Scope and repository hygiene + +- Changes are confined to this worktree and task scope. +- No push or PR was created. +- Generated capture files remain ignored and are not part of the commit. diff --git a/tests/e2e/test_door_interaction_e2e.gd b/tests/e2e/test_door_interaction_e2e.gd new file mode 100644 index 0000000..f9d1786 --- /dev/null +++ b/tests/e2e/test_door_interaction_e2e.gd @@ -0,0 +1,50 @@ +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_input_map_binds_space_and_e_to_interact() -> void: + assert_true(InputMap.action_has_event(&"interact", _key_event(KEY_SPACE))) + assert_true(InputMap.action_has_event(&"interact", _key_event(KEY_E))) + +func test_real_game_keyboard_space_and_test_seam_open_door_then_allow_walking_through_it() -> void: + var state := game.get_game_state() + var hud := game.get_node("HUD") as GameHud + var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label + var event_log := game.get_node("HUD/EventLog") as RichTextLabel + var door_cell := Vector2i(2, 1) + game._unhandled_input(_key_event(KEY_SPACE)) + + assert_eq(state.map.get_cell(door_cell), GridMapState.CellKind.FLOOR) + assert_eq(hud.get_context_prompt(), "") + assert_eq(prompt_label.text, "") + assert_string_contains(event_log.get_parsed_text(), "You open the door.") + + var move_results := game.submit_test_action(Vector2i.UP) + assert_eq(move_results[0].kind, &"moved") + assert_eq(state.player.cell, door_cell) + + var submitted_game := GameScene.instantiate() as Game + add_child_autofree(submitted_game) + await get_tree().process_frame + var submitted_results: Array[TurnResult] = submitted_game.submit_test_interact() + assert_eq(submitted_results[0].kind, &"door_opened") + assert_eq(submitted_game.get_game_state().map.get_cell(door_cell), GridMapState.CellKind.FLOOR) + + var e_game := GameScene.instantiate() as Game + add_child_autofree(e_game) + await get_tree().process_frame + e_game._unhandled_input(_key_event(KEY_E)) + assert_eq(e_game.get_game_state().map.get_cell(door_cell), GridMapState.CellKind.FLOOR) + +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_hud_prompts_e2e.gd b/tests/e2e/test_hud_prompts_e2e.gd index 9dcc5ad..61050be 100644 --- a/tests/e2e/test_hud_prompts_e2e.gd +++ b/tests/e2e/test_hud_prompts_e2e.gd @@ -29,9 +29,10 @@ func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() -> state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR) state.player.cell = Vector2i(9, 7) - game.submit_test_interact() - assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier") - assert_eq(prompt_label.text, "Espace — Descendre l’escalier") + var interact_results: Array[TurnResult] = game.submit_test_interact() + assert_eq(interact_results[0].kind, &"stairs_used") + assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible") + assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible") var results := game.submit_test_action(Vector2i.LEFT) assert_eq(results[0].kind, &"moved") diff --git a/tests/unit/test_door_interaction.gd b/tests/unit/test_door_interaction.gd new file mode 100644 index 0000000..c97dcf3 --- /dev/null +++ b/tests/unit/test_door_interaction.gd @@ -0,0 +1,75 @@ +extends GutTest + +const GridMapState = preload("res://scripts/domain/grid_map_state.gd") +const ActorState = preload("res://scripts/domain/actor_state.gd") +const GameState = preload("res://scripts/domain/game_state.gd") + +func make_state() -> GameState: + var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR) + var player := ActorState.new(&"player", Vector2i(3, 3), 12, 3) + var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2) + return GameState.new(map, player, {&"goblin": goblin}) + +func test_try_interact_opens_the_first_closed_door_in_contract_neighbour_order() -> void: + var state := make_state() + var north := state.player.cell + Vector2i.UP + var east := state.player.cell + Vector2i.RIGHT + state.map.set_cell(north, GridMapState.CellKind.CLOSED_DOOR) + state.map.set_cell(east, GridMapState.CellKind.CLOSED_DOOR) + + var results: Array[TurnResult] = state.try_interact() + + assert_eq(results.size(), 2) + assert_eq(results[0].kind, &"door_opened") + assert_eq(results[0].from_cell, state.player.cell) + assert_eq(results[0].to_cell, north) + assert_eq(state.map.get_cell(north), GridMapState.CellKind.FLOOR) + assert_eq(state.map.get_cell(east), GridMapState.CellKind.CLOSED_DOOR) + assert_eq(state.player.cell, Vector2i(3, 3)) + +func test_try_interact_without_a_target_only_reports_nothing_and_does_not_take_a_turn() -> void: + var state := make_state() + state.enemies[&"goblin"].cell = Vector2i(4, 3) + var player_cell := state.player.cell + var player_hp := state.player.hit_points + var enemy_cell := state.enemies[&"goblin"].cell + + var results: Array[TurnResult] = state.try_interact() + + assert_eq(results.size(), 1) + assert_eq(results[0].kind, &"nothing_to_interact") + assert_eq(state.player.cell, player_cell) + assert_eq(state.player.hit_points, player_hp) + assert_eq(state.enemies[&"goblin"].cell, enemy_cell) + +func test_opening_a_door_recalculates_fov_and_triggers_exactly_one_enemy_response() -> void: + var map := GridMapState.new(Vector2i(7, 5), GridMapState.CellKind.FLOOR) + var door := Vector2i(2, 2) + var revealed_cell := Vector2i(3, 2) + map.set_cell(door, GridMapState.CellKind.CLOSED_DOOR) + var player := ActorState.new(&"player", Vector2i(1, 2), 12, 3) + var goblin := ActorState.new(&"goblin", Vector2i(5, 2), 6, 2) + var state := GameState.new(map, player, {&"goblin": goblin}) + assert_false(state.visible_cells.has(revealed_cell)) + + var results: Array[TurnResult] = state.try_interact() + var enemy_result_count := 0 + for result in results: + if String(result.kind).begins_with("enemy_"): + enemy_result_count += 1 + + assert_eq(results[0].kind, &"door_opened") + assert_eq(state.map.get_cell(door), GridMapState.CellKind.FLOOR) + assert_true(state.visible_cells.has(revealed_cell)) + assert_eq(enemy_result_count, 1) + +func test_stairs_below_the_player_take_priority_and_mark_the_exit_reached() -> void: + var state := make_state() + state.map.set_cell(state.player.cell, GridMapState.CellKind.STAIRS) + state.map.set_cell(state.player.cell + Vector2i.UP, GridMapState.CellKind.CLOSED_DOOR) + + var results: Array[TurnResult] = state.try_interact() + + assert_true(state.exit_reached) + assert_eq(results[0].kind, &"stairs_used") + assert_eq(state.map.get_cell(state.player.cell + Vector2i.UP), GridMapState.CellKind.CLOSED_DOOR) From a8e59544ff2ebcbc7ed17bff30f6d23a7990b109 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 16:00:47 -0400 Subject: [PATCH 2/2] fix: keep stairs interaction read-only --- README.md | 4 +- scripts/domain/interaction_resolver.gd | 6 --- scripts/game/game.gd | 11 ++++-- scripts/run-visual-check.sh | 2 +- task-1-report.md | 51 -------------------------- tests/e2e/test_hud_prompts_e2e.gd | 7 ++-- tests/unit/test_door_interaction.gd | 11 ------ 7 files changed, 13 insertions(+), 79 deletions(-) delete mode 100644 task-1-report.md diff --git a/README.md b/README.md index 535d660..025462c 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; interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. +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; interacting with no target only logs `nothing_to_interact` and does not consume an enemy turn. Stairs remain a read-only HUD affordance in S5.3. ## Display, grid, and camera @@ -60,7 +60,7 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/run-visual-check.sh GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh ``` -`run-visual-check.sh` runs the actual project with `--capture-door`, opens the initial closed door before rendering, logs output to `artifacts/visual-check.log`, and requires the project-owned capture at `artifacts/visual-check.png` to be a valid **1280×720** PNG. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture. +`run-visual-check.sh` runs the actual project with `--capture`, logs output to `artifacts/visual-check.log`, and requires the project-owned capture at `artifacts/visual-check.png` to be a valid **1280×720** PNG. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture. For a direct headless startup check: diff --git a/scripts/domain/interaction_resolver.gd b/scripts/domain/interaction_resolver.gd index a09bb5e..fed3808 100644 --- a/scripts/domain/interaction_resolver.gd +++ b/scripts/domain/interaction_resolver.gd @@ -18,12 +18,6 @@ const TARGET_OFFSETS: Array[Vector2i] = [ static func resolve(state: GameState) -> Array[TurnResult]: var results: Array[TurnResult] = [] - if state.map.get_cell(state.player.cell) == GridMapState.CellKind.STAIRS: - state.exit_reached = true - results.append(TurnResultType.new(state.player.id, &"stairs_used", state.player.cell, state.player.cell, &"", 0, "You descend the stairs.")) - TurnResolverType.append_enemy_response(state, results) - return results - var door_cell := _find_closed_door(state) if door_cell.x >= 0: state.map.set_cell(door_cell, GridMapState.CellKind.FLOOR) diff --git a/scripts/game/game.gd b/scripts/game/game.gd index c7455ba..0d71be1 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -25,10 +25,7 @@ func _ready() -> void: _sync_enemy_views() hud.refresh(game_state) audio_library.set_ambience_context("exploration") - var user_args := OS.get_cmdline_user_args() - if "--capture-door" in user_args: - submit_test_interact() - if "--capture" in user_args or "--capture-door" in user_args: + if "--capture" in OS.get_cmdline_user_args(): _capture_visual_check() func _capture_visual_check() -> void: @@ -78,6 +75,8 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2: return Rect2() func _process_interact() -> Array[TurnResult]: + if game_state.get_context_target() in [&"stairs", &"exit_reached"]: + return _refresh_hud_for_context() var results := game_state.try_interact() _sync_map_renderer_visibility() player_view.refresh() @@ -87,6 +86,10 @@ func _process_interact() -> Array[TurnResult]: hud.refresh(game_state, results) return results +func _refresh_hud_for_context() -> Array[TurnResult]: + hud.refresh(game_state) + return [] + func _process_action(direction: Vector2i) -> Array[TurnResult]: var results := game_state.try_player_action(direction) _sync_map_renderer_visibility() diff --git a/scripts/run-visual-check.sh b/scripts/run-visual-check.sh index 1776d4c..36e3f35 100755 --- a/scripts/run-visual-check.sh +++ b/scripts/run-visual-check.sh @@ -28,7 +28,7 @@ if [[ -z "${DISPLAY:-}" ]]; then fi set +e -timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture-door >"$log_path" 2>&1 +timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture >"$log_path" 2>&1 status=$? set -e if (( status != 0 )); then diff --git a/task-1-report.md b/task-1-report.md deleted file mode 100644 index 8a9a543..0000000 --- a/task-1-report.md +++ /dev/null @@ -1,51 +0,0 @@ -# S5.3 — Task 1: Door interaction report - -**Worktree:** `/home/hectelyon/Documents/Projects/ProjetsPersos/DungeonCrawlerWorld/.worktrees/s5-3` - -**Branch:** `slice/s5-3-door-interaction` -**Date:** 2026-10-01 - -## Delivered - -- Added the dedicated domain `InteractionResolver` and public `GameState.try_interact()`. -- The resolver uses the frozen target order: player cell, N, E, S, W, NE, SE, SW, NW. -- A closed door becomes `FLOOR`, produces `door_opened`, and triggers the existing enemy-response mechanism exactly once. -- Stairs under the player produce `stairs_used` and set `exit_reached`. -- No target produces exactly `nothing_to_interact`, with no player/enemy state change and no enemy turn. -- Valid interaction refreshes FOV/exploration. Presentation refreshes map visibility, actor views, HUD prompt, and event log through the shared `Game` path. -- `submit_test_interact()` and configured `InputEvent` interaction both converge through `_process_interact()` into `GameState.try_interact()`. -- Extended the project-owned visual check to capture the real application after opening its initial door (`--capture-door`). -- Updated README interaction and capture documentation. - -## TDD evidence - -1. Added door unit/E2E specifications before domain implementation. -2. **Red:** `./scripts/test-unit.sh` failed as intended because `GameState.try_interact` did not exist (4 new tests failed with `Nonexistent function 'try_interact'`). -3. **Green:** implemented the resolver and shared game path; all unit and E2E checks passed. - -## Automated verification - -Executed from this worktree using Godot 4.5 and GUT 9.5: - -| Command | Result | -|---|---| -| `./scripts/test-unit.sh` | PASS — 25 tests, 108 assertions | -| `./scripts/test-e2e.sh` | PASS — 9 tests, 105 assertions | -| `env -u DISPLAY ./scripts/run-visual-check.sh` | PASS — actual app launched through Xvfb; `artifacts/visual-check.png` is 1280×720 | -| `./scripts/verify.sh` | PASS — unit, E2E, visual checks | -| `git diff --check` | PASS | - -The new real-scene E2E test verifies configured Space and E events, the `submit_test_interact()` seam, door opening, confirmation log/prompt refresh, and walking through the former door cell. Unit tests verify order, no-op behavior, FOV recalculation, one enemy response, and stairs precedence. - -## Visual proof - -- Capture: `artifacts/visual-check.png` (ignored/generated artifact) -- Log: `artifacts/visual-check.log` (ignored/generated artifact) -- Run used Xvfb because `DISPLAY` was explicitly unset. -- Capture was inspected and shows the initial north door rendered as floor, the prompt cleared, and the event log containing `You open the door.` - -## Scope and repository hygiene - -- Changes are confined to this worktree and task scope. -- No push or PR was created. -- Generated capture files remain ignored and are not part of the commit. diff --git a/tests/e2e/test_hud_prompts_e2e.gd b/tests/e2e/test_hud_prompts_e2e.gd index 61050be..9dcc5ad 100644 --- a/tests/e2e/test_hud_prompts_e2e.gd +++ b/tests/e2e/test_hud_prompts_e2e.gd @@ -29,10 +29,9 @@ func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() -> state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR) state.player.cell = Vector2i(9, 7) - var interact_results: Array[TurnResult] = game.submit_test_interact() - assert_eq(interact_results[0].kind, &"stairs_used") - assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible") - assert_eq(prompt_label.text, "Sortie atteinte — prochain étage bientôt disponible") + game.submit_test_interact() + assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier") + assert_eq(prompt_label.text, "Espace — Descendre l’escalier") var results := game.submit_test_action(Vector2i.LEFT) assert_eq(results[0].kind, &"moved") diff --git a/tests/unit/test_door_interaction.gd b/tests/unit/test_door_interaction.gd index c97dcf3..d8aabc2 100644 --- a/tests/unit/test_door_interaction.gd +++ b/tests/unit/test_door_interaction.gd @@ -62,14 +62,3 @@ func test_opening_a_door_recalculates_fov_and_triggers_exactly_one_enemy_respons assert_eq(state.map.get_cell(door), GridMapState.CellKind.FLOOR) assert_true(state.visible_cells.has(revealed_cell)) assert_eq(enemy_result_count, 1) - -func test_stairs_below_the_player_take_priority_and_mark_the_exit_reached() -> void: - var state := make_state() - state.map.set_cell(state.player.cell, GridMapState.CellKind.STAIRS) - state.map.set_cell(state.player.cell + Vector2i.UP, GridMapState.CellKind.CLOSED_DOOR) - - var results: Array[TurnResult] = state.try_interact() - - assert_true(state.exit_reached) - assert_eq(results[0].kind, &"stairs_used") - assert_eq(state.map.get_cell(state.player.cell + Vector2i.UP), GridMapState.CellKind.CLOSED_DOOR)