fix: localize active HUD journal events

This commit is contained in:
goose
2026-10-09 09:31:21 -04:00
parent f1b58935bf
commit dbc53aab71
11 changed files with 117 additions and 20 deletions
+55 -1
View File
@@ -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)