refactor(ui): D.2b-B — Populate uses GetContents only (drop test-driven fallback)

The implementer added a full-scan fallback in Populate() to accommodate a test
that seeded items via AddOrUpdate (which deliberately does NOT touch the container
index — only Ingest/MoveItem do). That was a production workaround for a faulty
test, and inconsistent (it only triggered when the index was wholly empty).

Root-fix: Populate reads GetContents(player) only — the index IS retail's
per-container item list. The test now seeds via the faithful indexed path
(AddOrUpdate + MoveItem → Reindex) through a SeedContained helper. 530 App tests green.
This commit is contained in:
Erik 2026-06-21 09:09:15 +02:00
parent 89c640a54d
commit 383e8b7b55
2 changed files with 22 additions and 31 deletions

View file

@ -121,38 +121,19 @@ public sealed class InventoryController
}
/// <summary>Retail gm*UI display refresh: partition the player's direct contents into loose
/// items (the "Contents of Backpack" grid) and side bags (the pack-selector list).
/// Uses the container index when available (items ingested via Ingest/MoveItem) or
/// falls back to a full scan — both paths are correct for the two production flows.</summary>
/// items (the "Contents of Backpack" grid) and side bags (the pack-selector list). The
/// container index (<see cref="ClientObjectTable.GetContents"/>) IS retail's per-container
/// item list — items enter it via the CreateObject (Ingest) / server-move (MoveItem) flows
/// that call Reindex, slot-sorted.</summary>
public void Populate()
{
uint p = _playerGuid();
// GetContents returns indexed + slot-sorted items (the production path via Ingest).
// For AddOrUpdate-seeded items (tests + initial populate before indexing), we fall
// back to scanning all objects with ContainerId == p, sorted by slot.
var indexed = _objects.GetContents(p);
IEnumerable<uint> guids;
if (indexed.Count > 0)
{
guids = indexed;
}
else
{
var direct = new List<(int slot, uint id)>();
foreach (var o in _objects.Objects)
if (o.ContainerId == p)
direct.Add((o.ContainerSlot, o.ObjectId));
direct.Sort((a, b) => a.slot.CompareTo(b.slot));
var ids = new List<uint>(direct.Count);
foreach (var (_, id) in direct) ids.Add(id);
guids = ids;
}
var contents = _objects.GetContents(p);
_contentsGrid?.Flush();
_containerList?.Flush();
foreach (var guid in guids)
foreach (var guid in contents)
{
var item = _objects.Get(guid);
if (item is null) continue;