extends ColorRect

@onready var label = $StoryText
@onready var keyTime = $KeyTime
@onready var textLength = label.text.length()
var textSpeed = 1

var switchedAudio = false

func _ready():
	keyTime.start()
	Audio.playStoryMusic()

func startGame():
	keyTime.stop()
	Fade.fade()
	await Fade.has_faded
	get_tree().change_scene_to_file("res://idk_base.tscn")
	queue_free()

func _on_key_time_timeout() -> void:
	if label.visible_characters >= textLength:
		startGame()
	elif not switchedAudio and label.get_visible_line_count() == 10:
		switchedAudio = true
		Audio.stopStoryMusic()
		Audio.playPlayMusic()
	else:
		label.visible_characters += textSpeed

func _on_skip_pressed() -> void:
	Audio.buttonClick.play()
	Audio.stopStoryMusic()
	Audio.playPlayMusic()
	startGame()
