diff --git a/tests/unit/test_hud_layout.gd b/tests/unit/test_hud_layout.gd index a27a1b9..1384c98 100644 --- a/tests/unit/test_hud_layout.gd +++ b/tests/unit/test_hud_layout.gd @@ -482,6 +482,144 @@ func _assert_named_non_overlapping_sections(layout: Control, rail_name: String, 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 test_character_section_exposes_live_name_and_level_labels() -> 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 + var character_section := layout.get_node_or_null("CharacterSection") as Control if layout != null else null + var name_label := layout.get_node_or_null("CharacterNameLabel") as Label if layout != null else null + var level_label := layout.get_node_or_null("CharacterLevelLabel") as Label if layout != null else null + assert_not_null(layout, "HUD requires ResponsiveLayout") + assert_not_null(character_section, "ResponsiveLayout requires CharacterSection") + assert_not_null(name_label, "CharacterSection requires CharacterNameLabel") + assert_not_null(level_label, "CharacterSection requires CharacterLevelLabel") + if layout == null or character_section == null or name_label == null or level_label == null: + return + + var state := game.get_game_state() + var run := game.get_run_state() + run.player_name = "Dame Ysabel" + state.player.progression.set_total_xp(125) + hud.refresh(state, [], run) + + assert_true(name_label.visible, "CharacterNameLabel must be visible") + assert_true(level_label.visible, "CharacterLevelLabel must be visible") + assert_true(character_section.get_global_rect().encloses(name_label.get_global_rect()), "CharacterSection must contain CharacterNameLabel") + assert_true(character_section.get_global_rect().encloses(level_label.get_global_rect()), "CharacterSection must contain CharacterLevelLabel") + assert_string_contains(name_label.text, run.player_name, "CharacterNameLabel must show the real player name") + assert_string_contains(level_label.text, str(state.player.progression.level), "CharacterLevelLabel must show the real player level") + +func test_character_portrait_uses_mockup_width_and_preserves_its_aspect_ratio_at_reference_size() -> 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(1920, 1080)) + await get_tree().process_frame + var layout := hud.get_node_or_null("ResponsiveLayout") as Control + var character_section := layout.get_node_or_null("CharacterSection") as Control if layout != null else null + var portrait := layout.get_node_or_null("PortraitIllustration") as TextureRect if layout != null else null + assert_not_null(character_section, "ResponsiveLayout requires CharacterSection") + assert_not_null(portrait, "CharacterSection requires PortraitIllustration") + if character_section == null or portrait == null: + return + assert_true(portrait.visible, "PortraitIllustration must be visible") + assert_gte(portrait.size.x / character_section.size.x, 0.28, "Portrait must use at least 28%% of CharacterSection width") + assert_lte(portrait.size.x / character_section.size.x, 0.38, "Portrait must use at most 38%% of CharacterSection width") + var texture := portrait.texture as Texture2D + assert_not_null(texture, "PortraitIllustration requires a portrait texture") + if texture != null: + assert_almost_eq(portrait.size.x / portrait.size.y, texture.get_width() as float / texture.get_height() as float, 0.01, "PortraitIllustration must preserve the portrait aspect ratio") + +func test_section_titles_are_visible_contained_and_readable_at_reference_size() -> 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(1920, 1080)) + await get_tree().process_frame + var layout := hud.get_node_or_null("ResponsiveLayout") as Control + assert_not_null(layout, "HUD requires ResponsiveLayout") + if layout == null: + return + var section_names := ["CharacterSection", "ObjectivesSection", "StatusSection", "JournalSection", "MapSection"] + var title_names := ["CharacterSectionTitle", "ObjectivesSectionTitle", "StatusSectionTitle", "JournalSectionTitle", "MapSectionTitle"] + for index in section_names.size(): + var section := layout.get_node_or_null(section_names[index]) as Control + var title := layout.get_node_or_null(title_names[index]) as Label + assert_not_null(section, "ResponsiveLayout requires %s" % section_names[index]) + assert_not_null(title, "ResponsiveLayout requires %s" % title_names[index]) + if section == null or title == null: + continue + assert_true(title.visible, "%s must be visible" % title_names[index]) + assert_true(section.get_global_rect().encloses(title.get_global_rect()), "%s must contain %s" % [section_names[index], title_names[index]]) + assert_gte(title.get_theme_font_size(&"font_size"), 16, "%s must use at least a 16px font at 1920x1080" % title_names[index]) + +func test_top_bar_contains_readable_non_overlapping_title_and_header_values() -> 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(1920, 1080)) + await get_tree().process_frame + var layout := hud.get_node_or_null("ResponsiveLayout") as Control + var top_bar := layout.get_node_or_null("TopBar") as Control if layout != null else null + var title := hud.get_node_or_null("TitleLabel") as Label + var header_values := hud.get_node_or_null("HeaderValuesLabel") as Label + assert_not_null(top_bar, "ResponsiveLayout requires TopBar") + assert_not_null(title, "TopBar requires TitleLabel") + assert_not_null(header_values, "TopBar requires HeaderValuesLabel") + if top_bar == null or title == null or header_values == null: + return + assert_true(top_bar.get_global_rect().encloses(title.get_global_rect()), "TopBar must contain TitleLabel") + assert_true(top_bar.get_global_rect().encloses(header_values.get_global_rect()), "TopBar must contain HeaderValuesLabel") + assert_false(title.get_global_rect().intersects(header_values.get_global_rect()), "TitleLabel and HeaderValuesLabel must not intersect") + assert_gte(title.get_theme_font_size(&"font_size"), 20, "TitleLabel must use at least a 20px font at 1920x1080") + assert_gte(header_values.get_theme_font_size(&"font_size"), 15, "HeaderValuesLabel must use at least a 15px font at 1920x1080") + +func test_command_bar_subzones_are_distinct_and_contain_their_text() -> 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(1920, 1080)) + await get_tree().process_frame + var layout := hud.get_node_or_null("ResponsiveLayout") as Control + var command_bar := layout.get_node_or_null("CommandBar") as Control if layout != null else null + assert_not_null(command_bar, "ResponsiveLayout requires CommandBar") + if layout == null or command_bar == null: + return + var quick_slots := layout.get_node_or_null("QuickSlotStrip") 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_text := layout.get_node_or_null("QuickSlotHint") as Control + var prompt_text := hud.get_node_or_null("ContextPromptLabel") as Control + var help_text := hud.get_node_or_null("HelpLabel") as Control + for zone: Control in [quick_slots, prompt_panel, help_panel]: + assert_not_null(zone, "CommandBar requires its three text sub-zones") + if zone != null: + assert_true(zone.visible, "%s must be visible" % zone.name) + assert_true(command_bar.get_global_rect().encloses(zone.get_global_rect()), "%s must be contained by CommandBar" % zone.name) + for index in 3: + for other_index in range(index + 1, 3): + var zones: Array[Control] = [quick_slots, prompt_panel, help_panel] + if zones[index] != null and zones[other_index] != null: + assert_false(zones[index].get_global_rect().intersects(zones[other_index].get_global_rect()), "%s must not overlap %s" % [zones[index].name, zones[other_index].name]) + assert_not_null(quick_text, "QuickSlotStrip requires QuickSlotHint") + assert_not_null(prompt_text, "PromptPanel requires ContextPromptLabel") + assert_not_null(help_text, "HelpPanel requires HelpLabel") + for text_control: Control in [quick_text, prompt_text, help_text]: + if text_control != null: + assert_true(text_control.visible, "%s text must be visible" % text_control.name) + if quick_slots != null and quick_text != null: + assert_true(quick_slots.get_global_rect().encloses(quick_text.get_global_rect()), "QuickSlotStrip must contain its text") + if prompt_panel != null and prompt_text != null: + assert_true(prompt_panel.get_global_rect().encloses(prompt_text.get_global_rect()), "PromptPanel must contain its text") + if help_panel != null and help_text != null: + assert_true(help_panel.get_global_rect().encloses(help_text.get_global_rect()), "HelpPanel must contain its text") + 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)