fix(D.5.1): UiItemList.Cell guards empty list with a diagnostic (review)

This commit is contained in:
Erik 2026-06-16 22:32:53 +02:00
parent 9c8db0d577
commit 9327fb64bf

View file

@ -24,8 +24,14 @@ public sealed class UiItemList : UiElement
public Func<uint, (uint tex, int w, int h)>? SpriteResolve { get; set; }
/// <summary>Convenience for single-cell slots (the toolbar): the first cell.</summary>
public UiItemSlot Cell => _cells[0];
/// <summary>Convenience for single-cell slots (the toolbar): the first cell.
/// Valid only while the list has at least one cell; after <see cref="Flush"/>
/// (the inventory-phase rebuild path) the list is empty until <see cref="AddItem"/>
/// runs, so use <see cref="GetItem"/> there instead.</summary>
/// <exception cref="InvalidOperationException">the list has no cells (e.g. after Flush).</exception>
public UiItemSlot Cell => _cells.Count > 0
? _cells[0]
: throw new InvalidOperationException("UiItemList has no cells; call AddItem first or use GetItem(index).");
public int GetNumUIItems() => _cells.Count;