#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#System["./tricky_system/TrickySystem.dnh"]
#Title["The Summer Snow Incident"]
#Text["Oh no. It's winter when it[r]shouldn't be. Again.[r]Okina Matara is mad that[r]someone took her idea, so[r]she tries to fix it herself."]
#Player["./lib/Okina_player_by_Python/Okina Matara/Okina.dnh"]

let scriptStage1;
let scriptStage2;
let scriptStage3;
let CSD = GetCurrentScriptDirectory;

function LoadAllImagesInFolder(path){
	yield;
	let plist = GetFilePathList(path);
	let dlist = GetDirectoryList(path);
	ascent(i in 0..length(plist)){
		let cFile = plist[i];
		let fExt = cFile[length(cFile)-3..length(cFile)];
		if(fExt == "png" || fExt == "jpg" || fExt == "bmp"){
			LoadTextureInLoadThread(cFile);
		}
	}
	
	ascent(i in 0..length(dlist)){
		LoadAllImagesInFolder(dlist[i]);
	}
}

@Loading{
LoadAllImagesInFolder(CSD);

scriptStage1 = LoadScript(CSD ~ "Stage1/aStage.dnh");
scriptStage2 = LoadScript(CSD ~ "Stage2/aStage.dnh");
scriptStage3 = LoadScript(CSD ~ "Stage3/aStage.dnh");

InstallFont(CSD ~ "BNKGOTHM.TTF");
SetCommonData("Main Game", true);
}

@Initialize{
SetPlayerLife(5);
TGame();
}

@MainLoop{ yield; }

task TGame{
	StartScript(scriptStage1);
	while(!IsCloseScript(scriptStage1)){ yield; }
	StartScript(scriptStage2);
	while(!IsCloseScript(scriptStage2)){ yield; }	
	StartScript(scriptStage3);
	while(!IsCloseScript(scriptStage3)){ yield; }	
	CloseStgScene;
	CloseScript(GetOwnScriptID());
}

function wait(w){ loop(w){ yield; } }