Load balance
This commit is contained in:
parent
a26dd235a2
commit
788e42135f
3 changed files with 11 additions and 3 deletions
|
@ -12,6 +12,7 @@
|
|||
resource_local_to_scene = true
|
||||
script = ExtResource("3_ruvuk")
|
||||
capacity = 4
|
||||
progress_speed = 10.0
|
||||
pop_treshold = 0.95
|
||||
internal_array = Array[ExtResource("2_54w8r")]([Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||
|
@ -79,7 +80,6 @@ _data = {
|
|||
[node name="Conveyor" type="Node2D" groups=["buildings"]]
|
||||
script = ExtResource("1_y326v")
|
||||
inventory = SubResource("Resource_t4je2")
|
||||
direction = null
|
||||
maximum_directions = 4
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." node_paths=PackedStringArray("structure")]
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[sub_resource type="Resource" id="Resource_iov8t"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("3_2ulpw")
|
||||
capacity = 4
|
||||
capacity = 1
|
||||
metadata/_custom_type_script = "uid://dlt3mbu6hk572"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0dkfh"]
|
||||
|
|
|
@ -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