Files
Emberwild/Assets/GAME/Script/Inventory/SlotContent.cs
2026-07-22 12:56:13 +02:00

43 lines
1.6 KiB
C#

namespace Ashwild.Inventory
{
/// <summary>
/// A container-agnostic snapshot of what a slot holds: the item, how many, and the remaining uses
/// of this concrete instance (-1 when the item does not track uses). It is the common currency
/// between every container — the player's inventory, a chest, or a stack in flight over the network —
/// so the transfer rules can be written once without knowing where a slot lives.
///
/// Carrying <see cref="Uses"/> is what keeps a half-worn tool half-worn when it changes slot: writing
/// a slot back without it silently repairs the item to full.
/// </summary>
public struct SlotContent
{
public ItemData Item;
public int Quantity;
public int Uses;
/// <summary>
/// True when this snapshot holds nothing — no item, or a quantity that ran out.
/// </summary>
public bool IsEmpty => Item == null || Quantity <= 0;
/// <summary>
/// The empty snapshot, used to clear a slot.
/// </summary>
public static SlotContent Empty => new SlotContent { Item = null, Quantity = 0, Uses = -1 };
/// <summary>
/// Builds a snapshot, normalising the uses of an item that does not track them to -1.
/// </summary>
public static SlotContent Of(ItemData item, int quantity, int uses)
{
if (item == null || quantity <= 0) return Empty;
return new SlotContent
{
Item = item,
Quantity = quantity,
Uses = item.HasUses ? uses : -1
};
}
}
}