

init python:

###############################################################################
# Define songs and playlists
###############################################################################

    # All songs (grouped in playlists)
    # Also specify if a song starts out as unlocked by default (True/False)


#Chapter 1
    playlist_Ch2_New = [
        ["music/Ambience/Aspiration to Infinity - Titan Sound.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
        ["music/VeskyThinkingOfYou.ogg", True],

    ]
    playlist_Ch2_Coffee = [
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
        ["music/Ambience/Corey King - Figure 8.ogg", True],
        ["music/Ambience/Hartley - Sunz.ogg", True],
        ["music/Ambience/Kensingtion Studios - Good Looking Shoes.ogg", True],
        ["music/Ambience/Aspiration to Infinity - Titan Sound.ogg", True],


    ]



    #Chapter 3.5


    playlist_BellaDate = [
        ["music/QuietRomance/Mattijs Muller - Through New Eyes.ogg", True],
        ["music/QuietRomance/Grace Mesa - We See Stardust.ogg", True],

    ]
    playlist_Chapter1 = [
        ["music/VeskyThinkingOfYou.ogg", True],
        ["music/Ambience/Vesky - Remembrance.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],

    ]

    playlist_Chapter1a = [
        ["music/Ambience/Jess Ellen - A Hypothetical.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
        ["music/Ambience/Aspiration to Infinity - Titan Sound.ogg", True],

    ]

    playlist_Amber = [
        ["music/VeskyBeyondTheWindow.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],

    ]

    playlist_Chapter1a = [
        ["music/Ambience/Jess Ellen - A Hypothetical.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
        ["music/Ambience/Aspiration to Infinity - Titan Sound.ogg", True],

    ]

    playlist_Chapter1b = [
        ["music/Ambience/Vesky - Thoughts.ogg", True],
        ["music/Ambience/Jess Ellen - A Hypothetical.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],

    ]

    playlist_Chapter1c = [
        ["music/Ambience/We Are Missing You.ogg", True],
        ["music/Ambience/Jess Ellen - A Hypothetical.ogg", True],

    ]

    playlist_Chapter1d = [
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],
        ["music/CH5/Beza - On the Moon.ogg", True],


    ]

    playlist_Ch1Bus = [
        # [song_file, start_as_unlocked]
        ["music/Late Kids/Late Kids - Some Days.ogg", True],
        ["music/Late Kids/Late Kids - Run.ogg", True],
    ]

    playlist_Ch1CollegeBella = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - I go crazy I go all the way.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
    ]

    playlist_Ch1CollegeEnd = [
        # [song_file, start_as_unlocked]
        ["music/RockPop/Sound and Vision - This Party Bussin'.ogg", True],
        ["music/Late Kids/Late Kids - Run.ogg", True],
    ]

    playlist_Ch1Vic = [
        ["music/QuietRomance/Hartley - Hugs.ogg", True],
        ["music/Ambience/Vesky - Remembrance.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],

    ]



    playlist_AmbientBella = [
        # [song_file, start_as_unlocked]
        ["music/Vesky - Aurora.ogg", True],
        ["music//Vesky - Departure.ogg", True],
        ["music//VeskyThinkingOfYou.ogg", True],
        ["music//Fyze - Wanderer.ogg", True],
        ["music//Vesky - Silhouette.ogg", True],
    ]

    playlist_AmbientBellchen = [
        ["music//Vesky - Departure.ogg", True],
        ["music/Vesky - Aurora.ogg", True],
        ["music//VeskyThinkingOfYou.ogg", True],
        ["music//Fyze - Wanderer.ogg", True],
        ["music//Vesky - Silhouette.ogg", True],
    ]
    playlist_AmbientCheeto = [
        ["music//VeskyThinkingOfYou.ogg", True],
        ["music/Vesky - Aurora.ogg", True],
        ["music//VeskyThinkingOfYou.ogg", True],
        ["music//Fyze - Wanderer.ogg", True],
        ["music//Vesky - Silhouette.ogg", True],
    ]



    playlist_GirlyPop = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/Late Kids/Late Kids - Run.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],

    ]

    playlist_Gymch3 = [
        # [song_file, start_as_unlocked]
        ["music/Late Kids/Late Kids - Run.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],

    ]

    playlist_SashaPop = [
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],
        ["music/Late Kids/Late Kids - Some Days.ogg", True],
    ]



    playlist_QuietRomance = [
        # [song_file, start_as_unlocked]
        ["music/QuietRomance/Beza - Save Myself.ogg", True],
        ["music/QuietRomance/Grace Mesa - We See Stardust.ogg", True],

    ]

    playlist_RockPop = [
        # [song_file, start_as_unlocked]
        ["music/RockPop/Sound and Vision - This Party Bussin'.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],
        ["music/Late Kids/Late Kids - Some Days.ogg", True],
        ["music/QuietRomance/Mattijs Muller - Through New Eyes.ogg", True],

    ]

    playlist_NamiSad = [
        # [song_file, start_as_unlocked]
        ["music/QuietRomance/Mattijs Muller - Through New Eyes.ogg", True],
        ["music/QuietRomance/Beza - Save Myself.ogg", True],
        ["music/Ambience/Aspiration to Infinity - Titan Sound.ogg", True],
    ]

    playlist_BellchenDinnerx = [
        # [song_file, start_as_unlocked]
        ["music/QuietRomance/Beza - Carry On.ogg", True],
        ["music/QuietRomance/Grace Mesa - We See Stardust.ogg", True],
        ["music/QuietRomance/Mattijs Muller - Through New Eyes.ogg", True],
    ]
    
    playlist_Ch2BB = [
        # [song_file, start_as_unlocked]
        ["music/Late Kids/Late Kids - Some Days.ogg", True],
        ["music/Late Kids/Late Kids - Run.ogg", True],
        ["music/QuietRomance/Mattijs Muller - Through New Eyes.ogg", True],
    ]

    #
############################################################################################################### CH4
    playlist_DarkAmbientDnD = [
        # [song_file, start_as_unlocked]
        ["music/Tabletop/Dark/A.Z - Dark Ambient 2.ogg", True],
        ["music/CH5/Soundside - Dark Room.ogg", True],
        ["music/Tabletop/Dark/A.Z - Dark Ambient 1.ogg", True],
    ]
    playlist_DarkAmbientDnDx = [
        # [song_file, start_as_unlocked]
        ["music/Suspense/A.W - Alone.ogg", True],
        ["music/CH5/Soundside - Dark Room.ogg", True],
        ["music/Tabletop/Dark/A.Z - Dark Ambient 2.ogg", True],
        ["music/Tabletop/Dark/A.Z - Dark Ambient 1.ogg", True],
    ]

    playlist_AfterDND = [
        # [song_file, start_as_unlocked]
        ["music/Late Kids/Late Kids - Run.ogg", True],
        ["music/Late Kids/Late Kids - Some Days.ogg", True],
    ]
    playlist_GirlyCh4 = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],
    ]
    playlist_GirlyCh4x = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
    ]
    playlist_AmbientNamiLake = [
        # [song_file, start_as_unlocked]

        ["music/VeskyThinkingOfYou.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
    ]
    playlist_Jaccuzi = [
        # [song_file, start_as_unlocked]
        ["music/TheIntangible/The Intangible - Encyclopedia of Frozen Dreams.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
        ["music/VeskyThinkingOfYou.ogg", True],
    ]

    playlist_MellowMaja = [
        # [song_file, start_as_unlocked]
        ["music/TheIntangible/The Intangible - Encyclopedia of Frozen Dreams.ogg", True],
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
        ["music/VeskyThinkingOfYou.ogg", True],
    ]

    playlist_Diner = [
        # [song_file, start_as_unlocked]
        ["music/Late Kids/Late Kids - Some Days.ogg", True],
        ["music/GirlyPop/Beza - Leave the Past Behind.ogg", True],
        ["music/GirlyPop/Grace Mesa - Life to Live.ogg", True],

    ]


################################# Ch4.5

    playlist_Ch4x5 = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - Right Kind of Day.ogg", True],
        ["music/GirlyPop/Beza - Leave the Past Behind.ogg", True],
        ["music/GirlyPop/Grace Mesa - Life to Live.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
    ]

    playlist_Ch4x5v = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - Life to Live.ogg", True],
        ["music/GirlyPop/Beza - Leave the Past Behind.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
    ]

    playlist_Ch4x52 = [
        # [song_file, start_as_unlocked]
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - Right Kind of Day.ogg", True],
        ["music/GirlyPop/Beza - Leave the Past Behind.ogg", True],
        ["music/GirlyPop/Grace Mesa - Life to Live.ogg", True],
    ]

    playlist_Ch4x5A = [
        # [song_file, start_as_unlocked]
        ["music/QuietRomance/Beza - Save Myself.ogg", True],
        ["music/GirlyPop/Beza - Leave the Past Behind.ogg", True],
    ]


    playlist_WatchingStars = [
        # [song_file, start_as_unlocked]
        ["music/QuietRomance/Beza - Watching from the Stars.ogg", True],
        ["music/TheIntangible/The Intangible - Qualia.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
    ]

    playlist_Crossroads = [
        # [song_file, start_as_unlocked]
        ["music/TheIntangible/The Intangible - Crossroads.ogg", True],
        ["music/TheIntangible/The Intangible - Qualia.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
    ]
    playlist_Crossroads2 = [
        # [song_file, start_as_unlocked]
        ["music/TheIntangible/The Intangible - Qualia.ogg", True],
        ["music/TheIntangible/The Intangible - Crossroads.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
    ]

    playlist_BigTiddyMila = [
        # [song_file, start_as_unlocked]
        ["music/QuietRomance/Mattijs Muller - Through New Eyes.ogg", True],
        ["music/TheIntangible/The Intangible - Qualia.ogg", True],

    ]

    playlist_Ch4x53 = [
        ["music/Ambience/Vesky - Remembrance.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],

    ]


    playlist_Ch5_Gas = [
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
        ["music/Ambience/Vesky - We are just stars.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],

    ]

    playlist_Ch5_Nia = [
        ["music/Ambience/Dr. ATMO - Flüsternde schatten feat. Johan Age.ogg", True],
        ["music/Youth83/YOUTH 83 - Water Girl.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],

    ]

    playlist_Ch5_ViceCity = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Mark Fabian - Slow Momentum.ogg", True],
        ["music/CH5/Magnetize Music - Hope Brings Life.ogg", True],
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
        ["music/Ambience/Dr. ATMO - Flüsternde schatten feat. Johan Age.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],

    ]

    playlist_Ch5_LostSoul = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Azula Wave - Lost Souls.ogg", True],
        ["music/CH5/Soundside - Dark Room.ogg", True],
    ]

    playlist_Ch5_Cougar = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Beza - On the Moon.ogg", True],
        ["music/GirlyPop/Grace Mesa - Right Kind of Day.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],


    ]
    playlist_Ch5_Cougar2 = [
        ["music/GirlyPop/Grace Mesa - Life to Live.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/CH5/Beza - On the Moon.ogg", True],
        ["music/GirlyPop/Grace Mesa - Right Kind of Day.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],
    ]

    playlist_Ch5_Sad_Cheeto = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Glory House - Lovely Stuff.ogg", True],
        ["music//VeskyThinkingOfYou.ogg", True],
        ["music/Vesky - Aurora.ogg", True],
        ["music//VeskyThinkingOfYou.ogg", True],
    ]

    playlist_Ch5_ViceCity2 = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
        ["music/Ambience/Dr. ATMO - Flüsternde schatten feat. Johan Age.ogg", True],
        ["music/CH5/Mark Fabian - Slow Momentum.ogg", True],
        ["music/CH5/Magnetize Music - Hope Brings Life.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
    ]

    playlist_Ch5_Zara = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Beza - Flashing Neon Signs.ogg", True],
        ["music/CH5/Beza - Can I Have This Dance.ogg", True],
        ["music/GirlyPop/Grace Mesa - Life to Live.ogg", True],
        ["music/GirlyPop/Grace Mesa - Diamonds Into Dust.ogg", True],
        ["music/GirlyPop/Grace Mesa - The Long Way.ogg", True],


    ]

    playlist_Ch5_Ghosts = [
        #["music/Youth83/YOUTH 83 - Red Kite.ogg", True],
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
        ["music/CH5/Magnetize Music - Hope Brings Life.ogg", True],
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
        ["music/Ambience/Dr. ATMO - Flüsternde schatten feat. Johan Age.ogg", True],
        ["music/Ambience/Awaken your Senses - Artlss.ogg", True],
    ]
    
    playlist_Ch2_ScaryMary = [
        ["music/Tabletop/Dark/A.Z - Dark Ambient 2.ogg", True],
        ["music/CH5/Soundside - Dark Room.ogg", True],
        ["music/Tabletop/Dark/A.Z - Dark Ambient 1.ogg", True],
    ]

    playlist_Ch2_ScaryMary2 = [
        ["music/CH5/Soundside - Dark Room.ogg", True],
        ["music/Tabletop/Dark/A.Z - Dark Ambient 2.ogg", True],
        ["music/Tabletop/Dark/A.Z - Dark Ambient 1.ogg", True],
    ]

    playlist_Ch2_ScaryMary3 = [
        ["music/CH5/Vesper Tapes - Mellow Fields.ogg", True],
    ]
    # All playlists
    all_playlists = [
        playlist_Chapter1,
        playlist_Chapter1a,
        playlist_Chapter1b,
        playlist_Ch1Bus,
        playlist_Chapter1d,
        playlist_Ch1CollegeEnd,
        playlist_Ch1Vic,
        playlist_Ch4x52,

        playlist_QuietRomance,
        playlist_RockPop,
        playlist_BellaDate,
        playlist_AmbientBella,
        playlist_NamiSad,
        playlist_GirlyPop,
        playlist_SashaPop,
        playlist_DarkAmbientDnD,
        playlist_AfterDND,
        playlist_GirlyCh4,
        playlist_GirlyCh4x,
        playlist_AmbientNamiLake,
        playlist_Jaccuzi,
        playlist_Diner,
        playlist_Chapter1c,
        playlist_Ch1CollegeBella,
        playlist_Ch2_New,

        playlist_Ch4x5,
        playlist_Ch4x5A,
        playlist_WatchingStars,
        playlist_Crossroads2,
        playlist_BigTiddyMila,
        playlist_Ch4x53,
        playlist_AmbientBellchen,
        playlist_AmbientCheeto,
        playlist_Ch4x5v,
        playlist_Amber,
        playlist_Gymch3,
        playlist_BellchenDinnerx,
        playlist_DarkAmbientDnDx,
        playlist_Ch2_Coffee,

        playlist_Ch5_Gas,
        playlist_Ch5_Nia,
        playlist_Ch5_ViceCity,
        playlist_Ch5_ViceCity2,
        playlist_Ch5_LostSoul,
        playlist_Ch5_Cougar,
        playlist_Ch5_Sad_Cheeto,
        playlist_Ch5_Zara,
        playlist_Ch5_Ghosts,
        playlist_Ch5_Cougar2,
        playlist_Ch2_ScaryMary,
        playlist_Ch2_ScaryMary2,
        playlist_Ch2_ScaryMary3,
        playlist_Ch2BB,
        playlist_MellowMaja,
    ]


###############################################################################
# Unlocking songs
###############################################################################

    def is_valid_song(song_file):
        all_song_files = get_all_song_files()
        return song_file in all_song_files


    def get_all_song_files():
        all_songs = get_all_songs()
        return [ song_file for song_file, song_starts_as_unlocked in all_songs ]


    def get_all_songs():
        all_songs = []
        for playlist in all_playlists:
            all_songs = all_songs + playlist
        return all_songs


    def has_song_been_unlocked(song_file):
        return song_file in persistent.unlocked_songs and persistent.unlocked_songs[song_file]


    # Use this to unlock a song
    def unlock_song(song_file_to_unlock):
        # First check if this is a valid song file
        if not is_valid_song(song_file_to_unlock):
            return

        # Unlock the song in persistent
        persistent.unlocked_songs[song_file_to_unlock] = True
        update_song_queue()


    # Create the unlocked songs persistent variable, in case it doesn't exist
    if not persistent.unlocked_songs:
        persistent.unlocked_songs = {}

    # Update the persistent variable at the start of the game with any new songs
    # which may have been added
    for playlist in all_playlists:
        for song_file, song_starts_as_unlocked in playlist:
            persistent.unlocked_songs[song_file] = has_song_been_unlocked(song_file) or song_starts_as_unlocked


###############################################################################
# Music player
###############################################################################

    def get_current_song_name():
        current_song_file = renpy.music.get_playing()
        if current_song_file is None:
            return ""
        # remove the folder names
        song_name = current_song_file.split("/")[-1]
        # remove the audio file extension (.mp3 etc)
        song_name = '.'.join(song_name.split('.')[0:-1])
        return song_name


    def get_current_song_number():
        current_song_file = renpy.music.get_playing()
        if current_song_file is None or current_song_file not in song_queue:
            return None

        current_song_number = song_queue.index(current_song_file)
        return current_song_number


    def get_unlocked_song_files_in_current_playlist():
        return [ song_file for song_file, song_starts_as_unlocked in current_playlist if has_song_been_unlocked(song_file) ]


    def pause_music():
        renpy.music.set_pause(True)


    def play_next():
        global song_queue
        current_song_number = get_current_song_number()
        if current_song_number is None:
            return

        song_queue = shift_items(song_queue, -current_song_number - 1)
        renpy.music.play(song_queue, loop=True)


    def play_playlist(playlist=None):
        global current_playlist
        global song_queue
        if playlist is None:
            playlist = current_playlist

        # Only play unlocked songs from the current playlist in the music player
        current_playlist = playlist
        song_queue = get_unlocked_song_files_in_current_playlist()
        renpy.music.play(song_queue, loop=True)


    def play_prev():
        global song_queue
        current_song_number = get_current_song_number()
        if current_song_number is None:
            return

        song_queue = shift_items(song_queue, current_song_number + 1)
        renpy.music.play(song_queue, loop=True)


    def shift_items(items, shift_amount):
        from collections import deque
        item_queue = deque(items)
        item_queue.rotate(shift_amount)
        shifted_list = list(item_queue)
        return shifted_list


    def unpause_music():
        renpy.music.set_pause(False)


    def update_song_queue():
        global song_queue
        song_queue = get_unlocked_song_files_in_current_playlist()


    current_playlist = []
    song_queue = []


###############################################################################
# Screens
###############################################################################

screen music_player_trigger():
    default hotspot_width = 200
    mousearea:
        area(1920 - hotspot_width, 0, hotspot_width, 200)
        hovered Show("music_player", transition=dissolve)
        unhovered Hide("music_player", transition=dissolve)


screen music_player():
    vbox:
        xalign 1.0

        hbox:
            xalign 1.0

            textbutton "<<" action Function(play_prev)
            if renpy.music.get_pause():
                textbutton ">" action Function(unpause_music)
            else:
                textbutton "||":
                    action Function(pause_music)
            textbutton ">>" action Function(play_next)

        if renpy.music.is_playing():
            text get_current_song_name()
