extends Node

signal ready_to_continue

@onready var menuMusic = $MenuBgMusic
@onready var storyMusic = $StoryBgMusic
@onready var playMusic = $PlayBgMusic
@onready var animationPlayer = $AnimationPlayer

@onready var buttonClick = $ButtonClick
@onready var upgradeSound = $UpgradeSound
@onready var windowSound = $ShowWindow

var first = true

func playMenuMusic():
	if not first:
		await ready_to_continue
	else:
		first = false
	menuMusic.play()
	animationPlayer.play("menu_fade_in")

func stopMenuMusic():
	animationPlayer.play("menu_fade_out")
	
func playStoryMusic():
	await ready_to_continue
	storyMusic.play()
	animationPlayer.play("story_fade_in")
	
func stopStoryMusic():
	animationPlayer.play("story_fade_out")
	
func playPlayMusic():
	await ready_to_continue
	playMusic.play()
	animationPlayer.play("play_fade_in")
	
func stopPlayMusic():
	animationPlayer.play("play_fade_out")
	
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	if anim_name == "menu_fade_out":
		menuMusic.stop()
		ready_to_continue.emit()
	elif anim_name == "story_fade_out":
		storyMusic.stop()
		ready_to_continue.emit()
	elif anim_name == "play_fade_out":
		playMusic.stop()
		ready_to_continue.emit()
