delurbelako/scripts/inventory/inventory.gd
2025-10-17 18:22:49 +05:00

41 lines
1,005 B
GDScript

@abstract
extends Resource
## Class that can hold items in it
class_name Inventory
signal stack_added(item : Stack,position : int)
signal stack_taken(item : Stack,position : int)
func _init() -> void:
resource_local_to_scene = true
## Tries to add an item into inventory. Returns not stored stack of item.
@abstract
func add(stack : Stack, context: InventoryContext = null) -> Stack
## Returns if conditions of adding are met
@abstract
func can_add(item : Item = null, context: InventoryContext = null) -> bool
## Tries to take first item. Returns null if no items in inventory
@abstract
func pop() -> Stack
@abstract
func peek() -> Stack
## Tries to take certain item from inventory. Returns null if no item found
@abstract
func take(item : Item,amount: int) -> Stack
## Finds first entry of item. Returns -1 if no item found
@abstract
func find(item : Item) -> int
@abstract
func refresh() -> void
## Does inventory have certain item?
func has(item : Item) -> bool:
return find(item) != -1