tyrano.plugin.kag.studio={app:{},tyrano:null,rider_view:{},ipc:{},flag_push_console:!0,last_push_console_obj:{},map_watch:{},init:function(){if(-1!=window.navigator.userAgent.indexOf("TyranoStudio")){try{this.ipc=window.studio_api}catch(e){return!1}TYRANO.kag.is_studio=!0;this.ipc=window.studio_api;console.log(this.ipc);setInterval((e=>{let charas=this.kag.stat.charas;this.send("chara-update-charas",charas)}),5e3);var j_reload_button=$("<div style='position:absolute;z-index:999999999;padding:10px;opacity:0.8;background-color:white;left:0px;top:0px'><button style='cursor:pointer'><span style=''>"+$.lang("reload")+"</span></button></div>");j_reload_button.draggable({scroll:!1,stop:(e,ui)=>{}});j_reload_button.find("button").on("click",(e=>{location.reload()}));$("body").append(j_reload_button);this.send("init-variable",{})}},trigger(cmd,arg){if("ping"==cmd)this.send("asynchronous-reply",JSON.stringify(arg));else if("variable-add"==cmd){let data=JSON.parse(arg),array_name=data.names;for(let i=0;i<array_name.length;i++){let name=array_name[i].name,val=""+this.kag.embScript(name);this.map_watch[name]=val;array_name[i].val=val}data.names=array_name;this.send("changed-variable",data)}else if("status-clear-save-data"==cmd)localStorage.clear();else if("status-load-save"==cmd){let slot=JSON.parse(arg).slot;var timer_id=setInterval((()=>{if(1==this.kag.stat.is_strong_stop){clearInterval(timer_id);this.kag.menu.loadGame(slot)}}),100)}else if("exe-tag"==cmd){let tag_text=JSON.parse(arg).tag_text;this.cutTyranoScript(tag_text)}else if("material-preview-position"==cmd){let data=JSON.parse(arg),file=data.file,category=data.category;this.insertElement(category,file)}else if("variable-add-all"==cmd){var map_variable=TYRANO.kag.variable,f=TYRANO.kag.stat.f,mp=TYRANO.kag.stat.mp;map_variable.f=f;map_variable.mp=mp;this.send("init-variable-all",map_variable)}},insertElement:function(category,file){var path="./data/"+category+"/"+file;if("fgimage"==category||"image"==category){var j_img=$("<div style='position:absolute;z-index:9999999999;'><div class='area_pos' style='position:absolute;width:100px;opacity:0.5;background-color:black;color:white'></div><div class='button_delete' style='position:absolute;right:0px;border:solid 1px gray;background-color:white;width:20px;height:20px;cursor:pointer' >×</div><img style='width:100%;border:solid 1px green;' src='"+path+"' /></div>");(()=>{var _j_img=j_img;j_img.on("mousedown",(e=>{TYRANO.kag.tmp.three.stat.fps.stop_eye_move=!0}));j_img.on("mouseup",(e=>{TYRANO.kag.tmp.three.stat.fps.stop_eye_move=!1}));j_img.draggable({scroll:!1,stop:(e,ui)=>{let left=Math.floor(ui.position.left),top=Math.floor(ui.position.top);_j_img.find(".area_pos").html("x:"+left+" y:"+top);let obj={left:left,top:top};this.send("material-update-pos",obj)}});j_img.resizable({aspectRatio:!0,handles:"all",resize:(e,ui)=>{var target=$(e.target);let obj={width:parseInt(target.css("width")),height:parseInt(target.css("height"))};this.send("material-update-size",obj)}});_j_img.find(".button_delete").click((function(){_j_img.remove()}));$(".tyrano_base").attr("ondragstart","");$(".tyrano_base").append(_j_img)})()}else if("bgimage"==category){TYRANO.kag.layer.getLayer("base","fore").css("background-image","url("+path+")")}},send:function(key,json_obj){window.opener&&window.opener.window.app.project.triggerIpc(key,json_obj)},notifyChangeVariable:function(){let data={},array_name=[];for(let key in this.map_watch){void 0===this.map_watch[key]&&(this.map_watch[key]="");let val=this.kag.embScript(key);this.map_watch[key]=val;array_name.push({name:key,val:val})}data.names=array_name;this.send("changed-variable",data)},pushConsole:function(obj){this.last_push_console_obj=obj;if(1==this.flag_push_console){this.flag_push_console=!1;setTimeout((e=>{this.flag_push_console=!0;this.send("replay-console",this.last_push_console_obj)}),1e3)}},complete:function(TG){let init_data={array_save:TG.kag.menu.getSaveData()};this.send("load-complete",init_data)},cutTyranoTag:function(tag,pm){TYRANO.kag.ftag.startTag(tag,pm)},cutTyranoScript:function(str){for(var array_s=TYRANO.kag.parser.parseScenario(str).array_s,i=0;i<array_s.length;i++){var tag=array_s[i];this.cutTyranoTag(tag.name,tag.pm)}}};
