Skip to content

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 ​

CombatManagercombat_manager
ItemInstancebag_itemnull
InventoryComponentinventorynull
InventorySlotInstancecovered_bynull

Methods ​

boolsupports_stacking()
boolaccepts_definition( definition: ItemDefinition )
boolis_special_for( definition: ItemDefinition )
boolcan_accept_item( item: ItemInstance )
intadd_quantity( amount: int )
intremove_quantity( amount: int )
boolcan_merge_with( other_slot: InventorySlotInstance )
boolcan_fully_merge_with( other_slot: InventorySlotInstance )
InventorySlotInstancemerge_with( other_slot: InventorySlotInstance )
InventorySlotInstancesplit_stack( amount_to_split: int )
Array[InventorySlotInstance]split_evenly( number_of_stacks: int )
inttransfer_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