extends Node

onready var mini_game = $MiniGame;

var dialogic_node: Control;

# Called when the node enters the scene tree for the first time.
func _ready():
	start_dialog('_start')


func _on_Dialogic_signal_received(value: String):
	print("signal received")
	var args = value.split(" ")
	if args.size() > 0:
		var type = args[0];
		match type:
			"start_minigame":
				start_minigame()
			"setup_minigame":
				if (args.size() >= 3):
					setup_minigame(args[1], args[2])
				else:
					print("not enough arguments for start_minigame")
			_:
				print("wrong type")


func close_dialog():
	dialogic_node.queue_free()

func start_dialog(timeline: String):
	dialogic_node = Dialogic.start(timeline)
	add_child_below_node(mini_game, dialogic_node)
	dialogic_node.connect('dialogic_signal', self, "_on_Dialogic_signal_received")



func setup_minigame(mode: String, next_timeline: String):
	mini_game.setup(mode, next_timeline)


func start_minigame():
	close_dialog()
	mini_game.start()


func _on_MiniGame_game_over(next_timeline: String):
	print("Game over received")
	print("next timeline: " + next_timeline)
	start_dialog(next_timeline)
