#include"./EV_const.dnh"

let bgm = ObjSound_Create();
let Current = GetCurrentScriptDirectory();

let songlists = [Current ~ "..\..\Bgm\pg_prebattle1.mp3",
				Current ~ "..\..\Bgm\pg_boss1.mp3"];
@Initialize{
SetCommonData("MusicSystem",true);
}

@MainLoop{
yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_PAUSE_ENTER){
		ObjSound_SetRestartEnable(bgm,true);
		ObjSound_Stop(bgm);
	}
	case(EV_PAUSE_LEAVE){
		ObjSound_Play(bgm);
		ObjSound_SetRestartEnable(bgm,false);
	}
	case(EV_PLAYMUSIC){
	let data = GetEventArgument(0);
		PlayMusic(songlists[ator(data[0])],ator(data[1]),data[2],data[3]);
	}
	case(EV_STOPMUSIC){
	ObjSound_Stop(bgm);
	ObjSound_SetLoopEnable(bgm,true);
	}
	/*case(EV_FADEMUSIC){
	//FadeMusic
	//IfMusicIsLessThan50%VolumeDeleteIt
	}*/
}

task PlayMusic(str,v,loopstart,loopend){
	ObjSound_Load(bgm,str);
	ObjSound_SetSoundDivision(bgm,SOUND_BGM);
	ObjSound_SetVolumeRate(bgm,v);
	ObjSound_SetLoopEnable(bgm,true);
	ObjSound_SetRestartEnable(bgm,false);
	ObjSound_SetLoopSampleCount(bgm,loopstart,loopend);
	ObjSound_Play(bgm);
}