Files
DungeonCrawlerWorld/tests/unit/test_hud_journal_localization.gd
T

70 lines
4.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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."),
# Production events carry their destination as `to_cell`, not the legacy `to` key.
GameEvent.new(2, 0, &"moved", {"to_cell": Vector2i(6, 8)}, "You move to (6, 8).", &"player"),
GameEvent.new(3, 0, &"enemy_moved", {"to_cell": Vector2i(5, 8)}, "The goblin moves.", &"goblin", &"player"),
GameEvent.new(4, 0, &"blocked", {"to_cell": Vector2i(5, 7)}, "Your way is blocked.", &"player"),
GameEvent.new(5, 0, &"melee", {"damage": 3, "attack_method": "épée courte"}, "You strike the goblin with a short sword for 3.", &"player", &"goblin"),
GameEvent.new(6, 0, &"enemy_melee", {"damage": 2, "attack_method": "griffes"}, "The goblin hits you with claws for 2.", &"goblin", &"player"),
GameEvent.new(7, 0, &"enemy_defeated", {}, "The goblin is defeated.", &"goblin", &"player"),
GameEvent.new(8, 0, &"attack_started", {"attack_method": "épée courte"}, "You attack.", &"player", &"goblin"),
GameEvent.new(9, 0, &"attack_hit", {}, "You hit.", &"player", &"goblin"),
GameEvent.new(10, 0, &"damage_dealt", {"damage": 3}, "You deal 3 damage.", &"player", &"goblin"),
GameEvent.new(11, 0, &"actor_died", {}, "The goblin is defeated.", &"goblin", &"player"),
GameEvent.new(12, 0, &"xp_granted", {"xp": 12}, "You gain experience.", &"player", &"goblin"),
GameEvent.new(13, 0, &"loot_dropped", {}, "Loot dropped.", &"goblin", &"player"),
GameEvent.new(14, 0, &"companion_intercepted", {}, "Your companion intercepts the attack.", &"goblin", &"companion"),
GameEvent.new(15, 0, &"companion_died", {}, "Your companion falls, but your run continues.", &"companion", &"player"),
GameEvent.new(16, 0, &"companion_moved", {}, "Your companion follows.", &"companion", &"player"),
GameEvent.new(17, 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()
for expected: String in [
"Ariane commence une nouvelle aventure.",
"Vous vous déplacez vers (6, 8).",
"Le gobelin se déplace.",
"Votre chemin est bloqué.",
"Vous frappez le gobelin avec épée courte et lui infligez 3 dégâts.",
"Le gobelin vous frappe avec griffes et vous inflige 2 dégâts.",
"Le gobelin est vaincu.",
"Vous attaquez le gobelin avec épée courte.",
"Vous touchez le gobelin.",
"Vous infligez 3 dégâts au gobelin.",
"Le gobelin succombe.",
"Vous gagnez 12 points d’expérience.",
"Le gobelin laisse tomber du butin.",
"Votre familier intercepte l’attaque du gobelin.",
"Votre familier tombe, mais votre aventure continue.",
"Votre familier vous suit.",
"Épisode 7 publié.",
]:
assert_string_contains(journal_text, expected)
for english_source: String in ["Ariane begins a new run.", "You move to (6, 8).", "The goblin moves.", "Your way is blocked.", "You strike the goblin with a short sword for 3.", "The goblin hits you with claws for 2.", "The goblin is defeated.", "You attack.", "You hit.", "You deal 3 damage.", "You gain experience.", "Loot dropped.", "Your companion intercepts the attack.", "Your companion falls, but your run continues.", "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)
func test_hud_keeps_the_domain_message_for_unknown_journal_event_kinds() -> 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 source_message := "An unknown event remains readable."
hud.refresh(state, [GameEvent.new(1, 0, &"unknown_event", {}, source_message)], game.get_run_state())
assert_string_contains(hud.event_log.get_parsed_text(), source_message)