Class InventorySection
ISaveSection holding the player's inventory: a list of item entries, each with
an id, a quantity, and an optional project-defined JSON escape hatch.
Inheritance
InventorySection
Assembly: Serenity.GameSave.Domain.dll
Syntax
public sealed class InventorySection : ISaveSection
Constructors
InventorySection()
Declaration
public InventorySection()
Fields
KEY
The section key this section is stored under.
Declaration
public const string KEY = "inventory"
Field Value
Properties
Entries
Every inventory entry, in insertion order.
Declaration
public IReadOnlyList<InventorySection.InventoryEntry> Entries { get; }
Property Value
SectionKey
The stable key this section is stored under within a SaveDocument.
Declaration
public string SectionKey { get; }
Property Value
Methods
AddItem(string, int, string)
Adds quantity of itemId. If the item is already
present, its quantity accumulates and its customJson replaces the
stored one when non-null; otherwise a new entry is appended.
Declaration
public void AddItem(string itemId, int quantity, string customJson = null)
Parameters
Exceptions
Deserialize(string)
Restores every entry from payload. itemId and quantity
are required per entry — a payload missing either is not a valid inventory entry and
fails the whole load. customJson is treated as OPTIONAL (looked up via the item's
property map rather than GetProperty(string)) so an older or hand-edited
save written before this field existed still loads, defaulting the field to null
instead of failing.
Declaration
public void Deserialize(string payload)
Parameters
| Type |
Name |
Description |
| string |
payload |
|
GetQuantity(string)
Gets the quantity held of itemId, or zero when absent.
Declaration
public int GetQuantity(string itemId)
Parameters
| Type |
Name |
Description |
| string |
itemId |
|
Returns
HasItem(string)
Checks whether at least one unit of itemId is held.
Declaration
public bool HasItem(string itemId)
Parameters
| Type |
Name |
Description |
| string |
itemId |
|
Returns
RemoveItem(string, int)
Removes quantity of itemId, dropping the entry
entirely once its remaining quantity reaches zero or below. A missing item is a no-op.
Declaration
public void RemoveItem(string itemId, int quantity)
Parameters
| Type |
Name |
Description |
| string |
itemId |
|
| int |
quantity |
|
Serialize()
Serializes this section's current state to JSON.
Declaration
public string Serialize()
Returns
Implements