Documentation
This commit is contained in:
parent
66a623e568
commit
23b6e5d180
5 changed files with 34 additions and 0 deletions
|
@ -1,8 +1,11 @@
|
|||
@tool
|
||||
extends Inventory
|
||||
|
||||
## Base class for simple storages with no differentiation.
|
||||
|
||||
class_name Storage
|
||||
|
||||
## Amount of stacks that can be held in storage
|
||||
@export var capacity : int:
|
||||
set(value):
|
||||
if value < 0:
|
||||
|
@ -16,14 +19,17 @@ class_name Storage
|
|||
get:
|
||||
return capacity
|
||||
|
||||
## :3
|
||||
@export_storage var internal_array : Array[InventorySlot] = []
|
||||
|
||||
## Finds first entry of item. Returns -1 if no item found
|
||||
func find(item : Item) -> int:
|
||||
for i in range(len(internal_array)):
|
||||
if internal_array[i].held_item == item:
|
||||
return i
|
||||
return -1
|
||||
|
||||
## Tries to add an item into inventory. Returns not stored stack of item.
|
||||
func add(stack: Stack) -> Stack:
|
||||
var found_index : int = find(stack.held_item)
|
||||
if found_index != -1:
|
||||
|
@ -37,12 +43,14 @@ func add(stack: Stack) -> Stack:
|
|||
return null
|
||||
return stack
|
||||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
func pop() -> Stack:
|
||||
for i in range(len(internal_array)):
|
||||
if internal_array[i].held_item != null:
|
||||
return internal_array[i].extract()
|
||||
return null
|
||||
|
||||
## Tries to take certain item from inventory. Returns null if no item found
|
||||
func take(item: Item,amount: int) -> Stack:
|
||||
var found = find(item)
|
||||
if found == -1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue