From 929e5a394c386ff688532463d558e3c9613d5fa6 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 15:21:32 -0400 Subject: [PATCH 1/7] feat: add display camera grid support --- README.md | 8 ++++- project.godot | 10 +++--- scenes/Game.tscn | 3 +- scripts/game/game.gd | 22 ++++++++++++++ scripts/presentation/actor_view.gd | 7 +++++ scripts/presentation/map_renderer.gd | 5 ++- scripts/run-visual-check.sh | 6 ++-- tests/e2e/test_display_camera_grid_e2e.gd | 32 ++++++++++++++++++++ tests/unit/test_actor_grid_alignment.gd | 20 ++++++++++++ tests/unit/test_display_layout.gd | 37 +++++++++++++++++++++++ tests/unit/test_display_layout.gd.uid | 1 + 11 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 tests/e2e/test_display_camera_grid_e2e.gd create mode 100644 tests/unit/test_actor_grid_alignment.gd create mode 100644 tests/unit/test_display_layout.gd create mode 100644 tests/unit/test_display_layout.gd.uid diff --git a/README.md b/README.md index a395a24..e354969 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ Godot 4.2+ is required (verified with Godot 4.5). GUT **9.5.0** is vendored and Use WASD / arrow keys (and QEZC diagonals). `Game.submit_test_action(Vector2i)` is the deterministic public E2E seam and follows the same action processor as keyboard input. +## Display, grid, and camera + +The project reference viewport is **1280×720**, with canvas-item stretching and a resizable window. Dungeon coordinates remain in the `cell * 32` domain: `MapRenderer.get_cell_rect(cell)` returns the exact 32×32 world rectangle for a cell, and `Game.get_actor_cell_rect(actor_id)` exposes the effective actor image rectangle. Actor sprites are top-left anchored so their complete 32×32 image is contained in their cell before and after movement. + +`Camera2D` follows the player after each valid action and is bounded to the map's world rectangle. The public HUD nodes stay below `HUD` (`CanvasLayer`, layer 1), so they remain viewport-anchored rather than moving with the camera. + ## Optional ASCII audio layout Audio is optional presentation. Its absence, unknown requests, missing folders, bad files, and unsupported codecs never affect a turn or game startup. No audio files ship with this repository. @@ -50,7 +56,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 nonempty valid PNG. It chooses `xvfb-run` 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`, 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. For a direct headless startup check: diff --git a/project.godot b/project.godot index 0be07ac..ea51a11 100644 --- a/project.godot +++ b/project.godot @@ -7,10 +7,12 @@ config/name="Dungeon Crawler World" run/main_scene="res://scenes/Game.tscn" [display] -window/size/viewport_width=640 -window/size/viewport_height=480 -window/size/window_width_override=640 -window/size/window_height_override=480 +window/size/viewport_width=1280 +window/size/viewport_height=720 +window/size/window_width_override=1280 +window/size/window_height_override=720 +window/size/resizable=true +window/stretch/mode="canvas_items" [rendering] renderer/rendering_method="gl_compatibility" diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 99d4e10..7c132cf 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -26,9 +26,10 @@ script = ExtResource("3_actor") [node name="Enemies" type="Node2D" parent="World"] [node name="Camera2D" type="Camera2D" parent="."] -position = Vector2(320, 240) +position_smoothing_enabled = false [node name="HUD" type="CanvasLayer" parent="."] +layer = 1 script = ExtResource("4_hud") [node name="PlayerHealthLabel" type="Label" parent="HUD"] diff --git a/scripts/game/game.gd b/scripts/game/game.gd index 40e1556..226cd97 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -1,6 +1,7 @@ class_name Game extends Node2D +const REFERENCE_VIEWPORT := Vector2i(1280, 720) const TILE_SIZE := Vector2i(32, 32) const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd") const ActorStateType = preload("res://scripts/domain/actor_state.gd") @@ -9,6 +10,7 @@ const ActorViewType = preload("res://scripts/presentation/actor_view.gd") @onready var map_renderer: MapRenderer = $World/MapRenderer @onready var player_view: ActorView = $World/Player @onready var enemies: Node2D = $World/Enemies +@onready var camera: Camera2D = $Camera2D @onready var hud: GameHud = $HUD @onready var audio_library = $AudioLibrary var game_state: GameState @@ -19,6 +21,7 @@ func _ready() -> void: map_renderer.set_map(game_state.map) _sync_map_renderer_visibility() player_view.set_actor(game_state.player) + _configure_camera() _sync_enemy_views() hud.refresh(game_state) audio_library.set_ambience_context("exploration") @@ -59,10 +62,18 @@ func submit_test_action(direction: Vector2i) -> Array[TurnResult]: func get_game_state() -> GameState: return game_state +func get_actor_cell_rect(actor_id: StringName) -> Rect2: + if actor_id == &"player": + return player_view.get_cell_rect() + if enemy_views.has(actor_id): + return enemy_views[actor_id].get_cell_rect() + return Rect2() + func _process_action(direction: Vector2i) -> Array[TurnResult]: var results := game_state.try_player_action(direction) _sync_map_renderer_visibility() player_view.refresh() + _sync_camera_to_player() _sync_enemy_views() _show_damage_feedback(results) _dispatch_audio(results) @@ -104,6 +115,17 @@ func _create_initial_state() -> GameState: var goblin := ActorStateType.new(&"goblin", Vector2i(4, 2), 6, 2) return GameStateType.new(map, player, {&"goblin": goblin}) +func _configure_camera() -> void: + var map_size := game_state.map.size * TILE_SIZE + camera.limit_left = $World.position.x + camera.limit_top = $World.position.y + camera.limit_right = $World.position.x + map_size.x + camera.limit_bottom = $World.position.y + map_size.y + _sync_camera_to_player() + +func _sync_camera_to_player() -> void: + camera.position = $World.position + Vector2(game_state.player.cell * TILE_SIZE) + func _sync_map_renderer_visibility() -> void: map_renderer.set_visibility(game_state.visible_cells, game_state.explored_cells) diff --git a/scripts/presentation/actor_view.gd b/scripts/presentation/actor_view.gd index 9fc7a1a..b7c7385 100644 --- a/scripts/presentation/actor_view.gd +++ b/scripts/presentation/actor_view.gd @@ -6,6 +6,13 @@ const DAMAGE_MODULATE := Color(1.0, 0.45, 0.45, 1.0) var actor: ActorState var last_damage := 0 +func _init() -> void: + centered = false + +func get_cell_rect() -> Rect2: + var local_image_rect := get_rect() + return Rect2(position + local_image_rect.position, local_image_rect.size) + func set_actor(new_actor: ActorState) -> void: actor = new_actor refresh() diff --git a/scripts/presentation/map_renderer.gd b/scripts/presentation/map_renderer.gd index e8b34b3..a650936 100644 --- a/scripts/presentation/map_renderer.gd +++ b/scripts/presentation/map_renderer.gd @@ -16,6 +16,9 @@ var map: GridMapState var _visible_cells: Dictionary[Vector2i, bool] = {} var _explored_cells: Dictionary[Vector2i, bool] = {} +func get_cell_rect(cell: Vector2i) -> Rect2: + return Rect2(Vector2(cell * TILE_SIZE), Vector2(TILE_SIZE)) + func set_map(new_map: GridMapState) -> void: map = new_map queue_redraw() @@ -47,7 +50,7 @@ func _draw() -> void: for y in range(map.size.y): for x in range(map.size.x): var cell := Vector2i(x, y) - var tile_rect := Rect2(Vector2(cell * TILE_SIZE), Vector2(TILE_SIZE)) + var tile_rect := get_cell_rect(cell) var color := get_cell_render_color(cell) if color == Color.BLACK: draw_rect(tile_rect, Color.BLACK) diff --git a/scripts/run-visual-check.sh b/scripts/run-visual-check.sh index e2bb794..36e3f35 100755 --- a/scripts/run-visual-check.sh +++ b/scripts/run-visual-check.sh @@ -20,7 +20,7 @@ rm -f "$capture_path" runner=() if [[ -z "${DISPLAY:-}" ]]; then if command -v xvfb-run >/dev/null 2>&1; then - runner=(xvfb-run --auto-servernum --server-args="-screen 0 640x480x24") + runner=(xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24") else echo "visual check unavailable: DISPLAY is unset and xvfb-run is not installed" | tee "$log_path" >&2 exit 2 @@ -56,8 +56,8 @@ with open(path, "rb") as capture: if signature != b"\x89PNG\r\n\x1a\n" or kind != b"IHDR" or len(data) != 13: raise SystemExit("invalid PNG") width, height = struct.unpack(">II", data[:8]) -if width == 0 or height == 0: - raise SystemExit("empty PNG") +if (width, height) != (1280, 720): + raise SystemExit(f"expected 1280x720 PNG, got {width}x{height}") print(f"visual capture: {path} ({width}x{height})") PY then diff --git a/tests/e2e/test_display_camera_grid_e2e.gd b/tests/e2e/test_display_camera_grid_e2e.gd new file mode 100644 index 0000000..dad8982 --- /dev/null +++ b/tests/e2e/test_display_camera_grid_e2e.gd @@ -0,0 +1,32 @@ +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_game_keyboard_movement_keeps_actor_in_cell_and_updates_camera_without_moving_hud() -> void: + var renderer := game.get_node("World/MapRenderer") as MapRenderer + var camera := game.get_node("Camera2D") as Camera2D + var hud := game.get_node("HUD") as CanvasLayer + var state := game.get_game_state() + var player_health_label := game.get_node("HUD/PlayerHealthLabel") as Label + var hud_screen_position: Vector2 = player_health_label.get_global_rect().position + var start_cell := state.player.cell + + assert_eq(Game.REFERENCE_VIEWPORT, Vector2i(1280, 720)) + assert_true(renderer.get_cell_rect(start_cell).encloses(game.get_actor_cell_rect(&"player"))) + + var keyboard_event := InputEventKey.new() + keyboard_event.physical_keycode = KEY_DOWN + keyboard_event.pressed = true + game._unhandled_input(keyboard_event) + + assert_eq(state.player.cell, start_cell + Vector2i.DOWN) + assert_true(renderer.get_cell_rect(state.player.cell).encloses(game.get_actor_cell_rect(&"player"))) + assert_eq(camera.position, game.get_node("World").position + Vector2(state.player.cell * Game.TILE_SIZE)) + assert_eq(hud.layer, 1) + assert_eq(game.get_node("HUD/PlayerHealthLabel").get_global_rect().position, hud_screen_position) diff --git a/tests/unit/test_actor_grid_alignment.gd b/tests/unit/test_actor_grid_alignment.gd new file mode 100644 index 0000000..435c0c9 --- /dev/null +++ b/tests/unit/test_actor_grid_alignment.gd @@ -0,0 +1,20 @@ +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_actor_render_rect_is_contained_in_its_grid_cell_before_and_after_movement() -> void: + var renderer := game.get_node("World/MapRenderer") as MapRenderer + var player_view := game.get_node("World/Player") as ActorView + var state := game.get_game_state() + + assert_true(renderer.get_cell_rect(state.player.cell).encloses(player_view.get_cell_rect())) + + game.submit_test_action(Vector2i.DOWN) + + assert_true(renderer.get_cell_rect(state.player.cell).encloses(player_view.get_cell_rect())) diff --git a/tests/unit/test_display_layout.gd b/tests/unit/test_display_layout.gd new file mode 100644 index 0000000..c73e6d6 --- /dev/null +++ b/tests/unit/test_display_layout.gd @@ -0,0 +1,37 @@ +extends GutTest + +const GameType = preload("res://scripts/game/game.gd") +const MapRendererType = preload("res://scripts/presentation/map_renderer.gd") +const GameScene = preload("res://scenes/Game.tscn") + +func test_reference_viewport_and_project_window_settings_are_1280_by_720() -> void: + assert_eq(GameType.REFERENCE_VIEWPORT, Vector2i(1280, 720)) + assert_eq(ProjectSettings.get_setting("display/window/size/viewport_width"), 1280) + assert_eq(ProjectSettings.get_setting("display/window/size/viewport_height"), 720) + assert_eq(ProjectSettings.get_setting("display/window/size/window_width_override"), 1280) + assert_eq(ProjectSettings.get_setting("display/window/size/window_height_override"), 720) + assert_eq(ProjectSettings.get_setting("display/window/size/resizable"), true) + assert_eq(ProjectSettings.get_setting("display/window/stretch/mode"), "canvas_items") + +func test_map_renderer_returns_the_contract_cell_rectangle() -> void: + var renderer := MapRendererType.new() + add_child_autofree(renderer) + + assert_eq(renderer.get_cell_rect(Vector2i(2, 3)), Rect2(64, 96, 32, 32)) + +func test_camera_tracks_player_after_a_valid_action_and_uses_map_limits() -> void: + var game := GameScene.instantiate() as Game + add_child_autofree(game) + await get_tree().process_frame + var camera := game.get_node("Camera2D") as Camera2D + var state := game.get_game_state() + + assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position) + assert_eq(camera.limit_left, 32) + assert_eq(camera.limit_top, 48) + assert_eq(camera.limit_right, 416) + assert_eq(camera.limit_bottom, 368) + + game.submit_test_action(Vector2i.DOWN) + + assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position) diff --git a/tests/unit/test_display_layout.gd.uid b/tests/unit/test_display_layout.gd.uid new file mode 100644 index 0000000..e64c406 --- /dev/null +++ b/tests/unit/test_display_layout.gd.uid @@ -0,0 +1 @@ +uid://cypvomhwmn2qt From 7c2c08e180f6ae87ca49c17ac8010610df7d51eb Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 15:25:56 -0400 Subject: [PATCH 2/7] docs: record S5.1 verification evidence --- README.md | 4 ++++ S4_ROUND_2_REPORT.md | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index e354969..363ab68 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ The project reference viewport is **1280×720**, with canvas-item stretching and `Camera2D` follows the player after each valid action and is bounded to the map's world rectangle. The public HUD nodes stay below `HUD` (`CanvasLayer`, layer 1), so they remain viewport-anchored rather than moving with the camera. +### S5.1 verification note + +The S5.1 contract—1280×720 reference viewport, actor rectangle, and camera behavior—is covered by the dedicated tests and visual capture check. This note records coverage only; it does not assert an execution result. + ## Optional ASCII audio layout Audio is optional presentation. Its absence, unknown requests, missing folders, bad files, and unsupported codecs never affect a turn or game startup. No audio files ship with this repository. diff --git a/S4_ROUND_2_REPORT.md b/S4_ROUND_2_REPORT.md index 0ae486b..45da073 100644 --- a/S4_ROUND_2_REPORT.md +++ b/S4_ROUND_2_REPORT.md @@ -16,3 +16,13 @@ The S4 prototype may discover admitted audio filenames under the configured ASCI ## Verification coverage Unit and E2E coverage create both a structurally nominal WAV and a truncated/invalid WAV in the external layout. They assert discovery remains diagnostic-only, neither file is playable through the public API, and combat still resolves normally. The README now states that discovery does not promise readability or playback. + +## S5.1 RED evidence reconstruction + +On base `515cf72`, a test referencing `Game.REFERENCE_VIEWPORT` produced: + +```text +SCRIPT ERROR: Parse Error: Cannot find member REFERENCE_VIEWPORT in base Game +``` + +The runner exited with status `1`. From 5679ed3008bda3b73b0d3dcf2259b9a336c2181e Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 15:40:58 -0400 Subject: [PATCH 3/7] feat: add responsive HUD prompts --- README.md | 5 +- project.godot | 1 + scenes/Game.tscn | 174 +++++++++++++++++++++++++++--- scripts/domain/game_state.gd | 11 ++ scripts/game/game.gd | 11 +- scripts/presentation/hud.gd | 21 ++++ tests/e2e/test_hud_prompts_e2e.gd | 38 +++++++ tests/unit/test_hud_layout.gd | 35 ++++++ tests/unit/test_hud_prompts.gd | 38 +++++++ 9 files changed, 314 insertions(+), 20 deletions(-) create mode 100644 tests/e2e/test_hud_prompts_e2e.gd create mode 100644 tests/unit/test_hud_layout.gd create mode 100644 tests/unit/test_hud_prompts.gd diff --git a/README.md b/README.md index 363ab68..8dcda06 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 QEZC diagonals). `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)` is the deterministic public E2E seam and follows the same action processor as keyboard input. ## Display, grid, and camera @@ -72,7 +72,8 @@ GODOT_BIN=/snap/bin/godot4 timeout 3s /snap/bin/godot4 --headless --path . - `GameState.visible_cells` render at full brightness; cells retained in `explored_cells` render dimly; unknown cells are black. - FOV is map-aware: walls and closed doors are visible but block cells behind them. -- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. +- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. Their historical public paths are retained while viewport-anchored HUD panels separate stats, journal, contextual prompt, and help. +- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. S5.2 only presents these affordances—neither doors nor stairs are modified. - Every `melee` and `enemy_melee` result is routed to its actor view; the sprite's persistent red tint makes received damage visible. ## Exports diff --git a/project.godot b/project.godot index ea51a11..d5fac00 100644 --- a/project.godot +++ b/project.godot @@ -24,6 +24,7 @@ textures/canvas_textures/default_texture_filter=0 enabled=PackedStringArray("res://addons/gut/plugin.cfg") [input] +interact={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":32),Object(InputEventKey,"physical_keycode":69)]} move_north={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":87),Object(InputEventKey,"physical_keycode":4194320)]} move_south={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":83),Object(InputEventKey,"physical_keycode":4194322)]} move_west={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":65),Object(InputEventKey,"physical_keycode":4194319)]} diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 7c132cf..b7a7795 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=3] +[gd_scene load_steps=8 format=3] [ext_resource type="Script" path="res://scripts/game/game.gd" id="1_game"] [ext_resource type="Script" path="res://scripts/presentation/map_renderer.gd" id="2_map"] @@ -7,6 +7,34 @@ [ext_resource type="Texture2D" path="res://assets/dcss/player.png" id="5_player"] [ext_resource type="Script" path="res://scripts/infrastructure/audio_library.gd" id="6_audio"] +[sub_resource type="StyleBoxFlat" id="StyleBox_hud_panel"] +bg_color = Color(0.035, 0.055, 0.09, 0.9) +border_width_left = 2 +border_width_top = 2 +border_width_right = 2 +border_width_bottom = 2 +border_color = Color(0.25, 0.48, 0.62, 0.9) +corner_radius_top_left = 6 +corner_radius_top_right = 6 +corner_radius_bottom_right = 6 +corner_radius_bottom_left = 6 +content_margin_left = 12.0 +content_margin_top = 8.0 +content_margin_right = 12.0 +content_margin_bottom = 8.0 + +[sub_resource type="StyleBoxFlat" id="StyleBox_prompt_panel"] +bg_color = Color(0.08, 0.12, 0.16, 0.94) +border_width_left = 2 +border_width_top = 2 +border_width_right = 2 +border_width_bottom = 2 +border_color = Color(0.82, 0.66, 0.25, 0.95) +corner_radius_top_left = 6 +corner_radius_top_right = 6 +corner_radius_bottom_right = 6 +corner_radius_bottom_left = 6 + [node name="Game" type="Node2D"] script = ExtResource("1_game") @@ -32,36 +60,148 @@ position_smoothing_enabled = false layer = 1 script = ExtResource("4_hud") -[node name="PlayerHealthLabel" type="Label" parent="HUD"] +[node name="ResponsiveLayout" type="Control" parent="HUD"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 + +[node name="StatsPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"] +layout_mode = 1 +anchors_preset = 0 offset_left = 12.0 -offset_top = 10.0 -offset_right = 220.0 -offset_bottom = 35.0 +offset_top = 12.0 +offset_right = 326.0 +offset_bottom = 116.0 +grow_horizontal = 0 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBox_hud_panel") + +[node name="LogPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -344.0 +offset_top = 12.0 +offset_right = -12.0 +offset_bottom = 278.0 +grow_horizontal = 0 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBox_hud_panel") + +[node name="PromptPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"] +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 332.0 +offset_top = -110.0 +offset_right = -332.0 +offset_bottom = -62.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBox_prompt_panel") + +[node name="HelpPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 12.0 +offset_top = -50.0 +offset_right = -12.0 +offset_bottom = -12.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBox_hud_panel") + +[node name="PlayerHealthLabel" type="Label" parent="HUD"] +layout_mode = 1 +anchors_preset = 0 +offset_left = 26.0 +offset_top = 20.0 +offset_right = 312.0 +offset_bottom = 44.0 +grow_horizontal = 0 +grow_vertical = 0 theme_override_colors/font_color = Color(1, 1, 1, 1) theme_override_font_sizes/font_size = 18 [node name="EnemyHealthLabel" type="Label" parent="HUD"] -offset_left = 12.0 -offset_top = 35.0 -offset_right = 240.0 -offset_bottom = 60.0 +layout_mode = 1 +anchors_preset = 0 +offset_left = 26.0 +offset_top = 48.0 +offset_right = 312.0 +offset_bottom = 72.0 +grow_horizontal = 0 +grow_vertical = 0 theme_override_colors/font_color = Color(1, 0.8, 0.7, 1) theme_override_font_sizes/font_size = 18 [node name="CombatSummaryLabel" type="Label" parent="HUD"] -offset_left = 12.0 -offset_top = 60.0 -offset_right = 300.0 -offset_bottom = 85.0 +layout_mode = 1 +anchors_preset = 0 +offset_left = 26.0 +offset_top = 78.0 +offset_right = 312.0 +offset_bottom = 100.0 +grow_horizontal = 0 +grow_vertical = 0 theme_override_colors/font_color = Color(1, 0.9, 0.5, 1) theme_override_font_sizes/font_size = 16 [node name="EventLog" type="RichTextLabel" parent="HUD"] -offset_left = 410.0 -offset_top = 285.0 -offset_right = 630.0 -offset_bottom = 470.0 +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -330.0 +offset_top = 24.0 +offset_right = -26.0 +offset_bottom = 266.0 +grow_horizontal = 0 +grow_vertical = 0 bbcode_enabled = false fit_content = false theme_override_colors/default_color = Color(1, 1, 0.8, 1) theme_override_font_sizes/normal_font_size = 14 + +[node name="ContextPromptLabel" type="Label" parent="HUD"] +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 348.0 +offset_top = -101.0 +offset_right = -348.0 +offset_bottom = -71.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_colors/font_color = Color(1, 0.92, 0.63, 1) +theme_override_font_sizes/font_size = 18 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HelpLabel" type="Label" parent="HUD"] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 28.0 +offset_top = -43.0 +offset_right = -28.0 +offset_bottom = -19.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_colors/font_color = Color(0.82, 0.9, 1, 1) +theme_override_font_sizes/font_size = 16 +text = "Déplacer : ZQSD / Flèches • Interagir : Espace ou E" +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/scripts/domain/game_state.gd b/scripts/domain/game_state.gd index ace3001..24d2474 100644 --- a/scripts/domain/game_state.gd +++ b/scripts/domain/game_state.gd @@ -8,6 +8,7 @@ var enemies: Dictionary[StringName, ActorState] var map: GridMapState var visible_cells: Dictionary[Vector2i, bool] = {} var explored_cells: Dictionary[Vector2i, bool] = {} +var exit_reached := false func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionary[StringName, ActorState]) -> void: map = new_map @@ -15,6 +16,16 @@ func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionar enemies = new_enemies update_exploration() +func get_context_target() -> StringName: + if exit_reached: + return &"exit_reached" + if map.get_cell(player.cell) == GridMapState.CellKind.STAIRS: + return &"stairs" + for direction in [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT, Vector2i(1, -1), Vector2i(1, 1), Vector2i(-1, 1), Vector2i(-1, -1)]: + if map.get_cell(player.cell + direction) == GridMapState.CellKind.CLOSED_DOOR: + return &"closed_door" + return &"" + func try_player_action(direction: Vector2i) -> Array[TurnResult]: var results := TurnResolverType.resolve_player_action(self, direction) update_exploration() diff --git a/scripts/game/game.gd b/scripts/game/game.gd index 226cd97..45163d3 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -39,7 +39,9 @@ func _capture_visual_check() -> void: get_tree().quit(0 if result == OK else 1) func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"move_north"): + if event.is_action_pressed(&"interact"): + submit_test_interact() + elif event.is_action_pressed(&"move_north"): _process_action(Vector2i.UP) elif event.is_action_pressed(&"move_south"): _process_action(Vector2i.DOWN) @@ -59,6 +61,9 @@ func _unhandled_input(event: InputEvent) -> void: func submit_test_action(direction: Vector2i) -> Array[TurnResult]: return _process_action(direction) +func submit_test_interact() -> Array[TurnResult]: + return _refresh_hud_for_context() + func get_game_state() -> GameState: return game_state @@ -69,6 +74,10 @@ 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_action(direction: Vector2i) -> Array[TurnResult]: var results := game_state.try_player_action(direction) _sync_map_renderer_visibility() diff --git a/scripts/presentation/hud.gd b/scripts/presentation/hud.gd index b8aee49..49cffbf 100644 --- a/scripts/presentation/hud.gd +++ b/scripts/presentation/hud.gd @@ -1,13 +1,20 @@ class_name GameHud extends CanvasLayer +const DOOR_PROMPT := "Espace — Ouvrir la porte" +const STAIRS_PROMPT := "Espace — Descendre l’escalier" +const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible" + @onready var player_health_label: Label = $PlayerHealthLabel @onready var enemy_health_label: Label = $EnemyHealthLabel @onready var combat_summary_label: Label = $CombatSummaryLabel @onready var event_log: RichTextLabel = $EventLog +@onready var context_prompt_label: Label = $ContextPromptLabel var combat_summary := "" +var _state: GameState func refresh(state: GameState, results: Array[TurnResult] = []) -> void: + _state = state player_health_label.text = "Player HP: %d/%d" % [state.player.hit_points, state.player.max_hit_points] if state.enemies.has(&"goblin"): var goblin: ActorState = state.enemies[&"goblin"] @@ -17,5 +24,19 @@ func refresh(state: GameState, results: Array[TurnResult] = []) -> void: enemy_health_label.text = "No active target" combat_summary = "No active target" combat_summary_label.text = combat_summary + context_prompt_label.text = get_context_prompt() for result in results: event_log.append_text(result.message + "\n") + +func get_context_prompt() -> String: + if _state == null: + return "" + match _state.get_context_target(): + &"closed_door": + return DOOR_PROMPT + &"stairs": + return STAIRS_PROMPT + &"exit_reached": + return EXIT_REACHED_PROMPT + _: + return "" diff --git a/tests/e2e/test_hud_prompts_e2e.gd b/tests/e2e/test_hud_prompts_e2e.gd new file mode 100644 index 0000000..9dcc5ad --- /dev/null +++ b/tests/e2e/test_hud_prompts_e2e.gd @@ -0,0 +1,38 @@ +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_game_exposes_door_and_stairs_prompts_with_help_and_event_log() -> void: + var hud := game.get_node("HUD") as GameHud + var state := game.get_game_state() + var help_label := game.get_node("HUD/HelpLabel") as Label + var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label + var event_log := game.get_node("HUD/EventLog") as RichTextLabel + + 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, "Interagir : Espace ou E") + + var interact_event := InputEventKey.new() + interact_event.keycode = KEY_SPACE + interact_event.pressed = true + game._unhandled_input(interact_event) + assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte") + assert_eq(state.map.get_cell(Vector2i(2, 1)), GridMapState.CellKind.CLOSED_DOOR) + + 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 results := game.submit_test_action(Vector2i.LEFT) + assert_eq(results[0].kind, &"moved") + assert_string_contains(event_log.get_parsed_text(), "You move to") diff --git a/tests/unit/test_hud_layout.gd b/tests/unit/test_hud_layout.gd new file mode 100644 index 0000000..4222789 --- /dev/null +++ b/tests/unit/test_hud_layout.gd @@ -0,0 +1,35 @@ +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_help_band_displays_the_exact_control_labels() -> void: + var help_label := game.get_node_or_null("HUD/HelpLabel") as Label + + assert_not_null(help_label) + assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches") + assert_string_contains(help_label.text, "Interagir : Espace ou E") + +func test_hud_uses_viewport_anchored_panels_with_distinct_stats_and_log_zones() -> void: + var hud := game.get_node("HUD") as GameHud + var layout := hud.get_node_or_null("ResponsiveLayout") as Control + var stats_panel := hud.get_node_or_null("ResponsiveLayout/StatsPanel") as PanelContainer + var log_panel := hud.get_node_or_null("ResponsiveLayout/LogPanel") as PanelContainer + var player_health := hud.get_node("PlayerHealthLabel") as Label + var enemy_health := hud.get_node("EnemyHealthLabel") as Label + var event_log := hud.get_node("EventLog") as RichTextLabel + + assert_not_null(layout) + assert_eq(layout.anchor_right, 1.0) + assert_eq(layout.anchor_bottom, 1.0) + assert_not_null(stats_panel) + assert_not_null(log_panel) + assert_true(stats_panel.get_global_rect().encloses(player_health.get_global_rect())) + assert_true(stats_panel.get_global_rect().encloses(enemy_health.get_global_rect())) + assert_true(log_panel.get_global_rect().encloses(event_log.get_global_rect())) + assert_false(stats_panel.get_global_rect().intersects(log_panel.get_global_rect())) diff --git a/tests/unit/test_hud_prompts.gd b/tests/unit/test_hud_prompts.gd new file mode 100644 index 0000000..44eefa6 --- /dev/null +++ b/tests/unit/test_hud_prompts.gd @@ -0,0 +1,38 @@ +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_context_prompt_describes_an_adjacent_closed_door_without_mutating_the_map() -> void: + var hud := game.get_node("HUD") as GameHud + var state := game.get_game_state() + var door_cell := Vector2i(2, 1) + + assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte") + assert_eq(state.map.get_cell(door_cell), GridMapState.CellKind.CLOSED_DOOR) + +func test_context_prompt_describes_stairs_under_player_and_nothing_else() -> void: + var hud := game.get_node("HUD") as GameHud + var state := game.get_game_state() + + state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR) + state.player.cell = Vector2i(9, 7) + hud.refresh(state) + assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier") + + state.map.set_cell(state.player.cell, GridMapState.CellKind.FLOOR) + hud.refresh(state) + assert_eq(hud.get_context_prompt(), "") + +func test_context_prompt_describes_a_reached_exit() -> void: + var hud := game.get_node("HUD") as GameHud + var state := game.get_game_state() + + state.exit_reached = true + hud.refresh(state) + assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible") From b469c6decb98a4aef34272ebd9deab696a9bdfe4 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 15:53:07 -0400 Subject: [PATCH 4/7] 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 5/7] 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) From c16f648ce80f2227cdd355b085aaea3ca9b16856 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 16:15:30 -0400 Subject: [PATCH 6/7] feat: complete stairs exit interaction and verification --- README.md | 29 ++++++++-- scripts/domain/interaction_resolver.gd | 6 ++ scripts/game/game.gd | 28 ++++++++-- scripts/run-visual-check.sh | 57 ++++++++++++------- tests/e2e/test_door_to_stairs_exit_e2e.gd | 44 +++++++++++++++ tests/e2e/test_hud_prompts_e2e.gd | 6 +- tests/unit/test_stairs_interaction.gd | 68 +++++++++++++++++++++++ 7 files changed, 206 insertions(+), 32 deletions(-) create mode 100644 tests/e2e/test_door_to_stairs_exit_e2e.gd create mode 100644 tests/unit/test_stairs_interaction.gd diff --git a/README.md b/README.md index 025462c..87f7526 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. Stairs remain a read-only HUD affordance in S5.3. +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. 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 @@ -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`, 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 twice: `--capture` records the initial state at `artifacts/visual-check.png`, while `--capture-exit` records the reached-exit state at `artifacts/visual-check-exit.png`. Both must be valid **1280×720** PNGs, and output is logged to `artifacts/visual-check.log`. 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: @@ -73,13 +73,32 @@ GODOT_BIN=/snap/bin/godot4 timeout 3s /snap/bin/godot4 --headless --path . - `GameState.visible_cells` render at full brightness; cells retained in `explored_cells` render dimly; unknown cells are black. - FOV is map-aware: walls and closed doors are visible but block cells behind them. - `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. Their historical public paths are retained while viewport-anchored HUD panels separate stats, journal, contextual prompt, and help. -- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. S5.2 only presents these affordances—neither doors nor stairs are modified. +- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. Using stairs sets only `GameState.exit_reached`, logs `stairs_used`, and leaves the player and current map in place. - Every `melee` and `enemy_melee` result is routed to its actor view; the sprite's persistent red tint makes received damage visible. ## Exports -Install the matching Godot export templates, then configure/export the project in the Godot editor for **Linux/X11** or **Windows Desktop**. Linux builds may be tested on a Linux host with the resulting executable. Windows exports can be produced from Linux when the export templates are installed, but this project does **not** claim that a Windows export has been tested on Windows. +Install the Godot 4.5 export templates matching the editor/runtime, then open `project.godot` in the Godot editor and use **Project → Export**. + +### Linux/X11 + +1. Add or select a **Linux/X11** preset. +2. Choose an output path such as `build/linux/DungeonCrawlerWorld.x86_64` and click **Export Project**. +3. On Linux, make the binary executable if necessary, then launch it: + + ```bash + chmod +x build/linux/DungeonCrawlerWorld.x86_64 + ./build/linux/DungeonCrawlerWorld.x86_64 + ``` + +### Windows Desktop + +1. Add or select a **Windows Desktop** preset. +2. Choose an output path such as `build/windows/DungeonCrawlerWorld.exe` and click **Export Project**. +3. Distribute the exported `.exe` with its generated `.pck` file when Godot produces one. + +Windows exports can be produced from Linux when the matching templates are installed, but this project does **not** claim that a Windows export has been tested on Windows. ## Limits -This compact prototype has one deterministic goblin, direct pursuit, no persistence or inventory UI, and persistent rather than animated damage tint. Audio remains intentionally nonblocking and uses no bundled assets. +This compact prototype has one deterministic goblin, direct pursuit, no persistence or inventory UI, and persistent rather than animated damage tint. Audio remains intentionally nonblocking and uses no bundled assets. Reaching the stairs is a demonstration-only exit: it sets `exit_reached` and displays `Sortie atteinte — prochain étage bientôt disponible`; **no next level is generated or loaded**, and the current player and map remain unchanged. diff --git a/scripts/domain/interaction_resolver.gd b/scripts/domain/interaction_resolver.gd index fed3808..3265601 100644 --- a/scripts/domain/interaction_resolver.gd +++ b/scripts/domain/interaction_resolver.gd @@ -18,6 +18,12 @@ 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 and not state.exit_reached: + 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 0d71be1..f347427 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -25,19 +25,37 @@ func _ready() -> void: _sync_enemy_views() hud.refresh(game_state) audio_library.set_ambience_context("exploration") - if "--capture" in OS.get_cmdline_user_args(): - _capture_visual_check() + var capture_mode := _get_capture_mode() + if not capture_mode.is_empty(): + _capture_visual_check(capture_mode) -func _capture_visual_check() -> void: +func _get_capture_mode() -> String: + var arguments := OS.get_cmdline_user_args() + if "--capture-exit" in arguments: + return "exit" + if "--capture" in arguments: + return "initial" + return "" + +func _capture_visual_check(capture_mode: String) -> void: + if capture_mode == "exit": + _prepare_exit_capture_state() await get_tree().process_frame await get_tree().process_frame await RenderingServer.frame_post_draw - var capture_path := ProjectSettings.globalize_path("res://artifacts/visual-check.png") + var filename := "visual-check-exit.png" if capture_mode == "exit" else "visual-check.png" + var capture_path := ProjectSettings.globalize_path("res://artifacts/" + filename) DirAccess.make_dir_recursive_absolute(capture_path.get_base_dir()) var image := get_viewport().get_texture().get_image() var result := image.save_png(capture_path) get_tree().quit(0 if result == OK else 1) +func _prepare_exit_capture_state() -> void: + game_state.map.set_cell(Vector2i(2, 1), GridMapStateType.CellKind.FLOOR) + game_state.player.cell = Vector2i(9, 7) + _process_interact() + _sync_camera_to_player() + func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed(&"interact"): submit_test_interact() @@ -75,7 +93,7 @@ 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"]: + if game_state.get_context_target() == &"exit_reached": return _refresh_hud_for_context() var results := game_state.try_interact() _sync_map_renderer_visibility() diff --git a/scripts/run-visual-check.sh b/scripts/run-visual-check.sh index 36e3f35..944fac4 100755 --- a/scripts/run-visual-check.sh +++ b/scripts/run-visual-check.sh @@ -14,8 +14,10 @@ fi mkdir -p artifacts log_path="artifacts/visual-check.log" -capture_path="artifacts/visual-check.png" -rm -f "$capture_path" +initial_capture_path="artifacts/visual-check.png" +exit_capture_path="artifacts/visual-check-exit.png" +rm -f "$initial_capture_path" "$exit_capture_path" +: > "$log_path" runner=() if [[ -z "${DISPLAY:-}" ]]; then @@ -27,23 +29,26 @@ if [[ -z "${DISPLAY:-}" ]]; then fi fi -set +e -timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture >"$log_path" 2>&1 -status=$? -set -e -if (( status != 0 )); then - echo "visual check failed: Godot exited with status $status; see $log_path" >&2 - exit "$status" -fi -if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then - echo "visual check failed: Godot reported errors; see $log_path" >&2 - exit 1 -fi -if [[ ! -s "$capture_path" ]]; then - echo "visual check failed: missing capture $capture_path" >&2 - exit 1 -fi -if ! python3 - "$capture_path" <<'PY' +run_capture() { + local label="$1" + local capture_argument="$2" + set +e + timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --"$capture_argument" >>"$log_path" 2>&1 + local status=$? + set -e + if (( status != 0 )); then + echo "visual check failed: $label capture Godot exited with status $status; see $log_path" >&2 + exit "$status" + fi +} + +validate_capture() { + local capture_path="$1" + if [[ ! -s "$capture_path" ]]; then + echo "visual check failed: missing capture $capture_path" >&2 + exit 1 + fi + if ! python3 - "$capture_path" <<'PY' import struct import sys @@ -60,7 +65,17 @@ if (width, height) != (1280, 720): raise SystemExit(f"expected 1280x720 PNG, got {width}x{height}") print(f"visual capture: {path} ({width}x{height})") PY -then - echo "visual check failed: capture is not a nonempty valid PNG" >&2 + then + echo "visual check failed: capture is not a nonempty valid PNG" >&2 + exit 1 + fi +} + +run_capture "initial" "capture" +run_capture "exit" "capture-exit" +if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then + echo "visual check failed: Godot reported errors; see $log_path" >&2 exit 1 fi +validate_capture "$initial_capture_path" +validate_capture "$exit_capture_path" diff --git a/tests/e2e/test_door_to_stairs_exit_e2e.gd b/tests/e2e/test_door_to_stairs_exit_e2e.gd new file mode 100644 index 0000000..cadb2d9 --- /dev/null +++ b/tests/e2e/test_door_to_stairs_exit_e2e.gd @@ -0,0 +1,44 @@ +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_input_event_completes_door_to_stairs_exit_without_replacing_the_current_map() -> 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 initial_map := state.map + var initial_map_size := state.map.size + + game._unhandled_input(_key_event(KEY_SPACE)) + assert_eq(state.map.get_cell(Vector2i(2, 1)), GridMapState.CellKind.FLOOR) + + for keycode in [KEY_UP, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT, KEY_RIGHT]: + game._unhandled_input(_key_event(keycode)) + + assert_eq(state.player.cell, Vector2i(9, 7)) + assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier") + game._unhandled_input(_key_event(KEY_E)) + + assert_true(state.exit_reached) + 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") + assert_string_contains(event_log.get_parsed_text(), "You open the door.") + assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.") + assert_same(state.map, initial_map) + assert_eq(state.map.size, initial_map_size) + assert_eq(state.map.get_cell(Vector2i(9, 7)), GridMapState.CellKind.STAIRS) + assert_eq(state.player.cell, Vector2i(9, 7)) + +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..eed1322 100644 --- a/tests/e2e/test_hud_prompts_e2e.gd +++ b/tests/e2e/test_hud_prompts_e2e.gd @@ -29,9 +29,13 @@ 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() + hud.refresh(state) assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier") assert_eq(prompt_label.text, "Espace — Descendre l’escalier") + var stairs_results := game.submit_test_interact() + assert_eq(stairs_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_stairs_interaction.gd b/tests/unit/test_stairs_interaction.gd new file mode 100644 index 0000000..76e687a --- /dev/null +++ b/tests/unit/test_stairs_interaction.gd @@ -0,0 +1,68 @@ +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") +const GameScene = preload("res://scenes/Game.tscn") + +func test_interacting_on_stairs_reaches_the_exit_emits_stairs_used_and_keeps_the_map_and_player() -> void: + var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR) + var stairs := Vector2i(3, 3) + map.set_cell(stairs, GridMapState.CellKind.STAIRS) + var player := ActorState.new(&"player", stairs, 12, 3) + var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2) + var state := GameState.new(map, player, {&"goblin": goblin}) + var player_cell := state.player.cell + var map_size := state.map.size + + var results: Array[TurnResult] = state.try_interact() + + assert_true(state.exit_reached) + assert_eq(results[0].kind, &"stairs_used") + assert_eq(results[0].from_cell, stairs) + assert_eq(results[0].to_cell, stairs) + assert_eq(results[0].message, "You descend the stairs.") + assert_eq(state.player.cell, player_cell) + assert_same(state.map, map) + assert_eq(state.map.size, map_size) + assert_eq(state.map.get_cell(stairs), GridMapState.CellKind.STAIRS) + +func test_stairs_usage_triggers_exactly_one_enemy_response_without_transitioning_the_level() -> void: + var map := GridMapState.new(Vector2i(8, 6), GridMapState.CellKind.FLOOR) + var stairs := Vector2i(3, 3) + map.set_cell(stairs, GridMapState.CellKind.STAIRS) + var player := ActorState.new(&"player", stairs, 12, 3) + var goblin := ActorState.new(&"goblin", Vector2i(6, 3), 6, 2) + var state := GameState.new(map, player, {&"goblin": goblin}) + var enemy_response_count := 0 + + var results: Array[TurnResult] = state.try_interact() + for result in results: + if String(result.kind).begins_with("enemy_"): + enemy_response_count += 1 + + assert_eq(results.size(), 2) + assert_eq(results[0].kind, &"stairs_used") + assert_eq(enemy_response_count, 1) + assert_true(state.exit_reached) + assert_eq(state.player.cell, stairs) + assert_same(state.map, map) + +func test_stairs_usage_refreshes_exact_exit_prompt_and_writes_the_journal() -> void: + var game := GameScene.instantiate() as Game + add_child_autofree(game) + await get_tree().process_frame + 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 + state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR) + state.player.cell = Vector2i(9, 7) + + var results := game.submit_test_interact() + + assert_eq(results[0].kind, &"stairs_used") + assert_true(state.exit_reached) + 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") + assert_string_contains(event_log.get_parsed_text(), "You descend the stairs.") From 6eef939905c3f303f86db3ba4f98e1c7a8d6a387 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 16:28:28 -0400 Subject: [PATCH 7/7] fix: import Godot project before test runners --- README.md | 2 + scripts/godot-import.sh | 13 ++++ scripts/run-visual-check.sh | 2 + scripts/test-e2e.sh | 3 + scripts/test-unit.sh | 3 + tests/scripts/test_godot_import_runners.sh | 73 ++++++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100755 scripts/godot-import.sh create mode 100755 tests/scripts/test_godot_import_runners.sh diff --git a/README.md b/README.md index 87f7526..09b291e 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/run-visual-check.sh GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh ``` +Each runner first executes `godot --headless --path . --import`. This generates the ignored `.godot` cache required for global script classes and imported assets, so the commands are reproducible from a newly checked-out worktree. Import failures stop the runner and retain Godot's error output. + `run-visual-check.sh` runs the actual project twice: `--capture` records the initial state at `artifacts/visual-check.png`, while `--capture-exit` records the reached-exit state at `artifacts/visual-check-exit.png`. Both must be valid **1280×720** PNGs, and output is logged to `artifacts/visual-check.log`. 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/godot-import.sh b/scripts/godot-import.sh new file mode 100755 index 0000000..5900b03 --- /dev/null +++ b/scripts/godot-import.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$root_dir" + +GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" +if [[ ! -x "$GODOT_BIN" ]]; then + GODOT_BIN="$(command -v godot4 || command -v godot || true)" +fi +: "${GODOT_BIN:?Set GODOT_BIN or install godot4/godot}" + +"$GODOT_BIN" --headless --path . --import diff --git a/scripts/run-visual-check.sh b/scripts/run-visual-check.sh index 944fac4..dc3cfcb 100755 --- a/scripts/run-visual-check.sh +++ b/scripts/run-visual-check.sh @@ -12,6 +12,8 @@ if [[ -z "$GODOT_BIN" ]]; then exit 2 fi +"$root_dir/scripts/godot-import.sh" + mkdir -p artifacts log_path="artifacts/visual-check.log" initial_capture_path="artifacts/visual-check.png" diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh index fed1347..8bbbdba 100755 --- a/scripts/test-e2e.sh +++ b/scripts/test-e2e.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash set -euo pipefail +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +"$script_dir/godot-import.sh" + GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" if [[ ! -x "$GODOT_BIN" ]]; then GODOT_BIN="$(command -v godot4 || command -v godot || true)" diff --git a/scripts/test-unit.sh b/scripts/test-unit.sh index dfa88df..361b810 100755 --- a/scripts/test-unit.sh +++ b/scripts/test-unit.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash set -euo pipefail +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +"$script_dir/godot-import.sh" + GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" if [[ ! -x "$GODOT_BIN" ]]; then GODOT_BIN="$(command -v godot4 || command -v godot || true)" diff --git a/tests/scripts/test_godot_import_runners.sh b/tests/scripts/test_godot_import_runners.sh new file mode 100755 index 0000000..e1f8b29 --- /dev/null +++ b/tests/scripts/test_godot_import_runners.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +set -euo pipefail + +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +tmp_dir="$(mktemp -d)" +trap 'rm -rf "$tmp_dir"' EXIT +project_dir="$tmp_dir/project" +cp -a "$root_dir" "$project_dir" +rm -rf "$project_dir/.git" "$project_dir/.godot" "$project_dir/artifacts" + +fake_godot="$tmp_dir/godot4" +cat > "$fake_godot" <<'FAKE_GODOT' +#!/usr/bin/env bash +set -euo pipefail +printf '%s\n' "$*" >> "$FAKE_GODOT_LOG" +if [[ " $* " == *" --import "* ]]; then + printf '%s\n' "fake import output" >&2 + exit "${FAKE_IMPORT_STATUS:-0}" +fi +if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* ]]; then + if [[ " $* " == *" --capture-exit "* ]]; then + capture_name="visual-check-exit.png" + else + capture_name="visual-check.png" + fi + python3 - "$capture_name" <<'PY' +import os +import struct +import sys + +os.makedirs("artifacts", exist_ok=True) +with open(f"artifacts/{sys.argv[1]}", "wb") as capture: + capture.write(b"\x89PNG\r\n\x1a\n") + capture.write(struct.pack(">I4sII5B", 13, b"IHDR", 1280, 720, 8, 2, 0, 0, 0)) +PY +fi +exit 0 +FAKE_GODOT +chmod +x "$fake_godot" + +assert_import_precedes_run() { + local runner="$1" + local log="$tmp_dir/${runner}.log" + FAKE_GODOT_LOG="$log" GODOT_BIN="$fake_godot" DISPLAY=:99 "$project_dir/scripts/$runner" + local first_line + first_line="$(head -n 1 "$log")" + [[ "$first_line" == *"--headless"* && "$first_line" == *"--import"* ]] || { + echo "$runner did not invoke headless import before its runner command" >&2 + return 1 + } + [[ "$(wc -l < "$log")" -ge 2 ]] || { + echo "$runner did not invoke its runner command after importing" >&2 + return 1 + } +} + +assert_import_precedes_run test-unit.sh +assert_import_precedes_run test-e2e.sh +assert_import_precedes_run run-visual-check.sh + +failure_log="$tmp_dir/import-failure.log" +set +e +failure_output="$(FAKE_GODOT_LOG="$failure_log" FAKE_IMPORT_STATUS=42 GODOT_BIN="$fake_godot" "$project_dir/scripts/test-unit.sh" 2>&1)" +failure_status=$? +set -e +[[ "$failure_status" -eq 42 ]] || { + echo "test-unit.sh did not return the import failure status" >&2 + exit 1 +} +[[ "$failure_output" == *"fake import output"* ]] || { + echo "test-unit.sh did not preserve import error output" >&2 + exit 1 +}