diff --git a/src/AcDream.Core/Items/ItemRepository.cs b/src/AcDream.Core/Items/ItemRepository.cs index 02c864a2..d070a651 100644 --- a/src/AcDream.Core/Items/ItemRepository.cs +++ b/src/AcDream.Core/Items/ItemRepository.cs @@ -136,6 +136,23 @@ public sealed class ItemRepository return true; } + /// + /// Enrich an already-known item (a stub created from PlayerDescription) with the + /// fuller data carried by its CreateObject (icon, name, type). Returns false if the + /// item isn't tracked yet — phase 1 enriches existing items only; full + /// CreateObject ingestion of newly-acquired items is the inventory phase. + /// Raises ItemPropertiesUpdated on success so bound widgets (the toolbar) re-render. + /// + public bool EnrichItem(uint objectId, uint iconId, string name, ItemType type) + { + if (!_items.TryGetValue(objectId, out var item)) return false; + if (iconId != 0) item.IconId = iconId; + if (!string.IsNullOrEmpty(name)) item.Name = name; + if (type != default) item.Type = type; + ItemPropertiesUpdated?.Invoke(item); + return true; + } + /// /// Apply a patch (e.g. from an /// IdentifyObjectResponse) to an existing item. Individual diff --git a/tests/AcDream.Core.Tests/Items/ItemRepositoryTests.cs b/tests/AcDream.Core.Tests/Items/ItemRepositoryTests.cs index 79fe2ef7..23cc46fe 100644 --- a/tests/AcDream.Core.Tests/Items/ItemRepositoryTests.cs +++ b/tests/AcDream.Core.Tests/Items/ItemRepositoryTests.cs @@ -116,4 +116,27 @@ public sealed class ItemRepositoryTests repo.Clear(); Assert.Equal(0, repo.ItemCount); } + + [Fact] + public void EnrichItem_updatesIconOnExistingStub_andRaisesUpdated() + { + var repo = new ItemRepository(); + repo.AddOrUpdate(new ItemInstance { ObjectId = 0x5001u, WeenieClassId = 42u }); // stub from PlayerDescription + ItemInstance? updated = null; + repo.ItemPropertiesUpdated += i => updated = i; + + bool hit = repo.EnrichItem(0x5001u, iconId: 0x06001234u, name: "Mana Stone", type: ItemType.Misc); + + Assert.True(hit); + Assert.Equal(0x06001234u, repo.GetItem(0x5001u)!.IconId); + Assert.Equal("Mana Stone", repo.GetItem(0x5001u)!.Name); + Assert.NotNull(updated); + } + + [Fact] + public void EnrichItem_returnsFalse_whenItemUnknown() + { + var repo = new ItemRepository(); + Assert.False(repo.EnrichItem(0x9999u, 0x06001234u, "x", ItemType.Misc)); + } }