feat(D.5.1): ItemRepository.EnrichItem (icon/name/type from CreateObject)
Adds EnrichItem(objectId, iconId, name, type) — enriches an existing stub created from PlayerDescription with the fuller data carried by its CreateObject message. Returns false when the item isn't tracked yet (phase 1: enrich-existing only). Raises ItemPropertiesUpdated on success so bound widgets (the toolbar) re-render. Two xUnit tests: enrich-existing updates IconId/Name/raises event (true), unknown-id returns false. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
da171cb4e3
commit
f8da98b67f
2 changed files with 40 additions and 0 deletions
|
|
@ -136,6 +136,23 @@ public sealed class ItemRepository
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply a <see cref="PropertyBundle"/> patch (e.g. from an
|
/// Apply a <see cref="PropertyBundle"/> patch (e.g. from an
|
||||||
/// <c>IdentifyObjectResponse</c>) to an existing item. Individual
|
/// <c>IdentifyObjectResponse</c>) to an existing item. Individual
|
||||||
|
|
|
||||||
|
|
@ -116,4 +116,27 @@ public sealed class ItemRepositoryTests
|
||||||
repo.Clear();
|
repo.Clear();
|
||||||
Assert.Equal(0, repo.ItemCount);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue