InventorySlotInstance ​
Inherits: SlotInstance < RefCounted
Inherited by: KeptAsideSlotInstance
Inventory slot with full stacking support and item management
Description ​
Provides advanced stacking capabilities including:
- Merging compatible item stacks
- Splitting stacks into multiple slots
- Adding/removing specific quantities
- Validation for stackable items
Used by InventoryComponent for general item storage where multiple items of the same type can be stacked together.
Variables ​
CombatManager | combat_manager | |
ItemInstance | bag_item | null |
InventoryComponent | inventory | null |
InventorySlotInstance | covered_by | null |
Methods ​
bool | supports_stacking() |
bool | accepts_definition( definition: ItemDefinition ) |
bool | is_special_for( definition: ItemDefinition ) |
bool | can_accept_item( item: ItemInstance ) |
int | add_quantity( amount: int ) |
int | remove_quantity( amount: int ) |
bool | can_merge_with( other_slot: InventorySlotInstance ) |
bool | can_fully_merge_with( other_slot: InventorySlotInstance ) |
InventorySlotInstance | merge_with( other_slot: InventorySlotInstance ) |
InventorySlotInstance | split_stack( amount_to_split: int ) |
Array[InventorySlotInstance] | split_evenly( number_of_stacks: int ) |
int | transfer_to( target_slot: InventorySlotInstance, amount: int = -1 ) |
Signals ​
quantity_removed( item_instance: ItemInstance, amount: int ) ​
Emitted when the stack of the item in this slot got smaller without the inventory asking for it (an item that was used or consumed)
Variable descriptions ​
CombatManager combat_manager ​
The combat system manager
ItemInstance bag_item = null ​
The bag that gave this slot (null = a slot of the character's own bag)
InventoryComponent inventory = null ​
The inventory this slot is in (a grid needs it to ask whether an item fits where it is dropped)
InventorySlotInstance covered_by = null ​
Grid: the slot that holds the item that covers this cell (null = this cell is free, or it is the cell of its own item)
Method descriptions ​
bool supports_stacking() ​
Inventory slots always support stacking
bool accepts_definition( definition: ItemDefinition ) ​
Does this slot take an item of this definition? A slot of a bag that takes only some groups refuses the others
bool is_special_for( definition: ItemDefinition ) ​
Does this slot belong to a bag that takes only some items (and does this definition fit it)?
bool can_accept_item( item: ItemInstance ) ​
Check if this slot can accept a specific item instance
int add_quantity( amount: int ) ​
Add quantity to this slot's stack Returns the amount that couldn't be added (overflow)
int remove_quantity( amount: int ) ​
Remove quantity from this slot's stack Returns the amount that was actually removed
bool can_merge_with( other_slot: InventorySlotInstance ) ​
Check if this slot can merge with another slot
bool can_fully_merge_with( other_slot: InventorySlotInstance ) ​
Check if this slot can fully absorb another slot's contents
InventorySlotInstance merge_with( other_slot: InventorySlotInstance ) ​
Merge another slot's contents into this slot Returns null if fully merged, or the other slot with remaining items
InventorySlotInstance split_stack( amount_to_split: int ) ​
Split this slot's stack, creating a new slot with the specified amount Returns a new InventorySlotInstance or null if split failed
Array[InventorySlotInstance] split_evenly( number_of_stacks: int ) ​
Split this slot evenly into multiple stacks Returns array of new slots (excluding this one which retains remainder)
int transfer_to( target_slot: InventorySlotInstance, amount: int = -1 ) ​
Try to transfer items to another slot Returns the amount that couldn't be transferred