Inventory
namespace Griff.Scenes;
public sealed class Inventory : Component, IHoldsItemsWhat an entity is carrying: keys, potions, the parts of a machine, gold, blocks. A Pickup with an Item puts things in the inventory of whoever collects it (adding one if they don’t have one); locked Doors and Switches use up its keys. A Counter with an Item shows how many there are. Items are the one idea every genre shares (see Items): what a recipe takes, a strategy unit or a card costs or a shop’s pickup sells for is paid from it, and with ForTeam it holds a whole team’s.
It’s saved with the scene, so it rewinds with everything else and you can start a playtest holding a key; with SaveAs it’s kept in the save data too, from one run (and one scene) to the next.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Contents
Section titled “Contents”public IReadOnlyList<ValueTuple<string, int>> Contents { get; }Everything it holds and how many, in the order each was first added.
ForTeam
Section titled “ForTeam”public string? ForTeam { get; set; }Holds a team’s items, e.g. “Player”: anything on that team (see Teams) without an inventory of its own collects into it and pays from it, so a platformer hero’s coins buy a strategy army or pay for cards. Empty holds only its own entity’s.
public IReadOnlyList<ValueTuple<string, int>> Held { get; }What it holds, without a copy, for what reads it every frame (see Version); don’t keep it.
ItemUses
Section titled “ItemUses”public IReadOnlyList<string> ItemUses { get; set; }What its items do when they’re used, one per line: the item, a colon, and what it does, several separated by commas: “heal 3” gives back hit points, “spawn Explosion” spawns a prefab where it stands, “send Teleport” sends a message (with this entity as its data). E.g. “Potion: heal 3”, “Bomb: spawn Explosion, send Boom”. Using one takes it out; a potion that only heals isn’t used up at full health.
public IReadOnlyList<string> Items { get; set; }What it holds, one kind per row: a name and how many, e.g. “Key 2” (just “Key” is one).
Loaded
Section titled “Loaded”public bool Loaded { get; set; }Set by the game once it has taken what it holds from the save data, so a rewind doesn’t do it again. Leave it be.
NumberKeys
Section titled “NumberKeys”public bool NumberKeys { get; set; }The number keys use what it holds: 1 the first item it has with a use (in the order it got them), 2 the second, up to 9.
SaveAs
Section titled “SaveAs”public string? SaveAs { get; set; }Keeps what it holds in the game’s save data under this name, e.g. “Items”, so it’s still there the next time the game runs, and an inventory saved as the same name in the next scene starts with it (a player walking from room to room). Empty keeps nothing. Game → Clear Save Data forgets it while you test.
Usable
Section titled “Usable”public IReadOnlyList<string> Usable { get; }The items it holds that have a use (see ItemUses), in the order it got them: what the number keys use.
UseSound
Section titled “UseSound”public string? UseSound { get; set; }A sound played as an item is used, e.g. “Sounds/drink.wav”.
Version
Section titled “Version”public int Version { get; }A number that goes up whenever what it holds changes, so what shows it redraws only then.
Methods
Section titled “Methods”public void Add(string item, int count = 1)Puts count of item in.
AddItems
Section titled “AddItems”public void AddItems(string items)Puts in the items listed, e.g. “Gold 50, Key”: something won, bought or found.
public void Clear()Empties it.
public int Count(string item)How many of item it holds (names ignore case). Read as “Count:Key”.
EffectsOf
Section titled “EffectsOf”public IReadOnlyList<ValueTuple<string, string>> EffectsOf(string item)What item does when used, as ItemUses says: each a verb (“heal”, “spawn”, “send”) and what it takes.
public bool Has(string item, int count = 1)True if it holds at least count of item.
public bool Take(string item, int count = 1)Takes count of item out, if it has that many; returns whether it did.
TakeItems
Section titled “TakeItems”public void TakeItems(string items)Takes out the items listed, e.g. “Gold 50”, if it holds them all; otherwise takes nothing.
public void Use(string item)Uses one item at the start of the next frame, as its number key does: on its turn, if it holds one.
public override bool Uses(string property)Events
Section titled “Events”Changed
Section titled “Changed”public event Action<string>? ChangedRaised when what it holds changes, with the item’s name.
public event Action<string>? UsedRaised as an item is used, with its name.