class

PointClickEngine::Inventory::InventorySystem

Inherits PointClickEngine::Core::Drawable < YAML::Serializable < Reference < Object

Manages the player's inventory of items and item interactions

The InventorySystem provides a visual grid-based interface for managing collected items, supports item combination mechanics, and handles item usage on scene objects. Items can be selected, combined with other items, or used on hotspots and characters in the game world.

Key Features

  • Grid-based visual inventory display
  • Item selection and combination system
  • Drag-and-drop style interactions
  • Item usage callbacks for scene integration
  • Automatic item icon rendering
  • YAML serialization for save/load functionality

Usage Example

inventory = InventorySystem.new(Vector2.new(10, 10))
inventory.add_item(key_item)
inventory.add_item(potion_item)

inventory.on_item_used = ->(item : InventoryItem, target : String) {
  handle_item_usage(item, target)
}

inventory.on_items_combined = ->(item1, item2, action) {
  create_combined_item(item1, item2, action)
}

NOTE: The inventory automatically handles screen coordinate conversion when used with the display manager.

Constructors

new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
Source
new(position : RL::Vector2 = RL::Vector2.new(x: 10, y: 10))

Creates an inventory system at the specified position

  • position : Screen position for the inventory panel (default: 10,10)
Source
new(*, __context_for_yaml_serializable ctx : YAML::ParseContext, __node_for_yaml_serializable node : YAML::Nodes::Node)
Source

Instance methods

add_item(item : InventoryItem)

Adds an item to the inventory

Prevents duplicate items with the same name from being added. If an item with the same name already exists, it won't be added again.

  • item : The inventory item to add
Source
after_yaml_deserialize(ctx : YAML::ParseContext)

Restores runtime state after YAML deserialization

Restores item state and reconnects the selected item reference.

  • ctx : YAML parsing context
Source
background_color

Background color for the inventory panel (runtime only)

Source
background_color=(background_color : RL::Color)

Background color for the inventory panel (runtime only)

Source
clear

Clears all items from the inventory

Removes all items, deselects any selected item, and exits combination mode.

Source
combination_mode

Whether the system is in combination mode (runtime only)

Source
combination_mode=(combination_mode : Bool)

Whether the system is in combination mode (runtime only)

Source
deselect_item

Deselects the currently selected item

Also exits combination mode if active.

Source
draw

Renders the inventory panel and all contained items

Draws the background panel, item slots, icons or names, selection highlights, and combination mode indicators.

Source
event_bus

Optional EventBus for publishing inventory events

Source
event_bus=(event_bus : Core::Events::EventBus | Nil)

Optional EventBus for publishing inventory events

Source
get_item(name : String) : InventoryItem | Nil

Gets an item from the inventory by name

  • name : Name of the item to retrieve

Returns: The inventory item, or nil if not found

Source
get_item_at_position(pos : RL::Vector2) : InventoryItem | Nil

Gets the item at a specific screen position

Used for mouse interaction to determine which item was clicked. Only works when the inventory is visible.

  • pos : Screen position to check

Returns: The item at that position, or nil if none found

Source
has_item?(name : String) : Bool

Checks if an item with the specified name exists in the inventory

  • name : Name of the item to check for

Returns: true if the item exists, false otherwise

Source
items

Collection of items currently in the inventory

Source
items=(items : Array(InventoryItem))

Collection of items currently in the inventory

Source
on_item_used

Callback for when an item is used on a target (runtime only)

Source
on_item_used=(on_item_used : Proc(InventoryItem, String, Nil) | Nil)

Callback for when an item is used on a target (runtime only)

Source
on_items_combined

Callback for when two items are combined (runtime only)

Source
on_items_combined=(on_items_combined : Proc(InventoryItem, InventoryItem, String | Nil, Nil) | Nil)

Callback for when two items are combined (runtime only)

Source
padding

Padding between inventory slots in pixels

Source
padding=(padding : Float32)

Padding between inventory slots in pixels

Source
remove_item(item_name : String)

Removes an item from the inventory by name

If the removed item was selected, it will be deselected.

  • item_name : Name of the item to remove
Source
remove_item(item : InventoryItem)

Removes an item from the inventory

  • item : The inventory item to remove
Source
select_item(name : String)

Selects an item by name

The selected item will be highlighted and available for use or combination.

  • name : Name of the item to select
Source
selected_item

Reference to currently selected item (runtime only)

Source
selected_item=(selected_item : InventoryItem | Nil)

Reference to currently selected item (runtime only)

Source
selected_item_name

Name of currently selected item for serialization

Source
selected_item_name=(selected_item_name : String | Nil)

Name of currently selected item for serialization

Source
slot_size

Size of each inventory slot in pixels

Source
slot_size=(slot_size : Float32)

Size of each inventory slot in pixels

Source
start_combination_mode

Enters combination mode for the selected item

Only works if an item is currently selected. In combination mode, clicking another item will attempt to combine them.

Source
update(dt : Float32)

Updates inventory interaction and input handling

Processes mouse clicks on inventory items, handles selection and combination mode, and manages coordinate conversion for proper display scaling.

  • dt : Delta time in seconds since last update
Source
use_selected_item_on(target_name : String)

Uses the selected item on a target object

Checks if the selected item can be used on the specified target, then executes the usage callback. Removes consumable items after use.

  • target_name : Name of the target object/character/hotspot
Source