extends Node

enum Songs {PigeonPark, DirtJuice, ShopTheme, Alight, Library, 
CalmCave, PigeonGrove, Faire, MainMenu, Home, Boat, Titanic, None, Beach}

var songFiles = {}
var locationSongs = {}

var musicPlayer:AudioStreamPlayer

var currentSong:Songs

func _ready():
	musicPlayer = load("res://Sounds/MusicPlayer.tscn").instantiate()
	add_child(musicPlayer)
	
	load_songs()
	initialize_location_songs()
	
	LocationManager.location_changed.connect(play_location_song)

func play_menu_music():
	currentSong = Songs.MainMenu
	musicPlayer.stream = songFiles[currentSong]
	musicPlayer.play()

func play_music(song:Songs):
	if currentSong == null or currentSong != song:
		musicPlayer.stream = songFiles[song]
		musicPlayer.play()
	
	currentSong = song

func play_location_song():
	play_music(locationSongs[LocationManager.currentLocationName])

func initialize_location_songs():
	locationSongs[LocationManager.Locations.Park] = Songs.PigeonPark
	locationSongs[LocationManager.Locations.Arcade] = Songs.Alight
	locationSongs[LocationManager.Locations.JuiceCafe] = Songs.ShopTheme
	locationSongs[LocationManager.Locations.Faire] = Songs.Faire
	locationSongs[LocationManager.Locations.MuseumArea] = Songs.PigeonPark
	locationSongs[LocationManager.Locations.PigeonGrove] = Songs.PigeonGrove
	locationSongs[LocationManager.Locations.Tutorial] = Songs.Boat
	locationSongs[LocationManager.Locations.Pier] = Songs.PigeonPark
	locationSongs[LocationManager.Locations.ElliePier] = Songs.None
	locationSongs[LocationManager.Locations.EllieBoat] = Songs.Titanic
	locationSongs[LocationManager.Locations.HomeArea] = Songs.DirtJuice
	locationSongs[LocationManager.Locations.PlayerHome] = Songs.Home
	locationSongs[LocationManager.Locations.MarlowHome] = Songs.DirtJuice
	locationSongs[LocationManager.Locations.BeachPathForest] = Songs.PigeonPark
	locationSongs[LocationManager.Locations.Museum] = Songs.Library
	locationSongs[LocationManager.Locations.MuseumCave] = Songs.CalmCave
	locationSongs[LocationManager.Locations.JonaldLairEntrance] = Songs.CalmCave
	locationSongs[LocationManager.Locations.JonaldLair] = Songs.Alight
	locationSongs[LocationManager.Locations.Beach] = Songs.Beach
	locationSongs[LocationManager.Locations.ParkBeachPath] = Songs.PigeonPark

func load_songs():
	songFiles[Songs.MainMenu] = load("res://Sounds/OST/New/mainmenu.mp3")
	songFiles[Songs.Home] = load("res://Sounds/OST/New/home.mp3")
	songFiles[Songs.PigeonPark] = load("res://Sounds/OST/New/pigeonpark.mp3")
	songFiles[Songs.DirtJuice] = load("res://Sounds/OST/New/dirtjuice.mp3")
	songFiles[Songs.ShopTheme] = load("res://Sounds/OST/New/juice.mp3")
	songFiles[Songs.Alight] = load("res://Sounds/OST/New/jonald.mp3")
	songFiles[Songs.Library] = load("res://Sounds/OST/New/museum.mp3")
	songFiles[Songs.CalmCave] = load("res://Sounds/OST/New/cavemusic.mp3")
	songFiles[Songs.PigeonGrove] = load("res://Sounds/OST/New/grove.mp3")
	songFiles[Songs.Faire] = load("res://Sounds/OST/New/faire.mp3")
	songFiles[Songs.Boat] = load("res://Sounds/OST/New/boat.mp3")
	songFiles[Songs.Titanic] = load("res://Sounds/OST/New/boatbad.mp3")
	songFiles[Songs.None] = load("res://Sounds/OST/New/swingdotted8ths.mp3")
	songFiles[Songs.Beach] = load("res://Sounds/OST/New/meetingTheWhale.mp3")
