extends Area2D

export var vanish_on_interaction := false


var game_data

func _ready():
	game_data = get_tree().get_root().find_node("GameData", true, false)
	assert(game_data)
	



func start_interaction() -> void:
	# Pauses the game and play each action under the $Actions node
	# Actions that transition to another scene (e.g. StartCombatAction) may unpause
	# the game themselves
	# PawnInteractive processes even when the game is paused, but not
	# PawnLeader, the player-controlled pawn
	get_tree().paused = true
	var actions = $Actions.get_children()


	# An interactive pawn should have some interaction

	assert(actions != [])
	for action in actions:
		action.interact()
		yield(action, "finished")
	emit_signal("interaction_finished", self)
	if vanish_on_interaction:
		queue_free()
	get_tree().paused = false
	game_data.add("DialogueTester_interacted")


func _on_DialogueTester_body_entered(body):
	start_interaction()
