extends "res://SetPiece_.gd"
class_name TransitionPiece

@export var appear_at_node: String 
@export_file("*.tscn") var target
#@export var priority: int = 100
# Called when the node enters the scene tree for the first time.
func _ready():
	priority = 100
	super()




func default_script(scene: Scene):
	var path = NavigationServer2D.map_get_path(scene.map, scene.pathfind.to_local(scene.ego.global_position), scene.pathfind.to_local($"exit".global_position), true)
	scene.start_main_script(scene.ScriptBuilder.init(scene.ScriptBuilder.walk_path(scene.ego, path))
	.and_then(scene.ScriptBuilder.transition(scene, load(target), appear_at_node + "/exit"))
	.and_then(scene.ScriptBuilder.walk_to_deferred(appear_at_node + "/exit", appear_at_node + "/entrance"))
	.can_interrupt().build(scene, "_on_script_complete"))
