65 lines
2.3 KiB
GDScript
65 lines
2.3 KiB
GDScript
extends Node2D
|
|
|
|
@onready var parent_structure : Structure = get_parent()
|
|
@onready var inventory : BeltInventory = parent_structure.inventory
|
|
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
|
|
|
|
func _ready() -> void:
|
|
sync_animations.call_deferred()
|
|
|
|
func sync_animations() -> void:
|
|
animator.seek(BeltManager.sync_time,true)
|
|
|
|
func _draw() -> void:
|
|
for i in range(inventory.capacity):
|
|
if inventory.internal_array[i].amount > 0:
|
|
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
|
|
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position)
|
|
|
|
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,parent_structure.facing)) == false:
|
|
return
|
|
var popped = inventory.pop()
|
|
if popped == null:
|
|
return
|
|
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,parent_structure.facing))
|
|
|
|
func calculate_position(index: int) -> Vector2:
|
|
var indexed_part = 16.0 / inventory.capacity
|
|
match parent_structure.facing:
|
|
Structure.Facing.RIGHT:
|
|
return Vector2.LEFT*8 + Vector2.RIGHT * indexed_part * (index + inventory.progress_array[index])
|
|
Structure.Facing.DOWN:
|
|
return Vector2.UP*8 + Vector2.DOWN * indexed_part * (index + inventory.progress_array[index])
|
|
Structure.Facing.LEFT:
|
|
return Vector2.RIGHT*8 + Vector2.LEFT * indexed_part * (index + inventory.progress_array[index])
|
|
Structure.Facing.UP:
|
|
return Vector2.DOWN*8 + Vector2.UP * indexed_part * (index + inventory.progress_array[index])
|
|
return Vector2.ZERO
|
|
|
|
func get_next() -> Structure:
|
|
match parent_structure.facing:
|
|
Structure.Facing.RIGHT:
|
|
return parent_structure.get_relative(Vector2(1,0))
|
|
Structure.Facing.DOWN:
|
|
return parent_structure.get_relative(Vector2(0,1))
|
|
Structure.Facing.LEFT:
|
|
return parent_structure.get_relative(Vector2(-1,0))
|
|
Structure.Facing.UP:
|
|
return parent_structure.get_relative(Vector2(0,-1))
|
|
return null
|
|
|
|
func _on_conveyor_switched_facing(to: Structure.Facing) -> void:
|
|
match to:
|
|
Structure.Facing.RIGHT:
|
|
animator.play("right")
|
|
Structure.Facing.DOWN:
|
|
animator.play("down")
|
|
Structure.Facing.LEFT:
|
|
animator.play("left")
|
|
Structure.Facing.UP:
|
|
animator.play("up")
|
|
sync_animations()
|