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
Creates an inventory system at the specified position
- position : Screen position for the inventory panel (default: 10,10)
Instance methods
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
Restores runtime state after YAML deserialization
Restores item state and reconnects the selected item reference.
- ctx : YAML parsing context
Background color for the inventory panel (runtime only)
Clears all items from the inventory
Removes all items, deselects any selected item, and exits combination mode.
Whether the system is in combination mode (runtime only)
Renders the inventory panel and all contained items
Draws the background panel, item slots, icons or names, selection highlights, and combination mode indicators.
Optional EventBus for publishing inventory events
Gets an item from the inventory by name
- name : Name of the item to retrieve
Returns: The inventory item, or nil if not found
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
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
Callback for when an item is used on a target (runtime only)
Callback for when two items are combined (runtime only)
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
Removes an item from the inventory
- item : The inventory item to remove
Selects an item by name
The selected item will be highlighted and available for use or combination.
- name : Name of the item to select
Reference to currently selected item (runtime only)
Name of currently selected item for serialization
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.
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
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