524 lines
27 KiB
GDScript
524 lines
27 KiB
GDScript
extends GutTest
|
|
|
|
const GameScene = preload("res://scenes/Game.tscn")
|
|
const HEADER_VALUES_GROUP := &"hud_header_values"
|
|
const CHARACTER_VALUES_GROUP := &"hud_character_values"
|
|
const COMMAND_HINTS_GROUP := &"hud_command_hints"
|
|
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)
|
|
if help_label == null:
|
|
return
|
|
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
|
|
assert_string_contains(help_label.text, "nord-est : pavé num. 9")
|
|
assert_string_contains(help_label.text, "Interagir : Espace ou E")
|
|
|
|
func test_xp_bar_shows_progress_inside_the_current_level_and_refreshes_after_xp_gain() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var state := game.get_game_state()
|
|
var xp_bar := hud.get_node_or_null("ExperienceBar") as ProgressBar
|
|
var xp_label := hud.get_node_or_null("ExperienceLabel") as Label
|
|
|
|
assert_not_null(xp_bar)
|
|
assert_not_null(xp_label)
|
|
if xp_bar == null or xp_label == null:
|
|
return
|
|
assert_eq(xp_bar.min_value, 0.0)
|
|
assert_eq(xp_bar.max_value, 100.0)
|
|
assert_eq(xp_bar.value, 0.0)
|
|
assert_eq(xp_label.text, "Niveau 1 — XP 0/100")
|
|
|
|
state.player.progression.set_total_xp(125)
|
|
hud.refresh(state, [], game.get_run_state())
|
|
|
|
assert_eq(xp_bar.max_value, 200.0)
|
|
assert_eq(xp_bar.value, 25.0)
|
|
assert_eq(xp_label.text, "Niveau 2 — XP 25/200")
|
|
|
|
func test_hud_preserves_legacy_responsive_panel_paths() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout")
|
|
if layout == null:
|
|
return
|
|
|
|
var stats_panel := layout.get_node_or_null("StatsPanel") as PanelContainer
|
|
var log_panel := layout.get_node_or_null("LogPanel") as PanelContainer
|
|
var prompt_panel := layout.get_node_or_null("PromptPanel") as PanelContainer
|
|
var help_panel := layout.get_node_or_null("HelpPanel") as PanelContainer
|
|
assert_not_null(stats_panel, "HUD must preserve ResponsiveLayout/StatsPanel")
|
|
assert_not_null(log_panel, "HUD must preserve ResponsiveLayout/LogPanel because GameHud uses that path")
|
|
assert_not_null(prompt_panel, "HUD must preserve ResponsiveLayout/PromptPanel")
|
|
assert_not_null(help_panel, "HUD must preserve ResponsiveLayout/HelpPanel")
|
|
if stats_panel == null or log_panel == null or prompt_panel == null or help_panel == null:
|
|
return
|
|
|
|
var player_health := hud.get_node_or_null("PlayerHealthLabel") as Control
|
|
var event_log := hud.get_node_or_null("EventLog") as Control
|
|
var prompt := hud.get_node_or_null("ContextPromptLabel") as Control
|
|
var help := hud.get_node_or_null("HelpLabel") as Control
|
|
assert_not_null(player_health, "StatsPanel requires the existing health control")
|
|
assert_not_null(event_log, "LogPanel requires the existing event log")
|
|
assert_not_null(prompt, "PromptPanel requires the existing context prompt")
|
|
assert_not_null(help, "HelpPanel requires the existing help label")
|
|
if player_health == null or event_log == null or prompt == null or help == null:
|
|
return
|
|
assert_true(stats_panel.get_global_rect().encloses(player_health.get_global_rect()))
|
|
assert_true(log_panel.get_global_rect().encloses(event_log.get_global_rect()))
|
|
assert_true(prompt_panel.get_global_rect().encloses(prompt.get_global_rect()))
|
|
assert_true(help_panel.get_global_rect().encloses(help.get_global_rect()))
|
|
|
|
func test_hud_defines_a_full_frame_shell_with_a_significant_centered_play_area() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout")
|
|
if layout == null:
|
|
return
|
|
|
|
var top_bar := layout.get_node_or_null("TopBar") as Control
|
|
var left_rail := layout.get_node_or_null("LeftRail") as Control
|
|
var play_area_frame := layout.get_node_or_null("PlayAreaFrame") as Control
|
|
var right_rail := layout.get_node_or_null("RightRail") as Control
|
|
var command_bar := layout.get_node_or_null("CommandBar") as Control
|
|
assert_not_null(top_bar, "ResponsiveLayout requires a TopBar")
|
|
assert_not_null(left_rail, "ResponsiveLayout requires a LeftRail")
|
|
assert_not_null(play_area_frame, "ResponsiveLayout requires a PlayAreaFrame")
|
|
assert_not_null(right_rail, "ResponsiveLayout requires a RightRail")
|
|
assert_not_null(command_bar, "ResponsiveLayout requires a CommandBar")
|
|
if top_bar == null or left_rail == null or play_area_frame == null or right_rail == null or command_bar == null:
|
|
return
|
|
|
|
assert_eq(layout.anchor_right, 1.0)
|
|
assert_eq(layout.anchor_bottom, 1.0)
|
|
_assert_play_area_is_centered_and_inside_effective_viewport(play_area_frame)
|
|
var play_rect := play_area_frame.get_global_rect()
|
|
assert_false(left_rail.get_global_rect().intersects(play_rect), "LeftRail must not cover the framed play area")
|
|
assert_false(right_rail.get_global_rect().intersects(play_rect), "RightRail must not cover the framed play area")
|
|
assert_false(top_bar.get_global_rect().intersects(play_rect), "TopBar must not cover the framed play area")
|
|
assert_false(command_bar.get_global_rect().intersects(play_rect), "CommandBar must not cover the framed play area")
|
|
assert_false(left_rail.get_global_rect().intersects(right_rail.get_global_rect()), "the two rails must be distinct")
|
|
assert_false(top_bar.get_global_rect().intersects(command_bar.get_global_rect()), "the top and command bars must be distinct")
|
|
|
|
func test_live_hud_content_is_enclosed_by_its_intended_shell_region() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout")
|
|
if layout == null:
|
|
return
|
|
var top_bar := layout.get_node_or_null("TopBar") as Control
|
|
var left_rail := layout.get_node_or_null("LeftRail") as Control
|
|
var right_rail := layout.get_node_or_null("RightRail") as Control
|
|
var command_bar := layout.get_node_or_null("CommandBar") as Control
|
|
assert_not_null(top_bar, "ResponsiveLayout requires a TopBar")
|
|
assert_not_null(left_rail, "ResponsiveLayout requires a LeftRail")
|
|
assert_not_null(right_rail, "ResponsiveLayout requires a RightRail")
|
|
assert_not_null(command_bar, "ResponsiveLayout requires a CommandBar")
|
|
if top_bar == null or left_rail == null or right_rail == null or command_bar == null:
|
|
return
|
|
|
|
_assert_controls_enclosed(top_bar, [
|
|
hud.get_node_or_null("AchievementToast") as Control,
|
|
hud.get_node_or_null("TitleLabel") as Control,
|
|
] + _controls_in_group(hud, HEADER_VALUES_GROUP), "TopBar")
|
|
_assert_controls_enclosed(left_rail, [
|
|
hud.get_node_or_null("PlayerHealthLabel") as Control,
|
|
hud.get_node_or_null("PlayerFocusLabel") as Control,
|
|
hud.get_node_or_null("ExperienceBar") as Control,
|
|
hud.get_node_or_null("ExperienceLabel") as Control,
|
|
hud.get_node_or_null("GoldLabel") as Control,
|
|
hud.get_node_or_null("QuestTrackerLabel") as Control,
|
|
hud.get_node_or_null("SpellLabel") as Control,
|
|
hud.get_node_or_null("EnemyHealthLabel") as Control,
|
|
hud.get_node_or_null("CombatSummaryLabel") as Control,
|
|
hud.get_node_or_null("DeadlineLabel") as Control,
|
|
] + _controls_in_group(hud, CHARACTER_VALUES_GROUP), "LeftRail")
|
|
_assert_controls_enclosed(right_rail, [hud.get_node_or_null("EventLog") as Control], "RightRail")
|
|
_assert_controls_enclosed(command_bar, _controls_in_group(hud, COMMAND_HINTS_GROUP), "CommandBar")
|
|
|
|
func test_dynamic_hud_groups_refresh_from_live_game_values() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout")
|
|
if layout == null:
|
|
return
|
|
var top_bar := layout.get_node_or_null("TopBar") as Control
|
|
var left_rail := layout.get_node_or_null("LeftRail") as Control
|
|
var command_bar := layout.get_node_or_null("CommandBar") as Control
|
|
assert_not_null(top_bar, "ResponsiveLayout requires a TopBar")
|
|
assert_not_null(left_rail, "ResponsiveLayout requires a LeftRail")
|
|
assert_not_null(command_bar, "ResponsiveLayout requires a CommandBar")
|
|
if top_bar == null or left_rail == null or command_bar == null:
|
|
return
|
|
|
|
var state := game.get_game_state()
|
|
var run := game.get_run_state()
|
|
run.player_name = "Dame Ysabel"
|
|
state.player.hit_points = state.player.max_hit_points - 1
|
|
state.player.cell = state.floor_state.entrance
|
|
hud.refresh(state, [], run)
|
|
|
|
var header_values := _labels_in_group(hud, HEADER_VALUES_GROUP)
|
|
var character_values := _labels_in_group(hud, CHARACTER_VALUES_GROUP)
|
|
var command_hints := _labels_in_group(hud, COMMAND_HINTS_GROUP)
|
|
assert_gte(header_values.size(), 1, "TopBar exposes dynamic header values through the hud_header_values group")
|
|
assert_gte(character_values.size(), 1, "LeftRail exposes dynamic character values through the hud_character_values group")
|
|
assert_gte(command_hints.size(), 1, "CommandBar exposes dynamic hints through the hud_command_hints group")
|
|
if header_values.is_empty() or character_values.is_empty() or command_hints.is_empty():
|
|
return
|
|
|
|
var header_text := _combined_label_text(header_values)
|
|
var character_text := _combined_label_text(character_values)
|
|
var expected_room_id := ""
|
|
for room: RoomState in state.floor_state.rooms:
|
|
if room.bounds.has_point(state.player.cell):
|
|
expected_room_id = String(room.id)
|
|
break
|
|
assert_ne(expected_room_id, "", "The player's authored room must be discoverable from its bounds")
|
|
assert_string_contains(header_text, run.player_name)
|
|
assert_string_contains(header_text, str(state.floor_state.floor_number))
|
|
assert_string_contains(header_text, expected_room_id)
|
|
assert_string_contains(header_text, str(state.explored_cells.size()))
|
|
assert_string_contains(character_text, str(state.player.hit_points))
|
|
_assert_controls_enclosed(top_bar, header_values, "TopBar")
|
|
_assert_controls_enclosed(left_rail, character_values, "LeftRail")
|
|
|
|
state.player.cell = Vector2i(35, 7)
|
|
hud.refresh(state, [], run)
|
|
assert_string_contains(_combined_label_text(command_hints), hud.get_context_prompt())
|
|
assert_string_contains(_combined_label_text(command_hints), "Ouvrir la porte")
|
|
_assert_controls_enclosed(command_bar, command_hints, "CommandBar")
|
|
|
|
func test_compact_1280_layout_scales_header_text_and_keeps_it_inside_the_top_bar() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
|
|
hud.apply_viewport_layout(Vector2(1280, 720))
|
|
var top_bar := hud.get_node_or_null("ResponsiveLayout/TopBar") as Control
|
|
var header := hud.get_node_or_null("HeaderValuesLabel") as Label
|
|
assert_not_null(top_bar, "ResponsiveLayout requires a TopBar")
|
|
assert_not_null(header, "HUD requires HeaderValuesLabel")
|
|
if top_bar == null or header == null:
|
|
return
|
|
|
|
assert_eq(header.get_theme_font_size(&"font_size"), 11, "The compact shell scales the 16px header value font to the 1280x720 artboard")
|
|
assert_true(top_bar.get_global_rect().encloses(header.get_global_rect()), "The compact header remains inside its TopBar")
|
|
assert_lte(header.get_minimum_size().y, header.size.y, "The compact header has enough height for its scaled text")
|
|
|
|
func test_compact_1280_layout_contains_live_hud_regions_without_covering_the_play_area() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
|
|
hud.apply_viewport_layout(Vector2(1280, 720))
|
|
await get_tree().process_frame
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
var minimap := hud.get_node_or_null("Minimap") as Minimap
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout")
|
|
assert_not_null(minimap, "HUD requires its live minimap")
|
|
if layout == null or minimap == null:
|
|
return
|
|
var top_bar := layout.get_node_or_null("TopBar") as Control
|
|
var left_rail := layout.get_node_or_null("LeftRail") as Control
|
|
var play_area := layout.get_node_or_null("PlayAreaFrame") as Control
|
|
var right_rail := layout.get_node_or_null("RightRail") as Control
|
|
var command_bar := layout.get_node_or_null("CommandBar") as Control
|
|
var stats_panel := layout.get_node_or_null("StatsPanel") as Control
|
|
var log_panel := layout.get_node_or_null("LogPanel") as Control
|
|
var prompt_panel := layout.get_node_or_null("PromptPanel") as Control
|
|
var help_panel := layout.get_node_or_null("HelpPanel") as Control
|
|
var quick_slots := layout.get_node_or_null("QuickSlotStrip") as Control
|
|
assert_not_null(top_bar)
|
|
assert_not_null(left_rail)
|
|
assert_not_null(play_area)
|
|
assert_not_null(right_rail)
|
|
assert_not_null(command_bar)
|
|
assert_not_null(stats_panel)
|
|
assert_not_null(log_panel)
|
|
assert_not_null(prompt_panel)
|
|
assert_not_null(help_panel)
|
|
assert_not_null(quick_slots)
|
|
if top_bar == null or left_rail == null or play_area == null or right_rail == null or command_bar == null or stats_panel == null or log_panel == null or prompt_panel == null or help_panel == null or quick_slots == null:
|
|
return
|
|
|
|
_assert_controls_enclosed(top_bar, [
|
|
hud.get_node_or_null("AchievementToast") as Control,
|
|
hud.get_node_or_null("TitleLabel") as Control,
|
|
hud.get_node_or_null("HeaderValuesLabel") as Control,
|
|
layout.get_node_or_null("HeaderOrnament") as Control,
|
|
], "compact TopBar")
|
|
_assert_controls_enclosed(left_rail, [
|
|
stats_panel,
|
|
hud.get_node_or_null("PlayerHealthLabel") as Control,
|
|
hud.get_node_or_null("HealthBar") as Control,
|
|
hud.get_node_or_null("PlayerFocusLabel") as Control,
|
|
hud.get_node_or_null("FocusBar") as Control,
|
|
hud.get_node_or_null("ExperienceBar") as Control,
|
|
hud.get_node_or_null("ExperienceLabel") as Control,
|
|
hud.get_node_or_null("CharacterStatusLabel") as Control,
|
|
hud.get_node_or_null("GoldLabel") as Control,
|
|
hud.get_node_or_null("QuestTrackerLabel") as Control,
|
|
hud.get_node_or_null("SpellLabel") as Control,
|
|
hud.get_node_or_null("EnemyHealthLabel") as Control,
|
|
hud.get_node_or_null("CombatSummaryLabel") as Control,
|
|
hud.get_node_or_null("DeadlineLabel") as Control,
|
|
], "compact LeftRail")
|
|
_assert_controls_enclosed(right_rail, [
|
|
log_panel,
|
|
hud.get_node_or_null("EventLog") as Control,
|
|
minimap,
|
|
], "compact RightRail")
|
|
_assert_controls_enclosed(command_bar, [prompt_panel, help_panel, quick_slots,
|
|
hud.get_node_or_null("ContextPromptLabel") as Control,
|
|
hud.get_node_or_null("HelpLabel") as Control,
|
|
layout.get_node_or_null("QuickSlotHint") as Control,
|
|
], "compact CommandBar")
|
|
|
|
for shell: Control in [top_bar, left_rail, right_rail, command_bar]:
|
|
assert_false(shell.get_global_rect().intersects(play_area.get_global_rect()), "%s must not cover the compact PlayAreaFrame" % shell.name)
|
|
assert_false(minimap.get_global_rect().intersects(play_area.get_global_rect()), "The compact minimap must remain off the PlayAreaFrame")
|
|
|
|
for label: Label in [
|
|
hud.get_node_or_null("HeaderValuesLabel") as Label,
|
|
hud.get_node_or_null("PlayerHealthLabel") as Label,
|
|
hud.get_node_or_null("PlayerFocusLabel") as Label,
|
|
hud.get_node_or_null("ExperienceLabel") as Label,
|
|
hud.get_node_or_null("ContextPromptLabel") as Label,
|
|
hud.get_node_or_null("HelpLabel") as Label,
|
|
]:
|
|
assert_not_null(label)
|
|
if label != null:
|
|
assert_gte(label.get_theme_font_size(&"font_size"), 9, "%s must keep a readable compact font" % label.name)
|
|
var journal := hud.get_node_or_null("EventLog") as RichTextLabel
|
|
assert_not_null(journal)
|
|
if journal != null:
|
|
assert_gte(journal.get_theme_font_size(&"normal_font_size"), 9, "The compact journal font must remain readable")
|
|
|
|
func test_non_sixteen_by_nine_viewports_center_the_artboard_and_mask_every_outside_band() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
|
|
for viewport_size: Vector2 in [Vector2(1024, 768), Vector2(2560, 1080)]:
|
|
hud.apply_viewport_layout(viewport_size)
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
var artboard := layout.get_node_or_null("Artboard") as Control if layout != null else null
|
|
assert_not_null(artboard, "ResponsiveLayout requires its centered 16:9 Artboard")
|
|
if layout == null or artboard == null:
|
|
return
|
|
var scale := minf(viewport_size.x / GameHud.REFERENCE_VIEWPORT.x, viewport_size.y / GameHud.REFERENCE_VIEWPORT.y)
|
|
var expected_size := GameHud.REFERENCE_VIEWPORT * scale
|
|
var expected_origin := (viewport_size - expected_size) * 0.5
|
|
assert_eq(artboard.position, expected_origin, "The artboard must be centered at %s" % viewport_size)
|
|
assert_eq(artboard.size, expected_size, "The artboard must preserve a 16:9 size at %s" % viewport_size)
|
|
|
|
var artboard_rect := artboard.get_global_rect()
|
|
for shell_name: String in ["TopBar", "LeftRail", "PlayAreaFrame", "RightRail", "CommandBar"]:
|
|
var shell := layout.get_node_or_null(shell_name) as Control
|
|
assert_not_null(shell)
|
|
if shell != null:
|
|
assert_true(artboard_rect.encloses(shell.get_global_rect()), "%s must remain inside the 16:9 artboard" % shell_name)
|
|
|
|
for band_name: String in ["LetterboxTop", "LetterboxBottom", "PillarboxLeft", "PillarboxRight"]:
|
|
var band := layout.get_node_or_null(band_name) as Panel
|
|
assert_not_null(band, "ResponsiveLayout requires %s" % band_name)
|
|
if band != null and band.size.x > 0.0 and band.size.y > 0.0:
|
|
var style := band.get_theme_stylebox(&"panel") as StyleBoxFlat
|
|
assert_not_null(style, "%s needs an explicit opaque panel style" % band_name)
|
|
if style != null:
|
|
assert_eq(style.bg_color.a, 1.0, "%s must be opaque so the world cannot show through" % band_name)
|
|
assert_false(band.get_global_rect().intersects(artboard_rect), "%s must cover only the outside band" % band_name)
|
|
|
|
var top := layout.get_node_or_null("LetterboxTop") as Control
|
|
var bottom := layout.get_node_or_null("LetterboxBottom") as Control
|
|
var left := layout.get_node_or_null("PillarboxLeft") as Control
|
|
var right := layout.get_node_or_null("PillarboxRight") as Control
|
|
if viewport_size == Vector2(1024, 768):
|
|
assert_eq(top.size, Vector2(1024, 96), "1024x768 needs a fully covered top letterbox")
|
|
assert_eq(bottom.size, Vector2(1024, 96), "1024x768 needs a fully covered bottom letterbox")
|
|
assert_eq(left.size.x, 0.0)
|
|
assert_eq(right.size.x, 0.0)
|
|
else:
|
|
assert_eq(left.size, Vector2(320, 1080), "ultrawide needs a fully covered left pillarbox")
|
|
assert_eq(right.size, Vector2(320, 1080), "ultrawide needs a fully covered right pillarbox")
|
|
assert_eq(top.size.y, 0.0)
|
|
assert_eq(bottom.size.y, 0.0)
|
|
|
|
func test_long_deadline_text_wraps_and_stays_inside_the_left_rail() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var state := game.get_game_state()
|
|
var run := game.get_run_state()
|
|
run.current_floor = 1
|
|
run.ensure_floor_deadline(1)
|
|
hud.refresh(state, [], run)
|
|
await get_tree().process_frame
|
|
|
|
var left_rail := hud.get_node_or_null("ResponsiveLayout/LeftRail") as Control
|
|
var deadline := hud.get_node_or_null("DeadlineLabel") as Label
|
|
assert_not_null(left_rail, "ResponsiveLayout requires a LeftRail")
|
|
assert_not_null(deadline, "HUD requires DeadlineLabel")
|
|
if left_rail == null or deadline == null:
|
|
return
|
|
assert_true(left_rail.get_global_rect().encloses(deadline.get_global_rect()))
|
|
assert_lte(deadline.get_minimum_size().x, deadline.size.x)
|
|
assert_gt(deadline.size.y, deadline.get_line_height())
|
|
|
|
func test_event_log_and_log_panel_never_intersect_the_hud_minimap_at_reference_and_compact_sizes() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
|
|
for viewport_size: Vector2 in [Vector2(1920, 1080), Vector2(1280, 720)]:
|
|
hud.apply_viewport_layout(viewport_size)
|
|
await get_tree().process_frame
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
var event_log := hud.get_node_or_null("EventLog") as Control
|
|
var minimap := hud.get_node_or_null("Minimap") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout at %s" % viewport_size)
|
|
assert_not_null(event_log, "HUD requires EventLog at %s" % viewport_size)
|
|
assert_not_null(minimap, "HUD requires Minimap at %s" % viewport_size)
|
|
if layout == null or event_log == null or minimap == null:
|
|
return
|
|
var log_panel := layout.get_node_or_null("LogPanel") as Control
|
|
assert_not_null(log_panel, "HUD requires ResponsiveLayout/LogPanel at %s" % viewport_size)
|
|
if log_panel == null:
|
|
return
|
|
|
|
assert_false(event_log.get_global_rect().intersects(minimap.get_global_rect()), "EventLog must not intersect HUD/Minimap at %s" % viewport_size)
|
|
assert_false(log_panel.get_global_rect().intersects(minimap.get_global_rect()), "LogPanel must not intersect HUD/Minimap at %s" % viewport_size)
|
|
|
|
func test_artboard_rails_and_center_follow_the_mockup_width_proportions() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
|
|
for viewport_size: Vector2 in [Vector2(1920, 1080), Vector2(1280, 720)]:
|
|
hud.apply_viewport_layout(viewport_size)
|
|
await get_tree().process_frame
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout at %s" % viewport_size)
|
|
if layout == null:
|
|
return
|
|
var artboard := layout.get_node_or_null("Artboard") as Control
|
|
var left_rail := layout.get_node_or_null("LeftRail") as Control
|
|
var play_area := layout.get_node_or_null("PlayAreaFrame") as Control
|
|
var right_rail := layout.get_node_or_null("RightRail") as Control
|
|
assert_not_null(artboard, "ResponsiveLayout requires Artboard at %s" % viewport_size)
|
|
assert_not_null(left_rail, "ResponsiveLayout requires LeftRail at %s" % viewport_size)
|
|
assert_not_null(play_area, "ResponsiveLayout requires PlayAreaFrame at %s" % viewport_size)
|
|
assert_not_null(right_rail, "ResponsiveLayout requires RightRail at %s" % viewport_size)
|
|
if artboard == null or left_rail == null or play_area == null or right_rail == null:
|
|
return
|
|
|
|
var left_ratio := left_rail.size.x / artboard.size.x
|
|
var center_ratio := play_area.size.x / artboard.size.x
|
|
var right_ratio := right_rail.size.x / artboard.size.x
|
|
assert_gte(left_ratio, 0.22, "LeftRail must use at least 22%% of the artboard width at %s" % viewport_size)
|
|
assert_lte(left_ratio, 0.26, "LeftRail must use at most 26%% of the artboard width at %s" % viewport_size)
|
|
assert_gte(center_ratio, 0.48, "PlayAreaFrame must use at least 48%% of the artboard width at %s" % viewport_size)
|
|
assert_lte(center_ratio, 0.56, "PlayAreaFrame must use at most 56%% of the artboard width at %s" % viewport_size)
|
|
assert_gte(right_ratio, 0.22, "RightRail must use at least 22%% of the artboard width at %s" % viewport_size)
|
|
assert_lte(right_ratio, 0.26, "RightRail must use at most 26%% of the artboard width at %s" % viewport_size)
|
|
|
|
func test_named_left_and_right_rail_sections_are_visible_enclosed_and_non_overlapping() -> void:
|
|
var hud := game.get_node_or_null("HUD") as GameHud
|
|
assert_not_null(hud, "Game scene requires HUD")
|
|
if hud == null:
|
|
return
|
|
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
|
assert_not_null(layout, "HUD requires ResponsiveLayout")
|
|
if layout == null:
|
|
return
|
|
|
|
_assert_named_non_overlapping_sections(layout, "LeftRail", ["CharacterSection", "ObjectivesSection", "StatusSection"])
|
|
_assert_named_non_overlapping_sections(layout, "RightRail", ["JournalSection", "MapSection"])
|
|
|
|
func _assert_named_non_overlapping_sections(layout: Control, rail_name: String, section_names: Array[String]) -> void:
|
|
var rail := layout.get_node_or_null(rail_name) as Control
|
|
assert_not_null(rail, "ResponsiveLayout requires %s" % rail_name)
|
|
if rail == null:
|
|
return
|
|
var sections: Array[Control] = []
|
|
for section_name in section_names:
|
|
var section := layout.get_node_or_null(section_name) as Control
|
|
assert_not_null(section, "%s requires a visible %s" % [rail_name, section_name])
|
|
if section == null:
|
|
continue
|
|
assert_true(section.visible, "%s must be visible" % section_name)
|
|
assert_true(rail.get_global_rect().encloses(section.get_global_rect()), "%s must be enclosed by %s" % [section_name, rail_name])
|
|
sections.append(section)
|
|
for index in sections.size():
|
|
for other_index in range(index + 1, sections.size()):
|
|
assert_false(sections[index].get_global_rect().intersects(sections[other_index].get_global_rect()), "%s must not overlap %s" % [sections[index].name, sections[other_index].name])
|
|
|
|
func _assert_play_area_is_centered_and_inside_effective_viewport(play_area_frame: Control) -> void:
|
|
var viewport_rect := get_viewport().get_visible_rect()
|
|
var expected_viewport := Vector2(Game.REFERENCE_VIEWPORT)
|
|
var play_rect := play_area_frame.get_global_rect()
|
|
assert_eq(viewport_rect.size, expected_viewport, "HUD layout is evaluated in the effective 1920x1080 viewport")
|
|
assert_gte(play_rect.position.x, viewport_rect.position.x, "PlayAreaFrame must stay inside the viewport on the left")
|
|
assert_gte(play_rect.position.y, viewport_rect.position.y, "PlayAreaFrame must stay inside the viewport at the top")
|
|
assert_lte(play_rect.end.x, viewport_rect.end.x, "PlayAreaFrame must stay inside the viewport on the right")
|
|
assert_lte(play_rect.end.y, viewport_rect.end.y, "PlayAreaFrame must stay inside the viewport at the bottom")
|
|
assert_gte(play_rect.size.x, viewport_rect.size.x * 0.40, "PlayAreaFrame must have meaningful viewport width")
|
|
assert_gte(play_rect.size.y, viewport_rect.size.y * 0.40, "PlayAreaFrame must have meaningful viewport height")
|
|
assert_gte(play_rect.get_area(), viewport_rect.get_area() * 0.25, "PlayAreaFrame must occupy a meaningful part of the viewport")
|
|
assert_lte(play_rect.get_center().distance_to(viewport_rect.get_center()), 2.0, "PlayAreaFrame must be centered in the effective viewport")
|
|
|
|
func _assert_controls_enclosed(region: Control, controls: Array, region_name: String) -> void:
|
|
for live_control: Control in controls:
|
|
assert_not_null(live_control, "%s must retain its live HUD control" % region_name)
|
|
if live_control != null:
|
|
assert_true(region.get_global_rect().encloses(live_control.get_global_rect()), "%s must enclose %s" % [region_name, live_control.get_path()])
|
|
|
|
func _controls_in_group(hud: GameHud, group_name: StringName) -> Array[Control]:
|
|
var controls: Array[Control] = []
|
|
for node in get_tree().get_nodes_in_group(group_name):
|
|
if node is Control and hud.is_ancestor_of(node):
|
|
controls.append(node as Control)
|
|
return controls
|
|
|
|
func _labels_in_group(hud: GameHud, group_name: StringName) -> Array[Label]:
|
|
var labels: Array[Label] = []
|
|
for node in _controls_in_group(hud, group_name):
|
|
if node is Label:
|
|
labels.append(node as Label)
|
|
return labels
|
|
|
|
func _combined_label_text(labels: Array[Label]) -> String:
|
|
var text := ""
|
|
for label in labels:
|
|
text += label.text + "\n"
|
|
return text
|