extends Control

var room = preload("res://Kamer.tscn").instantiate()
var opacity_dragon = 1.0
var opacity_panel = 1.0
var fadeout = false
var start = false
@onready var anim = $Draakje

func _ready():
	get_tree().get_root().print_tree()
	anim.play("default")
	$Draakje/Hoest.playing = true
	var size = get_viewport_rect().size
	anim.position = Vector2(size.x/2, size.y/2 - 100)
	
func _process(delta):
	if fadeout:
		opacity_dragon = max(0.0, opacity_dragon - delta * 2.0)
		anim.material.set_shader_parameter("opacity", opacity_dragon)
		if opacity_dragon <= 0.99:
			if !start:
				get_tree().get_root().add_child(room)
			var bg = get_theme_stylebox("panel")
			opacity_panel -= delta * (1.1 - opacity_panel)
			bg.bg_color.a = opacity_panel
			if opacity_panel <= 0:
				print("free willy")
				queue_free()

#Recenter draakje
func _on_item_rect_changed():
	if anim:
		var size = get_viewport_rect().size
		anim.position = Vector2(size.x/2, size.y/2)

func _on_draakje_animation_finished():
	fadeout = true
