module(..., package.seeall)

function music_start()
	local campaign= campaign_get()
	local current_campaign= campaign.current_campaign
	local level= campaign.get_current_level()
	
	global.music_id= -1
	
	local music_index= -1
	if (level) then
		music_index= level.music[0]
	end

	if (current_campaign and (music_index >= 0) and (music_index < current_campaign.music_refs.count)) then
		local filename= current_campaign.music_refs[music_index].music_filename
		local sm= world_state_get().sound_manager
		global.music_id= sm.play_music(filename, false)
	end
end

function music_fadeout()
	local ws= world_state_get()
	local sound= ws.sound_manager
	if (global.music_id ~= -1) then
		sound.fadeout_music(global.music_id, 5, true)
		global.music_id= -1
	end		
end
