Fix box name lookups falling back to raw IDs instead of localization

GetItem() returns null for box definition IDs, causing [MISSING:box_*]
display. Added GetLocalizedName() helper that checks both item and box
registries before resolving the localization key.
This commit is contained in:
Samuel Bouchet 2026-03-10 19:29:31 +01:00
parent 9c4fd0d73a
commit f88a3cc3f6

View file

@ -212,8 +212,7 @@ public static class Program
return; return;
} }
var boxNames = boxes.Select(b => var boxNames = boxes.Select(b => GetLocalizedName(b.DefinitionId)).ToList();
_loc.Get(_registry.GetItem(b.DefinitionId)?.NameKey ?? b.DefinitionId)).ToList();
boxNames.Add(_loc.Get("menu.back")); boxNames.Add(_loc.Get("menu.back"));
int choice = _renderer.ShowSelection(_loc.Get("prompt.choose_box"), boxNames); int choice = _renderer.ShowSelection(_loc.Get("prompt.choose_box"), boxNames);
@ -246,11 +245,12 @@ public static class Program
case ItemReceivedEvent itemEvt: case ItemReceivedEvent itemEvt:
_state.AddItem(itemEvt.Item); _state.AddItem(itemEvt.Item);
var itemDef = _registry.GetItem(itemEvt.Item.DefinitionId); var itemDef = _registry.GetItem(itemEvt.Item.DefinitionId);
var itemBoxDef = itemDef is null ? _registry.GetBox(itemEvt.Item.DefinitionId) : null;
_renderer.ShowLootReveal( _renderer.ShowLootReveal(
[ [
( (
_loc.Get(itemDef?.NameKey ?? itemEvt.Item.DefinitionId), GetLocalizedName(itemEvt.Item.DefinitionId),
(itemDef?.Rarity ?? ItemRarity.Common).ToString(), (itemDef?.Rarity ?? itemBoxDef?.Rarity ?? ItemRarity.Common).ToString(),
(itemDef?.Category ?? ItemCategory.Box).ToString() (itemDef?.Category ?? ItemCategory.Box).ToString()
) )
]); ]);
@ -321,9 +321,10 @@ public static class Program
.Select(g => .Select(g =>
{ {
var def = _registry.GetItem(g.Key); var def = _registry.GetItem(g.Key);
var bDef = def is null ? _registry.GetBox(g.Key) : null;
return ( return (
name: _loc.Get(def?.NameKey ?? g.Key), name: GetLocalizedName(g.Key),
rarity: (def?.Rarity ?? ItemRarity.Common).ToString(), rarity: (def?.Rarity ?? bDef?.Rarity ?? ItemRarity.Common).ToString(),
category: (def?.Category ?? ItemCategory.Box).ToString() category: (def?.Category ?? ItemCategory.Box).ToString()
); );
}) })
@ -404,7 +405,7 @@ public static class Program
var options = cosmeticItems.Select(i => var options = cosmeticItems.Select(i =>
{ {
var def = _registry.GetItem(i.DefinitionId); var def = _registry.GetItem(i.DefinitionId);
return $"[{def?.CosmeticSlot}] {_loc.Get(def?.NameKey ?? i.DefinitionId)}"; return $"[{def?.CosmeticSlot}] {GetLocalizedName(i.DefinitionId)}";
}).ToList(); }).ToList();
options.Add(_loc.Get("menu.back")); options.Add(_loc.Get("menu.back"));
@ -431,6 +432,22 @@ public static class Program
_renderer.WaitForKeyPress(_loc.Get("prompt.press_key")); _renderer.WaitForKeyPress(_loc.Get("prompt.press_key"));
} }
/// <summary>
/// Resolves the localized display name for any definition ID (item or box).
/// </summary>
private static string GetLocalizedName(string definitionId)
{
var itemDef = _registry.GetItem(definitionId);
if (itemDef is not null)
return _loc.Get(itemDef.NameKey);
var boxDef = _registry.GetBox(definitionId);
if (boxDef is not null)
return _loc.Get(boxDef.NameKey);
return _loc.Get(definitionId);
}
[System.Runtime.Versioning.SupportedOSPlatform("windows")] [System.Runtime.Versioning.SupportedOSPlatform("windows")]
private static void PlayMelody() private static void PlayMelody()
{ {