#nullable enable using Babushka.scripts.CSharp.GameEntity.LoadSave; using Newtonsoft.Json.Linq; namespace Babushka.scripts.CSharp.Common.Inventory; /// /// Represents a virtual object wrapper for an item instance. /// Can return the containing item or null. /// public class InventorySlot: IJsonSerializable { /// /// The inventory item instance that may or may not be bound to this slot. /// public ItemInstance? itemInstance; /// /// Whether or not this slot is currently occupied by an item instance. /// /// public bool IsEmpty() { return itemInstance == null; } public void LoadFromJson(JObject json) { var itemJson = json.Value("item"); if (itemJson != null) { itemInstance = new ItemInstance(); itemInstance.LoadFromJson(itemJson); } else { itemInstance = null; } } public JObject SaveToJson() { return new JObject() { ["item"] = itemInstance?.SaveToJson() }; } }