extends Area2D

const DIALOGO=preload("res://dialogues/dialogo_enemigo.dialogue")
@export var start_key: String = "start"
@export var one_shot: bool = true

var _triggered := false

func _ready() -> void:
	body_entered.connect(_on_body_entered)

func _on_body_entered(body: Node) -> void:
	print("entered:", body, " type:", body.get_class(), " groups:", body.get_groups())

	if _triggered and one_shot:
		return
	if Game.is_dialogue_active:
		return
	if not body.is_in_group("Player"):
		return
	if DIALOGO == null:
		push_warning("DialogueTrigger: dialogue_resource not set.")
		return

	_triggered = true
	Game.is_dialogue_active = true
	DialogueManager.show_dialogue_balloon(DIALOGO, "start")
	DialogueManager.dialogue_ended.connect(_on_dialogue_ended)
	
func _on_dialogue_ended(dialogue):
	$"../../Fade_transitions".show()
	$"../../Fade_transitions/FadeTimer".start()
	$"../../Fade_transitions"/AnimationPlayer.play("Fade_out")
	get_tree().change_scene_to_file("res://main_menu.tscn")
