Stack rework
This commit is contained in:
parent
5da9e11f36
commit
ea9c41054b
7 changed files with 60 additions and 39 deletions
|
@ -19,12 +19,7 @@ func _process(delta: float) -> void:
|
|||
inventory.advance(delta)
|
||||
queue_redraw()
|
||||
var next : Structure = get_next()
|
||||
if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,structure_parent.facing),inventory.internal_array[inventory.capacity-1].held_item) == false:
|
||||
return
|
||||
var popped = inventory.pop()
|
||||
if popped == null:
|
||||
return
|
||||
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,structure_parent.facing))
|
||||
try_transfer(next)
|
||||
|
||||
func calculate_position(index: int) -> Vector2:
|
||||
var indexed_part = 16.0 / inventory.capacity
|
||||
|
@ -43,6 +38,18 @@ func get_next() -> Structure:
|
|||
var faced_vector = Structure.facing_to_vector(structure_parent.facing)
|
||||
return structure_parent.get_relative(faced_vector)
|
||||
|
||||
func try_transfer(structure : Structure) -> void:
|
||||
if structure == null or inventory.internal_array[inventory.capacity-1].amount == 0:
|
||||
return
|
||||
var last_slot = inventory.internal_array[inventory.capacity-1]
|
||||
var ang_diff = Globals.facing_difference(structure_parent.facing,structure.facing)
|
||||
if structure.inventory.can_add_from_side(ang_diff,last_slot.held_item) == false:
|
||||
return
|
||||
last_slot.merge_stack(structure.inventory.add_from_side(last_slot.extract(),ang_diff))
|
||||
|
||||
if last_slot.amount == 0:
|
||||
inventory.sort()
|
||||
|
||||
func _on_conveyor_switched_facing(to: Structure.Facing) -> void:
|
||||
match to:
|
||||
Structure.Facing.RIGHT:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue