Conveyor
This commit is contained in:
parent
cb9aef6761
commit
222960a824
19 changed files with 282 additions and 22 deletions
|
@ -13,15 +13,18 @@ class_name Storage
|
|||
if value == capacity:
|
||||
return
|
||||
capacity = value
|
||||
internal_array.resize(capacity)
|
||||
for i in range(capacity):
|
||||
internal_array[i] = InventorySlot.new()
|
||||
get:
|
||||
return capacity
|
||||
|
||||
## :3
|
||||
@export_storage var internal_array : Array[InventorySlot] = []
|
||||
|
||||
func _init() -> void:
|
||||
super()
|
||||
internal_array.resize(capacity)
|
||||
for i in range(capacity):
|
||||
internal_array[i] = InventorySlot.new()
|
||||
|
||||
## Finds first entry of item. Returns -1 if no item found
|
||||
func find(item : Item) -> int:
|
||||
for i in range(len(internal_array)):
|
||||
|
@ -33,21 +36,31 @@ func find(item : Item) -> int:
|
|||
func add(stack: Stack) -> Stack:
|
||||
var found_index : int = find(stack.held_item)
|
||||
if found_index != -1:
|
||||
stack_added.emit(stack,found_index)
|
||||
stack = internal_array[found_index].merge_stack(stack)
|
||||
if stack == null:
|
||||
return null
|
||||
for i in range(len(internal_array)):
|
||||
if internal_array[i].held_item == null or internal_array[i].held_item == stack.held_item:
|
||||
stack_added.emit(stack,i)
|
||||
stack = internal_array[i].merge_stack(stack)
|
||||
if stack == null:
|
||||
return null
|
||||
return stack
|
||||
|
||||
func can_add() -> bool:
|
||||
for i in range(capacity):
|
||||
if internal_array[i].amount == 0:
|
||||
return true
|
||||
return false
|
||||
|
||||
## 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()
|
||||
var extracted = internal_array[i].extract()
|
||||
stack_taken.emit(extracted,i)
|
||||
return extracted
|
||||
return null
|
||||
|
||||
## Tries to take certain item from inventory. Returns null if no item found
|
||||
|
@ -55,4 +68,6 @@ func take(item: Item,amount: int) -> Stack:
|
|||
var found = find(item)
|
||||
if found == -1:
|
||||
return null
|
||||
return internal_array[found].extract_stack(amount)
|
||||
var extracted = internal_array[found].extract_stack(amount)
|
||||
stack_taken.emit(extracted,found)
|
||||
return extracted
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue