Craft
This commit is contained in:
parent
3af13d0a8b
commit
5da9e11f36
5 changed files with 48 additions and 26 deletions
|
@ -7,15 +7,13 @@ class_name InOutInventory
|
|||
@export var output_capacity : int
|
||||
|
||||
@export_storage var input_array : Array[InventorySlot]
|
||||
@export_storage var output_array : Array[InventorySlot]
|
||||
@export_storage var output_slot : InventorySlot
|
||||
|
||||
func resize() -> void:
|
||||
input_array.resize(input_capacity)
|
||||
output_array.resize(output_capacity)
|
||||
for i in range(input_capacity):
|
||||
input_array[i] = InventorySlot.new()
|
||||
for i in range(output_capacity):
|
||||
output_array[i] = InventorySlot.new()
|
||||
output_slot = InventorySlot.new()
|
||||
|
||||
func _init() -> void:
|
||||
super()
|
||||
|
@ -46,9 +44,7 @@ func can_add(item : Item = null) -> bool:
|
|||
return false
|
||||
else:
|
||||
for i in range(input_capacity):
|
||||
print(input_array[i].filter)
|
||||
if input_array[i].can_be_merged(item):
|
||||
print(input_array[i].filter)
|
||||
return true
|
||||
#return true
|
||||
return false
|
||||
|
@ -58,27 +54,21 @@ func can_add_from_side(_ang_diff : float,item: Item = null) -> bool:
|
|||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
func pop() -> Stack:
|
||||
for i in range(output_capacity):
|
||||
if output_array[i].held_item != null:
|
||||
var extracted = output_array[i].extract()
|
||||
stack_taken.emit(extracted,i)
|
||||
return extracted
|
||||
if output_slot.held_item != null:
|
||||
var extracted = output_slot.extract()
|
||||
stack_taken.emit(extracted,0)
|
||||
return extracted
|
||||
return null
|
||||
|
||||
func peek() -> Stack:
|
||||
for i in range(output_capacity):
|
||||
if output_array[i].held_item != null:
|
||||
var peeked = output_array[i].as_stack()
|
||||
return peeked
|
||||
if output_slot.held_item != null:
|
||||
var peeked = output_slot.as_stack()
|
||||
return peeked
|
||||
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:
|
||||
return null
|
||||
var extracted = output_array[found].extract_stack(amount)
|
||||
stack_taken.emit(extracted,found)
|
||||
var extracted = output_slot.extract_stack(amount)
|
||||
return extracted
|
||||
|
||||
func find_input(item : Item) -> int:
|
||||
|
@ -88,7 +78,6 @@ func find_input(item : Item) -> int:
|
|||
return -1
|
||||
|
||||
func find(item : Item) -> int:
|
||||
for i in range(output_capacity):
|
||||
if output_array[i].held_item == item:
|
||||
return i
|
||||
if output_slot.held_item == item:
|
||||
return 0
|
||||
return -1
|
||||
|
|
|
@ -72,6 +72,8 @@ func can_be_merged(item : Item) -> bool:
|
|||
|
||||
## Add provided stack's amount to this amount. Returns null if stack is empty or items arent matching
|
||||
func merge_stack(stack: Stack) -> Stack:
|
||||
if stack == null or stack.held_item == null or stack.amount == 0:
|
||||
return stack
|
||||
if held_item == null:
|
||||
if filter != null and filter.is_equal(stack.held_item) == false:
|
||||
return stack
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue