diff --git a/scripts/check-visual-capture.py b/scripts/check-visual-capture.py index ed1ccba..1b0e6f2 100755 --- a/scripts/check-visual-capture.py +++ b/scripts/check-visual-capture.py @@ -20,9 +20,9 @@ EXPECTED_DIMENSIONS = { "visual-check-exit.png": (REFERENCE_WIDTH, REFERENCE_HEIGHT), "visual-check-compact.png": (1280, 720), } -# Central dungeon measurement region in the reference 1920×1080 artboard. -# It excludes the anchored HUD panels and is scaled for the real 720p capture. -REFERENCE_VIEWPORT = (384, 60, 1536, 1017) +# The unmasked PlayAreaFrame in the reference 1920×1080 artboard. +# This is scaled for the real 720p capture. +PLAY_AREA_REFERENCE = (498, 125, 1422, 955) UNKNOWN = (1, 2, 5) # Captured explored tiles are texture modulated, so classify their blue-black # pixels by palette range rather than expecting one flat overlay color. @@ -170,13 +170,13 @@ def is_explored(pixel: tuple[int, int, int]) -> bool: # palette rather than one portable exact RGB value; accept only its dark, # blue-shifted range so HUD chrome and visible brown terrain cannot match. red, green, blue = pixel - return 4 <= red <= 14 and 8 <= green <= 22 and 17 <= blue <= 32 and blue >= green + 4 and green >= red + 3 + return 4 <= red <= 14 and 7 <= green <= 22 and 16 <= blue <= 32 and blue >= green + 4 and green >= red + 3 def viewport_for(width: int, height: int) -> tuple[int, int, int, int]: scale_x = width / REFERENCE_WIDTH scale_y = height / REFERENCE_HEIGHT - return tuple(round(coordinate * (scale_x if index % 2 == 0 else scale_y)) for index, coordinate in enumerate(REFERENCE_VIEWPORT)) + return tuple(round(coordinate * (scale_x if index % 2 == 0 else scale_y)) for index, coordinate in enumerate(PLAY_AREA_REFERENCE)) def measure(path: Path) -> None: diff --git a/scripts/game/game.gd b/scripts/game/game.gd index 020fc18..69e3758 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -343,6 +343,7 @@ func _prepare_exit_capture_state() -> void: _sync_map_renderer_visibility() _sync_minimap() player_view.refresh() + _configure_camera() _sync_camera_to_player() func _input(event: InputEvent) -> void: @@ -1994,10 +1995,18 @@ func _create_initial_state() -> GameState: 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 + # Camera2D clamps against its full engine viewport, while opaque HUD masks + # expose only PlayAreaFrame. Extend each map edge by the difference between + # those half-extents so actors at a map edge remain inside the framed area + # instead of being pinned against its border. + var frame := hud.get_node_or_null("ResponsiveLayout/PlayAreaFrame") as Control + var viewport_half := get_viewport().get_visible_rect().size / camera.zoom * 0.5 + var frame_half := frame.get_global_rect().size / camera.zoom * 0.5 if frame != null else viewport_half + var limit_padding := viewport_half - frame_half + camera.limit_left = floori($World.position.x - limit_padding.x) + camera.limit_top = floori($World.position.y - limit_padding.y) + camera.limit_right = ceili($World.position.x + map_size.x + limit_padding.x) + camera.limit_bottom = ceili($World.position.y + map_size.y + limit_padding.y) _sync_camera_to_player() func _sync_camera_to_player() -> void: diff --git a/tests/e2e/test_display_camera_grid_e2e.gd b/tests/e2e/test_display_camera_grid_e2e.gd index 7b7659c..180b126 100644 --- a/tests/e2e/test_display_camera_grid_e2e.gd +++ b/tests/e2e/test_display_camera_grid_e2e.gd @@ -30,3 +30,24 @@ func test_real_game_keyboard_movement_keeps_actor_in_cell_and_updates_camera_wit 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) + +func test_surface_exit_camera_keeps_the_player_inside_the_play_area_frame() -> void: + var state := game.get_game_state() + var camera := game.get_node("Camera2D") as Camera2D + var world := game.get_node("World") as Node2D + var player := game.get_node("World/Player") as ActorView + var play_area := game.get_node("HUD/ResponsiveLayout/PlayAreaFrame") as Control + state.player.cell = state.floor_state.exit + player.refresh() + game._configure_camera() + camera.force_update_scroll() + await get_tree().process_frame + + var player_screen_rect := Rect2( + (player.global_position - camera.get_screen_center_position()) * camera.zoom + get_viewport().get_visible_rect().size * 0.5, + Vector2(Game.TILE_SIZE) * camera.zoom + ) + assert_true(play_area.get_global_rect().encloses(player_screen_rect), "the exit player must stay within the unmasked PlayAreaFrame") + assert_gte(player_screen_rect.position.x - play_area.get_global_rect().position.x, 64.0, "the exit player needs a readable left margin") + assert_gte(play_area.get_global_rect().end.x - player_screen_rect.end.x, 64.0, "the exit player needs a readable right margin") + assert_eq(camera.position, world.position + Vector2(state.player.cell * Game.TILE_SIZE)) diff --git a/tests/unit/test_display_layout.gd b/tests/unit/test_display_layout.gd index 64527e0..ee1bf20 100644 --- a/tests/unit/test_display_layout.gd +++ b/tests/unit/test_display_layout.gd @@ -67,25 +67,31 @@ func test_minimap_root_is_enclosed_by_the_right_rail_at_reference_viewport() -> assert_true(right_rail.get_global_rect().encloses(minimap.get_global_rect())) -func test_camera_tracks_player_after_a_valid_action_and_uses_map_limits() -> void: +func test_camera_tracks_player_and_expands_limits_for_the_real_play_area() -> 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() + var play_area := game.get_node("HUD/ResponsiveLayout/PlayAreaFrame") as Control + var viewport_half := get_viewport().get_visible_rect().size / camera.zoom * 0.5 + var play_area_half := play_area.get_global_rect().size / camera.zoom * 0.5 + var limit_padding := viewport_half - play_area_half + var world := game.get_node("World") as Node2D + var map_size := Vector2(state.map.size * GameType.TILE_SIZE) - assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position) + assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + world.position) assert_eq(camera.zoom, Vector2(2.0, 2.0)) assert_eq(GameType.TILE_SIZE, Vector2i(32, 32)) assert_eq(MapRendererType.TILE_SIZE, Vector2i(32, 32)) - assert_eq(camera.limit_left, 32) - assert_eq(camera.limit_top, 48) - assert_eq(camera.limit_right, 1376) - assert_eq(camera.limit_bottom, 560) + assert_eq(camera.limit_left, floori(world.position.x - limit_padding.x)) + assert_eq(camera.limit_top, floori(world.position.y - limit_padding.y)) + assert_eq(camera.limit_right, ceili(world.position.x + map_size.x + limit_padding.x)) + assert_eq(camera.limit_bottom, ceili(world.position.y + map_size.y + limit_padding.y)) game.submit_test_action(Vector2i.DOWN) - assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + game.get_node("World").position) + assert_eq(camera.position, Vector2(state.player.cell * GameType.TILE_SIZE) + world.position) func test_play_area_has_four_opaque_masks_that_cover_only_the_artboard_outside_the_frame() -> void: var game := GameScene.instantiate() as Game @@ -156,14 +162,19 @@ func test_camera_limits_are_recomputed_when_entering_a_larger_generated_floor() await get_tree().process_frame var camera := game.get_node("Camera2D") as Camera2D var world := game.get_node("World") as Node2D + var play_area := game.get_node("HUD/ResponsiveLayout/PlayAreaFrame") as Control var state := game.get_game_state() state.player.cell = state.floor_state.exit game.submit_test_interact() + var viewport_half := get_viewport().get_visible_rect().size / camera.zoom * 0.5 + var play_area_half := play_area.get_global_rect().size / camera.zoom * 0.5 + var limit_padding := viewport_half - play_area_half + var map_size := Vector2(state.map.size * GameType.TILE_SIZE) assert_eq(game.get_run_state().current_floor, 1) - assert_eq(camera.limit_left, int(world.position.x)) - assert_eq(camera.limit_top, int(world.position.y)) - assert_eq(camera.limit_right, int(world.position.x) + state.map.size.x * GameType.TILE_SIZE.x) - assert_eq(camera.limit_bottom, int(world.position.y) + state.map.size.y * GameType.TILE_SIZE.y) + assert_eq(camera.limit_left, floori(world.position.x - limit_padding.x)) + assert_eq(camera.limit_top, floori(world.position.y - limit_padding.y)) + assert_eq(camera.limit_right, ceili(world.position.x + map_size.x + limit_padding.x)) + assert_eq(camera.limit_bottom, ceili(world.position.y + map_size.y + limit_padding.y)) assert_eq(camera.position, world.position + Vector2(state.player.cell * GameType.TILE_SIZE))