#Conditional Hooks
$Application: FS2_Open

$On Gameplay Start:
[
    hny_secret_music = false
    hny_music_handle = nil
    hny_music_cued = nil
    
    hny_stopped_debrief = false
    hny_stopped_mainhall = false
]

$State: GS_STATE_DEBRIEF
$On Frame:
[
    -- if this is happynewyear, and we got the secret, then play the secret music
    if hny_secret_music and not hny_stopped_debrief then
        -- stop the regular debriefing music
        ad.stopMusic(0, false, "briefing")
        hny_stopped_debrief = true

        -- start the timer
        hny_music_cued = time.getCurrentTime()
    end

    -- start the music with the same delay as normal debriefing music
    -- (well, partly because of the cymbal, start at 1.25 instead of 2.5)
    if hny_music_cued and (time.getCurrentTime() - hny_music_cued):getSeconds() >= 1.25 then
        hny_music_cued = nil

        -- happynewyear!
        hny_music_handle = ad.playMusic("newyork")
    end
]

$State: GS_STATE_MAIN_MENU
$On State Start:
[
    -- if we got the secret, stop the main hall music
    if hny_secret_music and hny_music_handle and not hny_stopped_mainhall then
        -- stop the regular mainhall music
        ad.stopMusic(0, false, "mainhall")
        hny_stopped_mainhall = true
    end
]

$State: GS_STATE_START_GAME
$On State Start:
[
    -- okay, calm down
    if hny_music_handle then
        ad.stopMusic(hny_music_handle, true)
        hny_music_handle = nil
    end
]

#End