fix: localize active HUD journal events
This commit is contained in:
@@ -222,12 +222,43 @@ func refresh(state: GameState, events: Array[GameEvent] = [], run_state: RunStat
|
||||
## Converts only the structured events the HUD owns into French. Domain messages
|
||||
## remain untouched and provide the presentation fallback for every other kind.
|
||||
func _localized_event_message(event: GameEvent) -> String:
|
||||
var actor := _localized_actor(event.actor_id)
|
||||
var target := _localized_actor(event.target_id)
|
||||
var damage := int(event.payload.get("damage", 0))
|
||||
var attack_method := String(event.payload.get("attack_method", "attaque"))
|
||||
match event.kind:
|
||||
&"game_started":
|
||||
return "%s commence une nouvelle aventure." % String(event.payload.get("player_name", "Sans-Nom"))
|
||||
&"moved":
|
||||
var destination: Variant = event.payload.get("to", event.payload.get("to_cell", event.cell))
|
||||
var destination: Variant = event.payload.get("to_cell", event.cell)
|
||||
return "Vous vous déplacez vers %s." % destination
|
||||
&"enemy_moved":
|
||||
return "%s se déplace." % _sentence_case(actor)
|
||||
&"blocked":
|
||||
return "Votre chemin est bloqué."
|
||||
&"melee":
|
||||
return "Vous frappez %s avec %s et lui infligez %d dégâts." % [target, attack_method, damage]
|
||||
&"enemy_melee":
|
||||
return "%s vous frappe avec %s et vous inflige %d dégâts." % [_sentence_case(actor), attack_method, damage]
|
||||
&"enemy_defeated":
|
||||
return "%s est vaincu." % _sentence_case(actor)
|
||||
&"attack_started":
|
||||
return "Vous attaquez %s avec %s." % [target, attack_method] if event.actor_id == &"player" else "%s attaque %s avec %s." % [_sentence_case(actor), target, attack_method]
|
||||
&"attack_hit":
|
||||
return "Vous touchez %s." % target if event.actor_id == &"player" else "%s touche %s." % [_sentence_case(actor), target]
|
||||
&"damage_dealt":
|
||||
var damage_target := _with_preposition("à", target)
|
||||
return "Vous infligez %d dégâts %s." % [damage, damage_target] if event.actor_id == &"player" else "%s inflige %d dégâts %s." % [_sentence_case(actor), damage, damage_target]
|
||||
&"actor_died":
|
||||
return "Vous succombez." if event.actor_id == &"player" else "%s succombe." % _sentence_case(actor)
|
||||
&"xp_granted":
|
||||
return "Vous gagnez %d points d’expérience." % int(event.payload.get("xp", 0))
|
||||
&"loot_dropped":
|
||||
return "%s laisse tomber du butin." % _sentence_case(actor)
|
||||
&"companion_intercepted":
|
||||
return "Votre familier intercepte l’attaque %s." % _with_preposition("de", actor)
|
||||
&"companion_died":
|
||||
return "Votre familier tombe, mais votre aventure continue."
|
||||
&"companion_moved":
|
||||
return "Votre familier vous suit."
|
||||
&"episode_published":
|
||||
@@ -235,6 +266,29 @@ func _localized_event_message(event: GameEvent) -> String:
|
||||
_:
|
||||
return event.message
|
||||
|
||||
func _sentence_case(text: String) -> String:
|
||||
return text.left(1).to_upper() + text.substr(1)
|
||||
|
||||
func _with_preposition(preposition: String, actor: String) -> String:
|
||||
if actor.begins_with("le "):
|
||||
return "%s %s" % ["au" if preposition == "à" else "du", actor.trim_prefix("le ")]
|
||||
if actor.begins_with("les "):
|
||||
return "%s %s" % ["aux" if preposition == "à" else "des", actor.trim_prefix("les ")]
|
||||
return "%s %s" % [preposition, actor]
|
||||
|
||||
func _localized_actor(actor_id: StringName) -> String:
|
||||
match actor_id:
|
||||
&"player":
|
||||
return "vous"
|
||||
&"companion":
|
||||
return "votre familier"
|
||||
&"goblin":
|
||||
return "le gobelin"
|
||||
&"":
|
||||
return "l’adversaire"
|
||||
_:
|
||||
return String(actor_id).replace("_", " ")
|
||||
|
||||
func _refresh_live_gauge(gauge: ProgressBar, current: int, maximum: int) -> void:
|
||||
gauge.min_value = 0
|
||||
gauge.max_value = max(1, maximum)
|
||||
|
||||
@@ -16,4 +16,4 @@ func test_current_game_event_and_hud_remain_available_with_attributes_domain_loa
|
||||
assert_eq(state.enemies[&"goblin"].hit_points, 3)
|
||||
assert_true(game.get_run_state().recent_events(2).any(func(event: GameEvent) -> bool: return event.kind == &"melee"))
|
||||
assert_true(hud.player_health_label.text.contains("PV du joueur :"))
|
||||
assert_true(hud.event_log.get_parsed_text().contains("You strike the goblin"))
|
||||
assert_true(hud.event_log.get_parsed_text().contains("Vous frappez le gobelin"))
|
||||
|
||||
@@ -39,7 +39,8 @@ func test_real_game_scene_completes_adjacent_bump_combat_and_defeat_route() -> v
|
||||
assert_eq(first_melee[1].kind, &"enemy_melee")
|
||||
assert_eq(state.player.cell, Vector2i(4, 7))
|
||||
assert_eq(enemy.cell, Vector2i(5, 7))
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "with mains nues")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "Vous frappez le gobelin avec mains nues")
|
||||
assert_eq(hud.event_log.get_parsed_text().find("You"), -1)
|
||||
|
||||
var lethal_melee := game.submit_test_action(Vector2i.RIGHT)
|
||||
assert_eq(lethal_melee[0].kind, &"melee")
|
||||
|
||||
@@ -58,4 +58,4 @@ func test_real_game_enemy_detects_approaches_attacks_and_dies_with_feedback() ->
|
||||
assert_false(state.enemies.has(&"goblin"))
|
||||
await get_tree().create_timer(1.2).timeout
|
||||
assert_eq(game.get_node("World/Enemies").get_child_count(), 0)
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "defeated")
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "Le gobelin est vaincu.")
|
||||
|
||||
@@ -34,7 +34,7 @@ func test_real_game_resolves_damage_and_death_before_a3_feedback_and_journals_st
|
||||
assert_true(loot_event.payload.has("gold"))
|
||||
await _wait_for_feedback(observed)
|
||||
assert_eq(observed.map(func(event: GameEvent) -> StringName: return event.kind), [&"attack_started", &"attack_hit", &"damage_dealt", &"actor_died", &"xp_granted", &"loot_dropped"])
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "defeated")
|
||||
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "Le gobelin succombe.")
|
||||
|
||||
func _wait_for_feedback(observed: Array[GameEvent]) -> void:
|
||||
var deadline := Time.get_ticks_msec() + 2500
|
||||
|
||||
@@ -71,7 +71,7 @@ func test_live_enemy_attack_is_intercepted_in_support_and_companion_death_leaves
|
||||
assert_eq(state.player.hit_points, state.player.max_hit_points)
|
||||
assert_false(companion.is_alive())
|
||||
assert_not_null(game.get_node_or_null("World/Companion"))
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "companion")
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "Votre familier tombe")
|
||||
|
||||
func _dispatch_key(keycode: Key) -> void:
|
||||
Input.parse_input_event(_key_event(keycode, true))
|
||||
|
||||
@@ -13,9 +13,7 @@ func test_real_input_event_records_one_action_turn_and_hud_renders_its_run_state
|
||||
var run := game.get_run_state()
|
||||
var events := run.recent_events(2)
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
var expected_hud_text := "Vous vous déplacez vers (3, 7).\n"
|
||||
for event in events.slice(1):
|
||||
expected_hud_text += event.message + "\n"
|
||||
var expected_hud_text := "Vous vous déplacez vers (3, 7).\nLe gobelin se déplace.\n"
|
||||
|
||||
# One input resolves movement plus an enemy response. They are one player action,
|
||||
# so their journal events share action turn 1 and are present exactly once.
|
||||
@@ -25,7 +23,8 @@ func test_real_input_event_records_one_action_turn_and_hud_renders_its_run_state
|
||||
assert_eq(run.current_turn, 1)
|
||||
assert_eq(event_log.get_parsed_text(), expected_hud_text)
|
||||
assert_string_contains(event_log.get_parsed_text(), "Vous vous déplacez vers (3, 7).")
|
||||
assert_string_contains(event_log.get_parsed_text(), events[1].message)
|
||||
assert_string_contains(event_log.get_parsed_text(), "Le gobelin se déplace.")
|
||||
assert_eq(event_log.get_parsed_text().find(events[1].message), -1)
|
||||
|
||||
func _key_event(keycode: Key) -> InputEventKey:
|
||||
var event := InputEventKey.new()
|
||||
|
||||
@@ -40,7 +40,7 @@ func test_combat_routes_damage_feedback_and_exposes_current_target_summary() ->
|
||||
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")
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "Vous frappez le gobelin avec mains nues")
|
||||
|
||||
func _visible_text_occurrences(hud: GameHud, needle: String) -> int:
|
||||
var occurrences := 0
|
||||
|
||||
@@ -13,4 +13,4 @@ func test_hud_replaces_its_log_with_the_supplied_journal_events() -> void:
|
||||
hud.refresh(state, [GameEvent.new(1, 0, &"moved", {}, "obsolete transient message")])
|
||||
hud.refresh(state, [GameEvent.new(2, 0, &"blocked", {}, "authoritative journal message")])
|
||||
|
||||
assert_eq(hud.event_log.get_parsed_text(), "authoritative journal message\n")
|
||||
assert_eq(hud.event_log.get_parsed_text(), "Votre chemin est bloqué.\n")
|
||||
|
||||
@@ -11,17 +11,59 @@ func test_hud_localizes_current_structured_journal_events_without_using_the_engl
|
||||
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."),
|
||||
# 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()
|
||||
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."]:
|
||||
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)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://dx236r7u7q2nn
|
||||
Reference in New Issue
Block a user