Inventory Types - coldrockgames/gml-raptor GitHub Wiki
The system provides multiple inventory implementations, each tailored to a specific use case in games. All of them inherit from the base _Inventory
class and extend or specialize its behavior.
List Inventory
Description:
A straightforward list-based inventory. Items are stored in a simple array, appended to the end when added.
Use Cases:
- RPGs or action games where inventory is just a bag/pouch without positional logic.
- Quick prototyping of item systems.
Key Features:
- Fixed or endless size depending on constructor arguments.
- Items can be stacked if allowed by
stack_size
. - Ideal for minimal overhead when you don’t need grid or slot mechanics.
Example:
var bag = new ListInventory(20, -1, 10); // 20 slots, unlimited weight, stack size of 10
bag.add_item(new InventoryItem("Potion", 5));
bag.add_item(new InventoryItem("Arrow", 30));
Grid Inventory
Description:
A two-dimensional inventory represented as a grid. Empty slots are explicitly undefined
. Positions are accessed via (x, y)
coordinates.
Use Cases:
- Survival games, RPGs, or tactical systems where items are placed in grid slots.
- UIs resembling classic grid-based systems (like Diablo or Minecraft).
Key Features:
- Defines grid dimensions (
x
andy
). - Items are stored in row-major order.
- Retrieves items by
(x, y)
position. - Handles inserting and removing items while maintaining empty slots.
- Tracks filled vs. empty slots explicitly.
Example:
var chest = new GridInventory(4, 4, 200, 5); // 4x4 grid, 200 max weight, stack size 5
var sword = new InventoryItem("Iron Sword", 1, 10);
chest.add_item(sword);
var item_at_0_0 = chest.get_item(0, 0); // Retrieves Iron Sword if placed at slot (0,0)
Slot Inventory
Description:
An inventory built around named slots. Each slot can hold a single item and is often tied to a character’s equipment (like head, chest, hands).
Use Cases:
- Character equipment systems (gear, weapons, armor).
- Crafting systems where specific slots matter.
- Loadouts with strict placement rules.
Key Features:
- Slots are instances of
InventorySlot
with properties likename
. - Provides
find_slot_by_name
for easy lookup. - Provides
add_or_swap_item_to_slot
to equip items or swap them with existing ones. - Stack size is always
1
since equipment slots usually hold only one item.
Example:
var equipment = new SlotInventory(3, -1, [
new InventorySlot("Head"),
new InventorySlot("Body"),
new InventorySlot("Weapon")
]);
var helmet = new InventoryItem("Iron Helmet", 1, 5);
equipment.add_or_swap_item_to_slot(helmet, "Head");
Choosing the Right Inventory Type
- Use
ListInventory
when you just need a bag/box-like system. - Use
GridInventory
when items are visually managed in a grid. - Use
SlotInventory
when items correspond to fixed roles or equipment positions.