//メイン処理
var baseJs = null;
var _time = null;
BaseJsLoaded = false;
function StartProcess(){
	//Jsセット
	StartProcess.prototype.constructor = function(){
		StartProcess.prototype.load = false;
		StartProcess.prototype.imageload = false;
		StartProcess.prototype.oneload = false;
		StartProcess.prototype.core_load = false;
		StartProcess.prototype.timer_load = false;
		StartProcess.prototype.setting_load = false;
		StartProcess.prototype.image_load = false;
		StartProcess.prototype.box_load = false;
		StartProcess.prototype.save_load = false;
		StartProcess.prototype.title_str = document.title;
		console.log("OK20230401");
	}
	this.constructor();
	StartProcess.prototype.ClassLoad = function(){
		this.loaded();
		this.ScriptLoad("./baseJs/core.js?202008191230");
		this.ScriptLoad("./baseJs/timer.js?202008191230");
		this.ScriptLoad("./baseJs/setting.js?202008191230");
		this.ScriptLoad("./baseJs/image.js?202008191230");
		this.ScriptLoad("./baseJs/box.js?202008191230");
		this.ScriptLoad("./baseJs/save.js?202008191230");
		this.ScriptLoad("./baseJs/baseJs.js?202008191230");
	}
	StartProcess.prototype.ScriptLoad = function(URL){
		if(Main.oneload){
			if((!Main.core_load)||(!Main.timer_load)||(!Main.setting_load)||(!Main.box_load)||(!Main.image_load)||(!Main.save_load)){
				setTimeout(Main.ScriptLoad,1000,URL);
				return;
			}			
		}
		Main.oneload = false;
		if(URL.indexOf("baseJs.js")!==-1){
			if((!Main.core_load)||(!Main.timer_load)||(!Main.setting_load)||(!Main.box_load)||(!Main.image_load)||(!Main.save_load)){
				setTimeout(Main.ScriptLoad,1000,URL);
				return;
			}
		}
		var selm = document.createElement("script");
		selm.src = URL;
		document.body.appendChild(selm);
		selm.onload = function(){
			Main.oneload = true;
			if(this.src.indexOf("core.js")!==-1)Main.core_load=true;
			if(this.src.indexOf("timer.js")!==-1)Main.timer_load=true;
			if(this.src.indexOf("setting.js")!==-1)Main.setting_load=true;
			if(this.src.indexOf("image.js")!==-1)Main.image_load=true;
			if(this.src.indexOf("box.js")!==-1)Main.box_load=true;
			if(this.src.indexOf("save.js")!==-1)Main.save_load=true;
			
			if(this.src.indexOf("baseJs.js")!==-1){
				setTimeout(function(){
					BaseJsLoaded = true;
				},500);
			}
		}
		return selm;
	}
	StartProcess.prototype.loaded = function(){
		setTimeout(function(_this){
			if(BaseJsLoaded){
				_this.load = true;
			}else{
				_this.loaded();
			}
		},100,this);
	}
	StartProcess.prototype.Start = function(func){
		if(!Main.load){
			setTimeout(Main.Start,1000,func);
			return;
		}
		func();
	}
	StartProcess.prototype.ClassSetting = function(){
		var _this =null;
		try{
		_this = new BaseJs();
		_this.addProto(TimerProc,_this);
		_this.addProto(BaseSetting,_this);
		_this.addProto(ImageProcess,_this);
		_this.addProto(BoxMaker,_this);
		}catch(e){
			console.log(e);
			document.location.reload();
		}
		return _this;
	}
	StartProcess.prototype.Loading = function(_self,width="400px",height="550px",loadingFlg = true){
		//枠を生成
		var elm_div = _self.GetInitBox();
		var Optin = {
			linecolor:false,
			bgcolor:"#030303",
			txtcolor:"#F0F0F0",
			opacity:1,
		}
		elm_div = _self.SetBoxParam(elm_div,"anmaku",width,height,Optin);
		_self.AddBoxData(elm_div);
		_self.ChangeBox(elm_div.Name);
		_self.AddCommand("anmaku","br1","　");
		_self.AddCommand("anmaku","br2","　");
		_self.AddCommand("anmaku","br3","　");
		_self.AddCommand("anmaku","br4","　");
		_self.AddCommand("anmaku","br5","　");
		_self.AddCommand("anmaku","Loading","Now Loading...");
		_self.Elm(".Loading").classList.toggle("blinking");
		_self.AddCommand("anmaku","br6","　");
		_self.AddCommand("anmaku","Progress","0%");
		_self.StartOn = false;
		_self.WarningView = function(){
			if(!Main.imageload){
				_self.setTimer(_self.WarningView,100);
				return;
			}
			if(_self.StartOn)return;
			_self.StartOn = true;
			_self.Elm(".Progress").innerText = "";
			_self.Elm(".Loading").classList.toggle("blinking");
			_self.Elm(".Loading").innerText = "＜注意＞\nこのゲームに出てくる人物はすべて18歳以上です。\n監禁や強姦等は犯罪です。\nゲーム内の行為は決して真似しないで下さい。";
			var setelm = _self.Elm(".anmaku");
			setelm.style.backgroundColor="rgba(0,0,0,0.8)";
			_self.setTimer(function(){_self.ButtonView();},5000);
		}
		_self.ButtonView = function(){
			/*if(!Main.imageload){
				_self.setTimer(_self.ButtonView,100);
				return;
			}*/
			if(loadingFlg){
				_self.Elm(".Loading").innerText = Main.title_str;
			}else{
				_self.Elm(".Loading").innerText = "\n";
			}
			_self.AddCommand("anmaku","startbutton","画面をタッチしてスタート！");
			_self.Elm(".startbutton").classList.toggle("blinking");
			_self.AddCommand("anmaku","Version","　");
			_self.Elm(".Version").innerText = ver_str;
			_self.AddEventForId("anmaku",function(e){
				//タイトル画面消去
				myImg.SetIndexPos('Other',0);
				myImg.ClearImage('Other');				
				_self.setTimer(function(){
					_self.Elm("anmaku",_self.TypeID).innerHTML = "";
				},500);
			});
		}
		_self.WarningView();
		return _self;
	}
	StartProcess.prototype.DisplayWidth = function(value){
		var width = 0;
		if(window.innerWidth>=value){
			width = value;		
		}else{
			width = window.innerWidth;
		}
		return width;
	}
	StartProcess.prototype.DisplayHeight = function(value){
		var height = 0;
		if(window.innerHeight<=value){
			height = window.innerHeight;
		}else{
			height = value;
		}
		return height;
	}
}
var Main = new StartProcess();