dofile("scripts/entities/entityinclude.lua")
dofile(appendUserDataPath("_mods/jukebox/scripts/jukeboxinclude.lua"))

--[[
Button layout on screen:

        *RAND*
  PREV          NEXT 
  
                     EXIT
--]]

local navmap = {
    [ACTION_MENULEFT] = "jukebox-previous",
    [ACTION_MENURIGHT] = "jukebox-next",
    [ACTION_MENUDOWN] = "jukebox-quit"
}

function init(me)
    jukebox_initButton(me)
end

function action(me, action, state)
	if isNestedMain() then return end
    return jukebox_doButtonAction(me, action, state, navmap, true)
end

function activate(me)
	if isNestedMain() then return end
	
	--playSfx("TitleAction")
	spawnParticleEffect("TitleEffect1", node_x(me), node_y(me))
	watch(0.5)
	
    local n = jukebox_getSong()
    local count = #SONG_LIST
    if count > 1 then
        local n2 = math.random(count-1)
        if n2 >= n then n2 = n2 + 1 end
        n = n2
    end
    jukebox_playSong(n)
end

function update(me, dt)
end
