Splitters part 1
This commit is contained in:
parent
39c52694da
commit
3c0777f4fd
9 changed files with 150 additions and 2 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
extends Inventory
|
||||
|
||||
class_name SplitterInventory
|
||||
|
||||
@export var capacity : int:
|
||||
set(value):
|
||||
if value < 0:
|
||||
|
@ -25,3 +27,48 @@ func deferred_init():
|
|||
for i in range(capacity):
|
||||
upper_array[i] = InventorySlot.new()
|
||||
down_array[i] = InventorySlot.new()
|
||||
|
||||
func add(stack : Stack, context: InventoryContext = null) -> Stack:
|
||||
if context == null:
|
||||
return stack
|
||||
if context.position == context.target.global_position:
|
||||
return add_to_array(stack,upper_array,context)
|
||||
return add_to_array(stack,down_array,context)
|
||||
|
||||
func add_to_array(stack: Stack, array: Array[InventorySlot], context: InventoryContext = null) -> Stack:
|
||||
for i in range(len(array)):
|
||||
if array[i].held_item == null or array[i].held_item == stack.held_item:
|
||||
stack_added.emit(stack,i)
|
||||
array[i].merge_stack(stack)
|
||||
if stack.is_valid() == false:
|
||||
return null
|
||||
return stack
|
||||
|
||||
func can_add(item : Item = null, context: InventoryContext = null) -> bool:
|
||||
if context == null:
|
||||
return false
|
||||
if item == null:
|
||||
for i in range(capacity):
|
||||
if upper_array[i].amount == 0 or down_array[i].amount == 0:
|
||||
return true
|
||||
else:
|
||||
for i in range(capacity):
|
||||
if upper_array[i].amount == 0:
|
||||
return upper_array[i].can_be_merged(item)
|
||||
if down_array[i].amount ==0:
|
||||
return down_array[i].can_be_merged(item)
|
||||
return false
|
||||
|
||||
func pop() -> Stack:
|
||||
return null
|
||||
|
||||
func peek() -> Stack:
|
||||
return null
|
||||
|
||||
## Tries to take certain item from inventory. Returns null if no item found
|
||||
func take(item : Item,amount: int) -> Stack:
|
||||
return null
|
||||
|
||||
## Finds first entry of item. Returns -1 if no item found
|
||||
func find(item : Item) -> int:
|
||||
return -1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue