47 lines
1.2 KiB
GDScript
47 lines
1.2 KiB
GDScript
extends Machine
|
|
|
|
@export var separation: float = 16.0;
|
|
|
|
func _ready() -> void:
|
|
remove_accepted_item_nodes = false
|
|
|
|
func set_start(node: Machine):
|
|
global_position = node.global_position
|
|
add_source(node)
|
|
#$Line.points = [Vector2(0,0)]
|
|
$Line.belt_stopped = true
|
|
#node.connect("item_available", accept_item)
|
|
|
|
func add_point(point: Vector2):
|
|
$Line.points.append(to_local(point))
|
|
|
|
func set_end(node: Machine):
|
|
$Line.points[1] = to_local(node.global_position)
|
|
#$Line.points.append(to_local(node.global_position))
|
|
$Line.calculate_length()
|
|
add_sink(node)
|
|
$Line.belt_stopped = false
|
|
#connect("item_available", node.accept_item)
|
|
|
|
func can_accept_item(item: Item) -> bool:
|
|
return super(item) \
|
|
and !$Line.belt_stopped \
|
|
and $Line.get_first_object_progress() >= separation
|
|
|
|
func offer_item(node: ItemNode) -> bool:
|
|
if $Line.belt_stopped:
|
|
return false
|
|
var ok: bool = super(node)
|
|
if ok:
|
|
$Line.add_transported_object(node)
|
|
return ok
|
|
|
|
func _on_line_node_at_end(node: Node) -> void:
|
|
if node is ItemNode:
|
|
if can_send_item(node.item_type):
|
|
fetch_item_from_storage(node.item_type, 1)
|
|
var sent: bool = send_item(node)
|
|
if sent:
|
|
$Line.remove_transported_object(node)
|
|
|