extends CutScene

func _ready() -> void:
	start_scene()

func start_scene(camera:CameraGame = null):
	var text_show_delay = 2
	var no_text_delay = 1
	
	$Wind.play()
	$Wind/Tween.interpolate_property($Wind, "volume_db", $Wind.volume_db, -15, 0.5)
	$Wind/Tween.start()
	
	$MarginContainer/Text.text = '';
	$AnimationPlayer.play("start")
	yield($AnimationPlayer, "animation_finished")
	
	$MarginContainer/Text.text = 'breathe...';
	$AnimationPlayer.play("fade-text")
	yield($AnimationPlayer, "animation_finished")
	yield(get_tree().create_timer(text_show_delay), "timeout")
	$AnimationPlayer.play_backwards("fade-text")
	yield($AnimationPlayer, "animation_finished")
	
	yield(get_tree().create_timer(no_text_delay), "timeout")
	
	$MarginContainer/Text.text = 'you know you can do this';
	$AnimationPlayer.play("fade-text")
	yield($AnimationPlayer, "animation_finished")
	yield(get_tree().create_timer(text_show_delay), "timeout")
	$AnimationPlayer.play_backwards("fade-text")
	yield($AnimationPlayer, "animation_finished")
	
	yield(get_tree().create_timer(no_text_delay), "timeout")
	
	$MarginContainer/Text.text = 'once again...';
	$AnimationPlayer.play("fade-text")
	yield($AnimationPlayer, "animation_finished")
	yield(get_tree().create_timer(text_show_delay), "timeout")
	$AnimationPlayer.play_backwards("fade-text")
	yield($AnimationPlayer, "animation_finished")
	
	yield(get_tree().create_timer(no_text_delay), "timeout")
	
	$Wind.play()
	$Wind/Tween.interpolate_property($Wind, "volume_db", $Wind.volume_db, -30, 0.5)
	$Wind/Tween.start()
	
	$AnimationPlayer.play_backwards("start")
	yield($AnimationPlayer, "animation_finished")
	_on_scene_exited()
	
func _on_scene_exited():
	end_scene()
	GameState.start_new_game(false, false)
