diff --git a/scripts/presentation/hud.gd b/scripts/presentation/hud.gd index bc595c9..0d8f147 100644 --- a/scripts/presentation/hud.gd +++ b/scripts/presentation/hud.gd @@ -298,10 +298,27 @@ func _localized_event_message(event: GameEvent) -> String: 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) + # Enemy items remain on the ground, while gold is credited to RunState at + # death. Keep both destinations explicit instead of presenting all rewards as + # ground loot. + var dropped_items := _localized_items(payload.get("items", [])) + var gold := int(payload.get("gold", 0)) + if not dropped_items.is_empty() and gold > 0: + return "Butin — au sol : %s ; or récupéré : %d." % [", ".join(dropped_items), gold] + if not dropped_items.is_empty(): + return "Butin au sol : %s." % ", ".join(dropped_items) + if gold > 0: + return "Or récupéré : %d." % gold + return "Aucun butin." + +func _localized_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(item) + return parts func _localized_loot_taken(payload: Dictionary) -> String: var rewards := _localized_reward_parts(payload) @@ -320,18 +337,13 @@ func _localized_pickup_refused(payload: Dictionary) -> String: 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 parts := _localized_items(payload.get("items", [])) 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) + parts.append("%d munitions récupérées" % ammunition) return parts func _localized_refused_items(items: Array) -> PackedStringArray: diff --git a/tests/e2e/test_melee_feedback_e2e.gd b/tests/e2e/test_melee_feedback_e2e.gd index efb18be..4d900cf 100644 --- a/tests/e2e/test_melee_feedback_e2e.gd +++ b/tests/e2e/test_melee_feedback_e2e.gd @@ -19,34 +19,36 @@ func test_real_game_resolves_damage_and_death_before_a3_feedback_and_journals_st observed.append(event) ) + var gold_before_kill := game.get_run_state().gold game.submit_test_action(Vector2i.RIGHT) assert_false(state.enemies.has(&"goblin")) # domain result is synchronous var recent := game.get_run_state().recent_events(8).filter(func(event: GameEvent) -> bool: return event.kind in [&"attack_started", &"attack_hit", &"damage_dealt", &"actor_died", &"xp_granted", &"loot_dropped"]) assert_eq(recent.map(func(event: GameEvent) -> StringName: return event.kind), [&"attack_started", &"attack_hit", &"damage_dealt", &"actor_died", &"xp_granted", &"loot_dropped"]) assert_eq(recent[2].payload.damage, 3) - assert_true(state.floor_state.ground_items.has(enemy.cell)) - if state.floor_state.ground_items.has(enemy.cell): - assert_false(state.floor_state.ground_items[enemy.cell].is_empty()) - assert_true(state.floor_state.ground_items[enemy.cell][0] is ItemInstance) 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("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)])) + # Each item announced by the kill is an actual ItemInstance at the corpse, + # whereas gold bypasses the ground and is immediately added to RunState. + assert_true(state.floor_state.ground_items.has(enemy.cell)) + var ground_items: Array = state.floor_state.ground_items.get(enemy.cell, []) + for item_data: Dictionary in loot_event.payload.items: + var matching_items := ground_items.filter(func(item: Variant) -> bool: + return item is ItemInstance and item.definition.id == StringName(item_data.item_id) and item.quantity == int(item_data.quantity) + ) + assert_false(matching_items.is_empty(), "Loot payload item must exist as an ItemInstance on the ground") + assert_eq(game.get_run_state().gold, gold_before_kill + int(loot_event.payload.gold), "Enemy gold must be collected immediately") assert_eq(int(loot_event.payload.gold), 26) + 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"]) + # This is the live journal produced by the normal combat flow. Do not manually + # refresh it: achievement observation must not erase the player's loot detail. + await get_tree().process_frame 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_string_contains(journal_text, "Butin — au sol : Bandage x1 ; or récupéré : 26.") assert_eq(journal_text.find("consumable_bandage"), -1) func _wait_for_feedback(observed: Array[GameEvent]) -> void: diff --git a/tests/e2e/test_pickup_inventory_e2e.gd b/tests/e2e/test_pickup_inventory_e2e.gd index 9561493..539e865 100644 --- a/tests/e2e/test_pickup_inventory_e2e.gd +++ b/tests/e2e/test_pickup_inventory_e2e.gd @@ -33,10 +33,10 @@ func test_real_interact_picks_visible_ground_item_then_inventory_action_opens_li assert_eq(pickup.kind, &"item_picked_up") assert_eq(pickup.payload.item_id, &"consumable_bandage") assert_eq(pickup.payload.quantity, 2) - # Achievements may refresh the journal after the pickup; the authoritative - # RunState event remains the HUD seam to verify. + # Assert the journal the player sees after the real interaction; no manual + # refresh may mask a later observer (such as achievements) overwriting it. var hud := game.get_node("HUD") as GameHud - hud.refresh(state, [pickup], game.get_run_state()) + await get_tree().process_frame assert_string_contains(hud.event_log.get_parsed_text(), "Ramassé : Bandage x2.") await _dispatch_key(KEY_I) diff --git a/tests/unit/test_hud_journal_localization.gd b/tests/unit/test_hud_journal_localization.gd index d95d773..65e91bc 100644 --- a/tests/unit/test_hud_journal_localization.gd +++ b/tests/unit/test_hud_journal_localization.gd @@ -46,7 +46,7 @@ func test_hud_localizes_current_structured_journal_events_without_using_the_engl "Vous infligez 3 dégâts au gobelin.", "Le gobelin succombe.", "Vous gagnez 12 points d’expérience.", - "Butin au sol : Bandage x2, Couteau de chasse x1, 12 or.", + "Butin — au sol : Bandage x2, Couteau de chasse x1 ; or récupéré : 12.", "Votre familier intercepte l’attaque du gobelin.", "Votre familier tombe, mais votre aventure continue.", "Votre familier vous suit.", @@ -58,27 +58,40 @@ func test_hud_localizes_current_structured_journal_events_without_using_the_engl 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: +func test_hud_distinguishes_dropped_enemy_items_from_immediately_collected_gold() -> 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 cases: Array[Dictionary] = [ + {"payload": {"items": [{"item_id": &"consumable_bandage", "quantity": 1}], "gold": 26}, "expected": "Butin — au sol : Bandage x1 ; or récupéré : 26."}, + {"payload": {"items": [{"item_id": &"consumable_bandage", "quantity": 2}], "gold": 0}, "expected": "Butin au sol : Bandage x2."}, + {"payload": {"items": [], "gold": 8}, "expected": "Or récupéré : 8."}, + {"payload": {"items": [], "gold": 0, "empty": true}, "expected": "Aucun butin."}, + ] + for test_case: Dictionary in cases: + hud.refresh(state, [GameEvent.new(1, 0, &"loot_dropped", test_case.payload, "Loot dropped.", &"goblin", &"player")], game.get_run_state()) + assert_eq(hud.event_log.get_parsed_text(), "%s\n" % test_case.expected) + +func test_hud_describes_pickup_and_loot_take_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"), + GameEvent.new(1, 0, &"item_picked_up", {"item_id": &"consumable_bandage", "quantity": 2}, "Picked up consumable_bandage x2.", &"player"), + GameEvent.new(2, 0, &"pickup_refused", {"item_id": &"consumable_bandage", "quantity": 2, "reason": "inventory_full"}, "Inventory is full.", &"player"), + GameEvent.new(3, 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, "Butin récupéré : Bandage x1, 4 or, 3 munitions récupérées") 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")