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.playing = true
	$Draakje/Hoest.playing = true
	var size = get_viewport_rect().size
	anim.position = Vector2(size.x/2, size.y/2)
	var bg = get_theme_stylebox("panel")
	bg.bg_color = Color("3a223a")
	
func _process(delta):
	if fadeout:
		opacity_dragon -= delta * 2.0
		anim.material.set_shader_parameter("opacity", opacity_dragon)
		$Draakje/Label.material.set_shader_parameter("opacity", opacity_dragon)
		if opacity_dragon <= 0.25:
			if !start:
				get_tree().root.add_child(room)
			var bg = get_theme_stylebox("panel")
			#bg.bg_color = Color.BLACK
			opacity_panel -= delta * 0.5
			bg.bg_color.a = opacity_panel
			if opacity_panel <= 0:
				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
