Load balance
This commit is contained in:
parent
a26dd235a2
commit
788e42135f
3 changed files with 11 additions and 3 deletions
|
@ -11,6 +11,8 @@ func get_down_next() -> Vector2:
|
|||
return base + base.rotated(PI/2).abs()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if has_non_empty(inventory.upper_array) == false and has_non_empty(inventory.down_array) == false:
|
||||
return
|
||||
var transfer_upper = try_transfer(get_upper_next(),false)
|
||||
var transfer_down = try_transfer(get_down_next(),true)
|
||||
if transfer_upper or transfer_down or (not transfer_down and not transfer_upper):
|
||||
|
@ -18,9 +20,9 @@ func _process(_delta: float) -> void:
|
|||
|
||||
func try_transfer(point:Vector2,down:bool) -> bool:
|
||||
var next :Structure = structure_parent.get_relative(point)
|
||||
var array : Array[InventorySlot] = inventory.down_array if split != down else inventory.upper_array
|
||||
if next == null:
|
||||
return false
|
||||
var array : Array[InventorySlot] = inventory.down_array if split != down else inventory.upper_array
|
||||
var context : InventoryContext = InventoryContext.new(structure_parent,next,to_global(point))
|
||||
for i in range(inventory.capacity):
|
||||
if array[i].amount > 0 and next.inventory.can_add(array[i].held_item,context):
|
||||
|
@ -30,3 +32,9 @@ func try_transfer(point:Vector2,down:bool) -> bool:
|
|||
|
||||
return true
|
||||
return false
|
||||
|
||||
func has_non_empty(array:Array[InventorySlot]) -> bool:
|
||||
for i in range(inventory.capacity):
|
||||
if array[i].amount > 0:
|
||||
return true
|
||||
return false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue