extends Path3D

var can_move: bool
@export var maxSpeed = 0.01

var pos = 0.0;
@onready var character_body_3d = $PathFollow3D/CharacterBody3D

@export var character_id: String

func _ready():
	DialogueManager.dialogue_finished.connect(_quit_dialogue)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	var previous_pos = pos;
	character_body_3d.moving = can_move
	if can_move and pos < 1:
		pos += maxSpeed * delta
	
	if previous_pos != pos:
		character_body_3d.animate_move()
	else:
		character_body_3d.animate_idle()
	
	$PathFollow3D.progress_ratio = clamp(pos, 0, 1)

func _quit_dialogue(_time_to_add: int):
	can_move = !character_id.is_empty() && DialogueManager.global_variables[character_id];
