diff --git a/tests/unit/test_combat_presentation.gd b/tests/unit/test_combat_presentation.gd index 720568e..36ca4a6 100644 --- a/tests/unit/test_combat_presentation.gd +++ b/tests/unit/test_combat_presentation.gd @@ -19,19 +19,36 @@ func test_combat_routes_damage_feedback_and_exposes_current_target_summary() -> var enemy_view := game.get_node("World/Enemies/Goblin") as ActorView hud.refresh(state, [], game.get_run_state()) - assert_eq(hud.combat_summary, "Target: Goblin HP: 6/6") + assert_string_contains(hud.combat_summary, "Gobelin") + assert_string_contains(hud.combat_summary, "PV") + assert_eq(hud.combat_summary.find("Target"), -1) + assert_eq(hud.combat_summary.find("HP"), -1) game.submit_test_action(Vector2i.RIGHT) await _wait_for_feedback() assert_eq(player_view.last_damage, 2) - assert_eq(hud.combat_summary, "Target: Goblin HP: 6/6") + assert_string_contains(hud.combat_summary, "Gobelin") + assert_string_contains(hud.combat_summary, "PV") + assert_eq(hud.combat_summary.find("Target"), -1) + assert_eq(hud.combat_summary.find("HP"), -1) game.submit_test_action(Vector2i.RIGHT) await _wait_for_feedback() game.submit_test_action(Vector2i.RIGHT) await _wait_for_feedback() assert_false(is_instance_valid(enemy_view)) - assert_eq(hud.combat_summary, "No active target") + assert_eq(hud.combat_summary, "Aucune cible active") + assert_eq(hud.get_node("EnemyHealthLabel").text, "Aucune cible active") + assert_eq(_visible_text_occurrences(hud, "Aucune cible active"), 1, "The no-target state must have one visible string, never a duplicate") + assert_eq(_visible_text_occurrences(hud, "No active target"), 0, "The no-target state must never expose the English fallback") assert_string_contains(hud.event_log.get_parsed_text(), "with mains nues") +func _visible_text_occurrences(hud: GameHud, needle: String) -> int: + var occurrences := 0 + for node in hud.find_children("*", "Label", true, false): + var label := node as Label + if label != null and label.visible and label.text == needle: + occurrences += 1 + return occurrences + func _wait_for_feedback() -> void: await get_tree().create_timer(0.32).timeout diff --git a/tests/unit/test_hud_journal_localization.gd b/tests/unit/test_hud_journal_localization.gd new file mode 100644 index 0000000..2dc74f3 --- /dev/null +++ b/tests/unit/test_hud_journal_localization.gd @@ -0,0 +1,27 @@ +extends GutTest + +const GameScene = preload("res://scenes/Game.tscn") +const GameEvent = preload("res://scripts/domain/run/game_event.gd") + +func test_hud_localizes_current_structured_journal_events_without_using_the_english_source_message() -> void: + var game := GameScene.instantiate() as Game + add_child_autofree(game) + await get_tree().process_frame + var hud := game.get_node("HUD") as GameHud + var state := game.get_game_state() + var events: Array[GameEvent] = [ + GameEvent.new(1, 0, &"game_started", {"player_name": "Ariane"}, "Ariane begins a new run."), + GameEvent.new(2, 0, &"moved", {"to": Vector2i(6, 8)}, "You move to (6, 8)."), + GameEvent.new(3, 0, &"companion_moved", {}, "Your companion follows."), + GameEvent.new(4, 0, &"episode_published", {"number": 7}, "Episode 7 published."), + ] + + hud.refresh(state, events, game.get_run_state()) + + var journal_text := hud.event_log.get_parsed_text() + assert_string_contains(journal_text, "Ariane commence une nouvelle aventure.") + assert_string_contains(journal_text, "Vous vous déplacez vers (6, 8).") + assert_string_contains(journal_text, "Votre familier vous suit.") + assert_string_contains(journal_text, "Épisode 7 publié.") + for english_source: String in ["Ariane begins a new run.", "You move to (6, 8).", "Your companion follows.", "Episode 7 published."]: + assert_eq(journal_text.find(english_source), -1, "GameHud must localize %s from structured event data, not reuse its source message" % english_source) diff --git a/tests/unit/test_hud_layout.gd b/tests/unit/test_hud_layout.gd index 1384c98..8d9d918 100644 --- a/tests/unit/test_hud_layout.gd +++ b/tests/unit/test_hud_layout.gd @@ -270,7 +270,6 @@ func test_compact_1280_layout_contains_live_hud_regions_without_covering_the_pla 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, @@ -659,3 +658,150 @@ func _combined_label_text(labels: Array[Label]) -> String: for label in labels: text += label.text + "\n" return text + +func test_hud_shell_frames_use_the_dark_fantasy_nine_patch_texture() -> 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 + + for frame_name: String in [ + "TopBar", "LeftRail", "RightRail", "CommandBar", + "CharacterSection", "ObjectivesSection", "StatusSection", "JournalSection", "MapSection", + ]: + var frame := layout.get_node_or_null(frame_name) as Panel + assert_not_null(frame, "ResponsiveLayout requires %s" % frame_name) + if frame == null: + continue + var style := frame.get_theme_stylebox(&"panel") + assert_true(style is StyleBoxTexture, "%s must use StyleBoxTexture rather than StyleBoxFlat" % frame_name) + var texture_style := style as StyleBoxTexture + if texture_style != null: + assert_true(_texture_uses_path(texture_style.texture, "res://assets/ui/dark_fantasy/panel_64x64_nine_patch_source.png"), "%s must use panel_64x64_nine_patch_source.png" % frame_name) + +func test_play_area_masks_use_the_dungeon_background_texture() -> 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 + + const DUNGEON_BACKGROUND := "res://assets/ui/dark_fantasy/dungeon_ui_background.png" + assert_file_exists(DUNGEON_BACKGROUND, "The required dungeon background asset must exist") + for mask_name: String in ["PlayAreaMaskTop", "PlayAreaMaskLeft", "PlayAreaMaskRight", "PlayAreaMaskBottom"]: + var mask := layout.get_node_or_null(mask_name) as Panel + assert_not_null(mask, "ResponsiveLayout requires %s" % mask_name) + if mask == null: + continue + var style := mask.get_theme_stylebox(&"panel") + assert_true(style is StyleBoxTexture, "%s must use a StyleBoxTexture/AtlasTexture dungeon background" % mask_name) + var texture_style := style as StyleBoxTexture + if texture_style != null: + assert_true(_texture_uses_path(texture_style.texture, DUNGEON_BACKGROUND), "%s must use the new dungeon_ui_background.png asset" % mask_name) + +func test_decorative_equipment_and_header_art_are_absent_or_hidden() -> 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 + for decorative_name: String in ["EquipmentIllustration", "HeaderOrnament"]: + var decorative := layout.get_node_or_null(decorative_name) as Control + assert_true(decorative == null or not decorative.visible, "%s must be absent or invisible rather than adding decorative visual noise" % decorative_name) + +func test_objectives_and_status_keep_the_requested_vertical_breathing_room() -> 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 objectives := layout.get_node_or_null("ObjectivesSection") as Control if layout != null else null + var status := layout.get_node_or_null("StatusSection") as Control if layout != null else null + var status_title := layout.get_node_or_null("StatusSectionTitle") as Label if layout != null else null + assert_not_null(objectives) + assert_not_null(status) + assert_not_null(status_title) + if objectives == null or status == null or status_title == null: + return + assert_gte(status.get_global_rect().position.y - objectives.get_global_rect().end.y, 24.0, "Objectives and Status need at least 24px of vertical separation at 1920x1080") + assert_gte(status_title.get_global_rect().position.y - status.get_global_rect().position.y, 14.0, "ÉTAT title needs at least 14px top inset") + +func test_character_and_journal_titles_are_outlined_light_and_readable() -> 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) + if layout == null: + return + for title_name: String in ["CharacterSectionTitle", "JournalSectionTitle"]: + var title := layout.get_node_or_null(title_name) as Label + assert_not_null(title, "ResponsiveLayout requires %s" % title_name) + if title == null: + continue + assert_gte(title.get_theme_font_size(&"font_size"), 16, "%s needs at least a 16px font at 1920x1080" % title_name) + assert_gte(title.get_theme_constant(&"outline_size"), 2, "%s needs a >=2px contour" % title_name) + assert_gte(title.get_theme_color(&"font_color").get_luminance(), 0.60, "%s needs a light font color" % title_name) + +func test_command_bar_keeps_all_three_zones_readable_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 command_bar := layout.get_node_or_null("CommandBar") as Control if layout != null else null + var quick_slots := layout.get_node_or_null("QuickSlotStrip") as Control if layout != null else null + var prompt_panel := layout.get_node_or_null("PromptPanel") as Control if layout != null else null + var help_panel := layout.get_node_or_null("HelpPanel") as Control if layout != null else null + var quick_hint := layout.get_node_or_null("QuickSlotHint") as Label if layout != null else null + var prompt := hud.get_node_or_null("ContextPromptLabel") as Label + var help := hud.get_node_or_null("HelpLabel") as Label + assert_not_null(command_bar, "CommandBar is required at %s" % viewport_size) + assert_not_null(quick_slots) + assert_not_null(prompt_panel) + assert_not_null(help_panel) + assert_not_null(quick_hint) + assert_not_null(prompt) + assert_not_null(help) + if command_bar == null or quick_slots == null or prompt_panel == null or help_panel == null or quick_hint == null or prompt == null or help == null: + continue + for zone: Control in [quick_slots, prompt_panel, help_panel]: + assert_true(command_bar.get_global_rect().encloses(zone.get_global_rect()), "%s must remain contained at %s" % [zone.name, viewport_size]) + for index in 3: + var zones: Array[Control] = [quick_slots, prompt_panel, help_panel] + for other_index in range(index + 1, 3): + assert_false(zones[index].get_global_rect().intersects(zones[other_index].get_global_rect()), "%s and %s must not overlap at %s" % [zones[index].name, zones[other_index].name, viewport_size]) + assert_true(quick_slots.get_global_rect().encloses(quick_hint.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())) + assert_false(help.clip_text, "HelpLabel must not be truncated at %s" % viewport_size) + assert_lte(help.get_minimum_size().x, help.size.x, "The right help zone must fit its complete label at %s" % viewport_size) + assert_eq(prompt.text, "F : Distance • X : Magie • K : Familier", "The center zone must contain exactly the three requested command notions") + +func _texture_uses_path(texture: Texture2D, expected_path: String) -> bool: + if texture == null: + return false + if texture.resource_path == expected_path: + return true + if texture is AtlasTexture: + var atlas_texture := texture as AtlasTexture + return atlas_texture.atlas != null and atlas_texture.atlas.resource_path == expected_path + return false