fix: describe enemy loot rewards in HUD

This commit is contained in:
goose
2026-10-09 10:25:24 -04:00
parent 4cc2bd4272
commit 0090753675
4 changed files with 116 additions and 4 deletions
+68 -1
View File
@@ -254,7 +254,14 @@ func _localized_event_message(event: GameEvent) -> String:
&"xp_granted": &"xp_granted":
return "Vous gagnez %d points d’expérience." % int(event.payload.get("xp", 0)) return "Vous gagnez %d points d’expérience." % int(event.payload.get("xp", 0))
&"loot_dropped": &"loot_dropped":
return "%s laisse tomber du butin." % _sentence_case(actor) return _localized_loot_dropped(event.payload)
&"loot_taken":
return _localized_loot_taken(event.payload)
&"item_picked_up":
var picked_item := _localized_item_quantity(event.payload)
return "Ramassé : %s." % picked_item if not picked_item.is_empty() else "Ramassage impossible."
&"pickup_refused":
return _localized_pickup_refused(event.payload)
&"companion_intercepted": &"companion_intercepted":
return "Votre familier intercepte l’attaque %s." % _with_preposition("de", actor) return "Votre familier intercepte l’attaque %s." % _with_preposition("de", actor)
&"companion_died": &"companion_died":
@@ -290,6 +297,66 @@ func _localized_event_message(event: GameEvent) -> String:
_: _:
return event.message return event.message
func _localized_loot_dropped(payload: Dictionary) -> String:
var rewards := _localized_reward_parts(payload)
if rewards.is_empty():
return "Aucun butin au sol."
return "Butin au sol : %s." % ", ".join(rewards)
func _localized_loot_taken(payload: Dictionary) -> String:
var rewards := _localized_reward_parts(payload)
var refused := _localized_refused_items(payload.get("refused_items", []))
if rewards.is_empty() and refused.is_empty():
return "Aucun butin ramassé."
var message := "Butin récupéré"
if not rewards.is_empty():
message += " : %s" % ", ".join(rewards)
if not refused.is_empty():
message += "%s%s" % [" ; " if not rewards.is_empty() else " : ", ", ".join(refused)]
return message + "."
func _localized_pickup_refused(payload: Dictionary) -> String:
var item := _localized_item_quantity(payload)
return "Inventaire plein : %s non ramassé." % item if not item.is_empty() else "Inventaire plein."
func _localized_reward_parts(payload: Dictionary) -> PackedStringArray:
var parts := PackedStringArray()
for item_data: Variant in payload.get("items", []):
if item_data is Dictionary:
var item := _localized_item_quantity(item_data)
if not item.is_empty():
parts.append(item)
var gold := int(payload.get("gold", 0))
if gold > 0:
parts.append("%d or" % gold)
var ammunition := int(payload.get("ammunition", 0))
if ammunition > 0:
parts.append("%d munitions" % ammunition)
return parts
func _localized_refused_items(items: Array) -> PackedStringArray:
var parts := PackedStringArray()
for item_data: Variant in items:
if item_data is Dictionary:
var item := _localized_item_quantity(item_data)
if not item.is_empty():
parts.append("%s non ramassé (inventaire plein)" % item)
return parts
func _localized_item_quantity(item_data: Dictionary) -> String:
var item_id := StringName(item_data.get("item_id", ""))
if item_id.is_empty():
return ""
var quantity := maxi(1, int(item_data.get("quantity", 1)))
return "%s x%d" % [_localized_item_name(item_id), quantity]
func _localized_item_name(item_id: StringName) -> String:
if _run_state != null and _run_state.content_catalog != null:
var item := _run_state.content_catalog.get_item(item_id)
if not item.is_empty():
return String(item.get("name", item_id))
return String(item_id).replace("_", " ")
func _localized_weapon(payload: Dictionary) -> String: func _localized_weapon(payload: Dictionary) -> String:
var weapon_id := StringName(payload.get("weapon_id", "")) var weapon_id := StringName(payload.get("weapon_id", ""))
if _run_state != null and _run_state.content_catalog != null and not weapon_id.is_empty(): if _run_state != null and _run_state.content_catalog != null and not weapon_id.is_empty():
+14 -1
View File
@@ -32,9 +32,22 @@ func test_real_game_resolves_damage_and_death_before_a3_feedback_and_journals_st
var loot_event: GameEvent = recent.filter(func(event: GameEvent) -> bool: return event.kind == &"loot_dropped")[0] var loot_event: GameEvent = recent.filter(func(event: GameEvent) -> bool: return event.kind == &"loot_dropped")[0]
assert_true(loot_event.payload.has("items")) assert_true(loot_event.payload.has("items"))
assert_true(loot_event.payload.has("gold")) assert_true(loot_event.payload.has("gold"))
# The deterministic demo-run seed yields a bandage and 26 gold here. Read the
# payload first so the test proves this literal French oracle describes real loot.
var expected_quantities := {&"consumable_bandage": 1}
for item: Dictionary in loot_event.payload.items:
assert_true(expected_quantities.has(StringName(item.item_id)))
assert_eq(int(item.quantity), int(expected_quantities[StringName(item.item_id)]))
assert_eq(int(loot_event.payload.gold), 26)
await _wait_for_feedback(observed) 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_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(), "Le gobelin succombe.") var hud := game.get_node("HUD") as GameHud
# Achievement entries can refresh the live journal after combat. Re-render the
# actual loot event to isolate the real HUD localization seam.
hud.refresh(state, [loot_event], game.get_run_state())
var journal_text := hud.event_log.get_parsed_text()
assert_string_contains(journal_text, "Butin au sol : Bandage x1, 26 or.")
assert_eq(journal_text.find("consumable_bandage"), -1)
func _wait_for_feedback(observed: Array[GameEvent]) -> void: func _wait_for_feedback(observed: Array[GameEvent]) -> void:
var deadline := Time.get_ticks_msec() + 2500 var deadline := Time.get_ticks_msec() + 2500
+5
View File
@@ -33,6 +33,11 @@ func test_real_interact_picks_visible_ground_item_then_inventory_action_opens_li
assert_eq(pickup.kind, &"item_picked_up") assert_eq(pickup.kind, &"item_picked_up")
assert_eq(pickup.payload.item_id, &"consumable_bandage") assert_eq(pickup.payload.item_id, &"consumable_bandage")
assert_eq(pickup.payload.quantity, 2) assert_eq(pickup.payload.quantity, 2)
# Achievements may refresh the journal after the pickup; the authoritative
# RunState event remains the HUD seam to verify.
var hud := game.get_node("HUD") as GameHud
hud.refresh(state, [pickup], game.get_run_state())
assert_string_contains(hud.event_log.get_parsed_text(), "Ramassé : Bandage x2.")
await _dispatch_key(KEY_I) await _dispatch_key(KEY_I)
+29 -2
View File
@@ -23,7 +23,7 @@ func test_hud_localizes_current_structured_journal_events_without_using_the_engl
GameEvent.new(10, 0, &"damage_dealt", {"damage": 3}, "You deal 3 damage.", &"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(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(12, 0, &"xp_granted", {"xp": 12}, "You gain experience.", &"player", &"goblin"),
GameEvent.new(13, 0, &"loot_dropped", {}, "Loot dropped.", &"goblin", &"player"), GameEvent.new(13, 0, &"loot_dropped", {"items": [{"item_id": &"consumable_bandage", "quantity": 2}, {"item_id": &"weapon_hunting_knife", "quantity": 1}], "gold": 12, "empty": false}, "Loot dropped.", &"goblin", &"player"),
GameEvent.new(14, 0, &"companion_intercepted", {}, "Your companion intercepts the attack.", &"goblin", &"companion"), 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(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(16, 0, &"companion_moved", {}, "Your companion follows.", &"companion", &"player"),
@@ -46,7 +46,7 @@ func test_hud_localizes_current_structured_journal_events_without_using_the_engl
"Vous infligez 3 dégâts au gobelin.", "Vous infligez 3 dégâts au gobelin.",
"Le gobelin succombe.", "Le gobelin succombe.",
"Vous gagnez 12 points d’expérience.", "Vous gagnez 12 points d’expérience.",
"Le gobelin laisse tomber du butin.", "Butin au sol : Bandage x2, Couteau de chasse x1, 12 or.",
"Votre familier intercepte l’attaque du gobelin.", "Votre familier intercepte l’attaque du gobelin.",
"Votre familier tombe, mais votre aventure continue.", "Votre familier tombe, mais votre aventure continue.",
"Votre familier vous suit.", "Votre familier vous suit.",
@@ -55,6 +55,33 @@ func test_hud_localizes_current_structured_journal_events_without_using_the_engl
assert_string_contains(journal_text, expected) 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."]: 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) assert_eq(journal_text.find(english_source), -1, "GameHud must localize %s from structured event data, not reuse its source message" % english_source)
for technical_id: String in ["consumable_bandage", "weapon_hunting_knife"]:
assert_eq(journal_text.find(technical_id), -1, "GameHud must resolve %s through the content catalog" % technical_id)
func test_hud_describes_empty_loot_and_pickup_outcomes_in_french() -> 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, &"loot_dropped", {"items": [], "gold": 0, "empty": true}, "Loot dropped.", &"goblin", &"player"),
GameEvent.new(2, 0, &"item_picked_up", {"item_id": &"consumable_bandage", "quantity": 2}, "Picked up consumable_bandage x2.", &"player"),
GameEvent.new(3, 0, &"pickup_refused", {"item_id": &"consumable_bandage", "quantity": 2, "reason": "inventory_full"}, "Inventory is full.", &"player"),
GameEvent.new(4, 0, &"loot_taken", {"items": [{"item_id": &"consumable_bandage", "quantity": 1}], "gold": 4, "ammunition": 3, "refused_items": [{"item_id": &"weapon_hunting_knife", "quantity": 1, "reason": "inventory_full"}]}, "Loot taken.", &"player"),
]
hud.refresh(state, events, game.get_run_state())
var journal_text := hud.event_log.get_parsed_text()
assert_string_contains(journal_text, "Aucun butin")
assert_eq(journal_text.find("laisse tomber du butin"), -1)
assert_string_contains(journal_text, "Ramassé : Bandage x2.")
assert_string_contains(journal_text, "Inventaire plein")
assert_string_contains(journal_text, "Butin récupéré : Bandage x1, 4 or, 3 munitions")
assert_string_contains(journal_text, "Couteau de chasse x1 non ramassé (inventaire plein)")
for technical_id: String in ["consumable_bandage", "weapon_hunting_knife"]:
assert_eq(journal_text.find(technical_id), -1, "GameHud must never expose known item IDs")
func test_hud_localizes_generated_enemy_ids_from_live_state_and_catalog_after_removal() -> void: func test_hud_localizes_generated_enemy_ids_from_live_state_and_catalog_after_removal() -> void:
var game := GameScene.instantiate() as Game var game := GameScene.instantiate() as Game