From 3161b8ab925a16728034d38dd6cf2a64ef201812 Mon Sep 17 00:00:00 2001 From: YAMADA Yoshihiro Date: Sun, 8 Aug 2021 22:17:25 +0900 Subject: [PATCH] Modified: Editor2Flow --- playground/lib/playground.js | 3 ++- playground/lib/playground.min.js | 2 +- playground/lib/playground_editor.js | 1 + playground/lib/playground_editor.min.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/playground/lib/playground.js b/playground/lib/playground.js index 1051b21c..e2f3a0d5 100644 --- a/playground/lib/playground.js +++ b/playground/lib/playground.js @@ -3542,13 +3542,14 @@ ${Util.createLinkText(value.id, scenario.edges)} // Editorへの遷移 $('#ctrl_flow2editor').click(function(){ + $('body').css('opacity', 0.2); localStorage['flow2editor'] = Util.createXml(); window.open('./editor.html', 'pgeditor'); }); // ページ移動時の警告 $(window).on('beforeunload', function(){ - return "ページを閉じてもよろしいですか?"; + return "ページを閉じてもよろしいですか?"; }); // TIPS表示 diff --git a/playground/lib/playground.min.js b/playground/lib/playground.min.js index e1078e04..e40541cf 100644 --- a/playground/lib/playground.min.js +++ b/playground/lib/playground.min.js @@ -1 +1 @@ -$((function(){class LevelResolver{constructor(scenario){this.scenario=scenario,this.level={},this.maxLevel=1}run(){let that=this,over=this.getEdgeCount();this.traceScenes(0,1),this.scenario.scenes.forEach((function(scene){let level=that.level[scene.id];scene.level=level||that.maxLevel,over.includes(scene.id)&&(scene.level=that.maxLevel+1)}))}traceScenes(id,level){let that=this,children;this.level[id]||(this.level[id]=level,this.getToScenes(id).forEach((function(scene){that.traceScenes(scene.id,level+1)})),this.maxLevel15&&result.push(id)})),Object.keys(to_id).forEach((function(id){to_id[id]>15&&result.push(id)})),result}}let network=null,filter_where=[],grid={},isUpdatedInGrid=!1,help_page,Common_HELP_URL="https://sorcerian.hateblo.jp/entry/2018/11/01/211745#",Common_SCENE_INDEX=8,Common_EDGE_INDEX=9,Common_MY_STORAGE="pg2_save",Common_LOAD_NAME="pg2_load",Common_RUN_NAME="pg2_run",Common_CONFIG_NAME="pgflow_config",Common_INIT_CONFIG={author:"Unnamed",disp:"auto",increment:10},Common_INIT_DATA_EMPTY={title:"",author:"",init:{basic:{},constraint:{},bgm:{},label:{},intro:{}},groups:[],items:[],flags:[],params:[],enemies:[],results:[],licence:[],scenes:[],edges:[]},Common_INIT_DATA={title:"Untitled",author:"Unnamed",init:{basic:{summary:"",imgset:""},constraint:{race:"",sex:"",age:""},bgm:{main:"",happy:"",bad:""},label:{free1:"",free2:"",free3:""},intro:{keywords:"",description:""}},groups:[{start:0,end:1,title:"Introduction",rule:""}],items:[{id:"i01",name:"Item-01",text:"Item description..."}],flags:[{id:"f01",text:"Flag description..."}],params:[{id:"p01",min:0,max:100,initial:50,text:"Param description..."}],enemies:[{id:"m01",name:"Enemy-01",element:"earth",attack:"physics",func:"L+R-STR",drop:"mon/2",text:"Enemy description..."}],results:[{id:"r01",name:"Result-01",level:1,text:"Result description..."}],licence:[{name:"Bgm-01",category:"bgm",creator:"SText",url:"https://example.com/"}],scenes:[{id:"0",summary:"プロローグ",label:"0:\nプロローグ",text:"ここにプロローグを書きます。",group:"prologue"},{id:"1",summary:"本文",label:"1:\n本文",text:"ここからが本文です。"}],edges:[{from:"0",to:"1",label:"次へ"}]},Util={refreshScenario:function(new_data){scenario=JSON.parse(JSON.stringify(new_data)),Util.createAllGrid()},loadConfig:function(){let conf=localStorage[Common_CONFIG_NAME];try{return conf?JSON.parse(conf):Common_INIT_CONFIG}catch(e){return Common_INIT_CONFIG}},saveConfig:function(data){return!!data&&(localStorage[Common_CONFIG_NAME]=JSON.stringify(data),!0)},updateLevel(){let lr=new LevelResolver(scenario);return lr.run(),lr.scenario},sortFn:function(m,n){try{return Number(m.id.substring(1))-Number(n.id.substring(1))}catch(e){return console.error(e),0}},transferQuery:function(selector){return selector.replace(/\//g," > ")},getHelpPage:function(selector){$.get("./lib/reference.xml").done((function(result){help_page=result,Util.showHelpDialog(selector)}))},showHelpDialog:function(selector){if(help_page){let el=$(Util.transferQuery(selector),help_page),txt=el.text(),ref=el.attr("ref");ref&&(txt+=$(Util.transferQuery(ref),help_page).text()),$("#help-dialog > #help-body").html(marked(txt)),$("#help-dialog").dialog("open")}else Util.getHelpPage(selector);Util.closeAllSidebar()},maxSceneId:function(){return Math.max.apply(null,scenario.scenes.map((function(s){return s.id>=9e4?0:s.id})))},sortScenario:function(){scenario.groups.sort((function(m,n){return Number(m.start)-Number(n.start)})),scenario.items.sort(Util.sortFn),scenario.flags.sort(Util.sortFn),scenario.enemies.sort(Util.sortFn),scenario.results.sort(Util.sortFn)},sortScenes:function(){scenario.scenes.sort((m,n)=>Number(m.id)-Number(n.id))},sortEdges:function(){scenario.edges.sort((m,n)=>{let m_from=Number(m.from),n_from=Number(n.from),m_order=Number(m.order),n_order=Number(n.order);return m_from!==n_from?m_from-n_from:m_order-n_order})},isDuplicateOrderedEdge:function(from,order){return scenario.edges.some((function(value){return Number(value.from)===Number(from)&&Number(value.order)===Number(order)}))},detectLinkOrder:function(from,start){for(;;){if(!Util.isDuplicateOrderedEdge(from,start))return start;start++}},isDuplicateId:function(id,data){return data.some((function(value){return value.id===id}))},isDuplicateScene:function(id){return scenario.scenes.some((function(value){return Number(value.id)===Number(id)}))},isNewScene:function(id){return!Util.isDuplicateScene(id)},nextScene:function(id){let next_id=Number(id);for(;;)if(next_id+=Number(global_config.increment),Util.isNewScene(next_id))return next_id},addNode:(id,summary)=>Util.isDuplicateScene(id)?(toastr.error("id値が重複しています。","不正なid"),!1):(scenario.scenes.push({id:String(id),summary:summary,label:`${id}:\n${summary}`,text:""}),Util.sortScenes(),!0),changeNodeId(old_id,new_id){scenario.scenes.forEach((function(scene){String(scene.id)===old_id&&(scene.id=new_id,scene.label=`${new_id}\n${scene.summary}`)})),scenario.edges.forEach((function(edge){String(edge.from)===old_id&&(edge.from=new_id),String(edge.to)===old_id&&(edge.to=new_id)}))},swapNodeId(old_id,new_id){scenario.scenes.forEach((function(scene){if(String(scene.id)===old_id)return scene.id=new_id,void(scene.label=`${new_id}\n${scene.summary}`);String(scene.id)===new_id&&(scene.id=old_id,scene.label=`${old_id}\n${scene.summary}`)})),scenario.edges.forEach((function(edge){let done_from=!1,done_to=!1;String(edge.from)===old_id&&(edge.from=new_id,done_from=!0),String(edge.to)===old_id&&(edge.to=new_id,done_to=!0),done_from||String(edge.from)!==new_id||(edge.from=old_id),done_to||String(edge.to)!==new_id||(edge.to=old_id)})),console.log(scenario)},generateLinkId:function(from,to){return`custom${from}-${to}-${Math.floor(1e5*Math.random())}`},addLink:function(from,to,label,kind="",add="",correct=""){let order=Util.detectLinkOrder(from,90);if(kind)if("R"===kind||"X"===kind){let tos=[];tos.push(to),tos=tos.concat(add.split(",")),tos=[...new Set(tos)];for(let tmp_to of tos)scenario.edges.push({from:from,to:tmp_to,label:label,type:kind,order:order,id:Util.generateLinkId(from,tmp_to)})}else"Q"===kind&&(scenario.edges.push({from:from,to:to,label:label,type:"Q",correct:correct,order:order,id:Util.generateLinkId(from,to)}),scenario.edges.push({from:from,to:add,label:label,type:"Q",order:order,id:Util.generateLinkId(from,add)}));else scenario.edges.push({from:from,to:to,label:label,id:Util.generateLinkId(from,to)})},deleteLink(id){let index=scenario.edges.findIndex((function(edge){return edge.id===id}));return scenario.edges.splice(index,1)},deleteScene(id){if(0==id)return void toastr.error("id=0のシーンは削除できません。","不正な操作");let index=scenario.scenes.findIndex((function(scene){return scene.id===id}));for(scenario.scenes.splice(index,1);;){let e_index=scenario.edges.findIndex((function(edge){return edge.from===id||edge.to===id}));if(console.log(e_index),-1===e_index)break;scenario.edges.splice(e_index,1)}return!0},getSceneById:function(id){return scenario.scenes.find((function(elem){return elem.id===id}))},createLinkList:function(id){$("#scene-select #edges-list").empty(),$("#scene-select #edges-list").append(''),Util.sortEdges(),scenario.edges.forEach((function(value){value.from===id&&$("").attr("value",value.id).text(`${value.to}: ${value.label}`).appendTo("#scene-select #edges-list")}))},createSortLinkList:function(id){return Util.sortEdges(),scenario.edges.filter((function(value){return value.from===id}))},createColorList:function(id,colors=["Purple","Olive","Blue","Gray","Green","Silver","Teal","Red","Fuchsia","Aqua","Yellow"]){let elem=$(id);elem.empty(),elem.append('');for(let color of colors)elem.append($("").val(color).text(color).css("background-color",color))},setSceneInfo:function(id){if(void 0!==id){Util.enableTab(Common_SCENE_INDEX);let scene=Util.getSceneById(id);$("#scene-select #id").val(scene.id),$("#scene-select #summary").val(scene.summary),$("#scene-select #end").val(scene.end),$("#scene-select #items").val(scene.items),$("#scene-select #flags").val(scene.flags),$("#scene-select #params").val(scene.params),$("#scene-select #enemies").val(scene.enemies),$("#scene-select #dice").val(scene.dice),$("#scene-select #result").val(scene.result),$("#scene-select #nexts").val(scene.nexts),$("#scene-select #rule").val(scene.rule),$("#scene-select #bgm").val(scene.bgm),$("#scene-select #se").val(scene.se),$("#scene-select #hp").val(scene.hp),$("#scene-select #mp").val(scene.mp),$("#scene-select #state").val(scene.state),$("#scene-select #str").val(scene.str),$("#scene-select #int").val(scene.int),$("#scene-select #dex").val(scene.dex),$("#scene-select #krm").val(scene.krm),$("#scene-select #stars").val(scene.stars),$("#scene-select #free1").val(scene.free1),$("#scene-select #free2").val(scene.free2),$("#scene-select #free3").val(scene.free3),$("#scene-select #hp_max").val(scene.hp_max),$("#scene-select #mp_max").val(scene.mp_max),$("#scene-select #str_max").val(scene.str_max),$("#scene-select #int_max").val(scene.int_max),$("#scene-select #dex_max").val(scene.dex_max),$("#scene-select #krm_max").val(scene.krm_max),$("#scene-select #fixed").prop("checked",!!scene.fixed),$("#scene-select #exclude").prop("checked",!!scene.exclude),$("#scene-select #exclude").prop("checked",!!scene.exclude),$("#scene-select #color").val(scene.color),scene.text?editor.setValue(scene.text):editor.setValue(""),editor.focus(),editor.clearSelection(),Util.createLinkList(id)}},getEdgeById:function(id){return scenario.edges.find((function(elem){return elem.id===id}))},setEdgeInfo:function(id){Util.enableTab(Common_EDGE_INDEX);let edge=Util.getEdgeById(id);$("#edge #id").val(edge.id),$("#edge #from").val(edge.from),$("#edge #to").val(edge.to),$("#edge #order").val(edge.order),$("#edge #label").val(edge.label),$("#edge #condition").val(edge.condition),$("#edge #type").val(edge.type),$("#edge #correct").val(edge.correct),$("#edge #cache").val(edge.cache)},objToElement:function(name,data){let flag=!1,result=$(`<${name}>`);for(let key of Object.keys(data))void 0!==data[key]&&""!==data[key]&&("text"===key?result.text(data[key]):"label"===key||"X"===key||"y"===key||result.attr(key,data[key]),flag=!0);return!!flag&&result},createNetwork:function(opts={}){(opts=Object.assign({level:!0,focus_id:null,fit:!1},opts)).level&&Util.updateLevel();let scale=1;network&&(scale=network.getScale()),Util.destroyNetwork(),0===filter_where.length&&(filter_where=[{start:0,end:99999}]),network=new vis.Network(document.getElementById("flow-area"),{autoResize:!1,nodes:new vis.DataSet(scenario.scenes.filter((function(value){let result=!1;for(let cond of filter_where)if(Number(cond.start)<=Number(value.id)&&Number(value.id)<=Number(cond.end)){result=!0;break}return result}))),edges:new vis.DataSet(scenario.edges)},{physics:!1,interaction:{hover:!0},groups:{prologue:{color:"#3f0"},happy:{color:"#ffc"},bad:{color:"#96f"}},layout:{improvedLayout:!1,hierarchical:{enabled:!0,levelSeparation:100,nodeSpacing:100,blockShifting:!0,edgeMinimization:!0,direction:"UD",sortMethod:"directed",treeSpacing:70}},manipulation:{enabled:!1,addNode:function(data,callback){document.getElementById("node-add").onclick=function(data,callback){if(data.id=$("#node-id").val(),data.summary=$("#node-summary").val(),data.label=data.id+":\n"+data.summary,scenario.scenes.some((function(value){return value.id===data.id})))return window.alert("重複したidは登録できません。"),void callback(null);{$("#scene-dialog").dialog("close"),scenario.scenes.push(data),scenario.scenes.sort((m,n)=>Number(m.id)-Number(n.id)),callback(data);let tmp_pos=network.getViewPosition();network.moveNode(data.id,tmp_pos.x,tmp_pos.y)}}.bind(this,data,callback),document.getElementById("node-cancel").onclick=function(){$("#scene-dialog").dialog("close")},$("#scene-dialog").dialog("open")},addEdge:function(data,callback){scenario.edges.push(data),callback(data)},editEdge:function(data,callback){let edge=Util.getEdgeById(data.id);edge.from=data.from,edge.to=data.to,Util.disableTab(),callback(data)},deleteNode:function(data,callback){if(confirm("Sceneを削除しても良いですか?")){let node=Util.getSceneById(data.nodes[0]);if(0===Number(node.id))return window.alert("id=0のノードは削除できません。"),void callback(null);scenario.scenes=scenario.scenes.filter((function(value){return value.id!==node.id})),scenario.edges=scenario.edges.filter((function(value){return value.from!==node.id&&value.to!==node.id})),Util.disableTab(),callback(data)}else callback(null)},deleteEdge:function(data,callback){if(confirm("Edgeを削除しても良いですか?")){for(ed of data.edges)scenario.edges=scenario.edges.filter((function(value){return console.log(value),console.log(ed),console.log("----"),value.id!==ed}));Util.disableTab(),callback(data)}else callback(null)}},locale:"ja",locales:{ja:{edit:"Edit",del:"Delete Selected",back:"Back",addNode:"Add Scene",addEdge:"Add Link",editNode:"Edit Scene",editEdge:"Edit Link",addDescription:"Click in an empty space to place a new scene.",edgeDescription:"Click on a scene and drag the link to another scene to connect them.",editEdgeDescription:"Click on the control points and drag them to a scene to connect to it.",createEdgeError:"Cannot link edges to a cluster.",deleteClusterError:"Clusters cannot be deleted.",editClusterError:"Clusters cannot be edited."}},nodes:{shape:"box",size:20,font:{size:12},color:{background:"skyblue",highlight:{border:"#f00",background:"#f90"}}},edges:{arrows:"to",smooth:{enabled:!0,type:"curvedCCW",roundness:.1},font:{size:12,color:"rgba(0,0,0,0)",strokeWidth:0},chosen:{label:function(values){values.color="#f00",values.strokeWidth=2,values.mod="bold"}},color:{color:"skyblue",hover:"#f90",highlight:"#f00"}}}),network.moveTo({scale:scale}),opts.focus_id&&(network.focus(opts.focus_id),network.selectNodes([opts.focus_id])),opts.fit&&network.fit(),network.on("selectNode",(function(e){let id=this.getNodeAt(e.pointer.DOM);Util.setSceneInfo(id)})),network.on("selectEdge",(function(e){if(0!==e.nodes.length)return;let id=network.getEdgeAt(e.pointer.DOM);void 0!==id&&Util.setEdgeInfo(id)})),network.on("oncontext",(function(e){let org_e=e.event;$("#scene-select #id").val()===e.nodes[0]&&($("#chart-menu").css({display:"block",top:org_e.pageY,left:org_e.pageX}),org_e.preventDefault())}))},destroyNetwork:function(){null!==network&&(network.destroy(),network=null)},createGrid:function(selector,data,cols,opts,helpName,checkid=!0){void 0===data&&(data=[]);let grid=new Slick.Grid(selector,data,cols,opts);return grid.setSelectionModel(new Slick.CellSelectionModel),grid.onClick.subscribe((function(e,args){$(e.target).hasClass("btn-delete")&&(data.splice(args.row,1),grid.invalidate())})),grid.onCellChange.subscribe((function(e,args){0===args.cell&&(isUpdatedInGrid=!0)})),grid.onAddNewRow.subscribe((function(e,args){let item=args.item;if(checkid){if(!item.id)return void toastr.error("idを入力してください。","Id Error");if(Util.isDuplicateId(item.id,data))return void toastr.error("idが重複しています。","Id Error")}grid.invalidateRow(data.length),data.push(item),grid.updateRowCount(),grid.render(),isUpdatedInGrid=!0})),grid.onHeaderClick.subscribe((function(e,args){Util.showHelpDialog(`${helpName}/${args.column.id}`)})),grid},validateId:function(value,prefix,name,name_e){let msg="";return null==value||""===value.trim()?msg=`${name}のidは空にはできません。`:value.startsWith(prefix)?Util.isDuplicateId(value,scenario[name_e])&&(msg=`${name}のidが重複しています。`):msg=`${name}のidは「${prefix}~」形式で入力してください。`,msg?(toastr.error(msg,"Id Error"),{valid:!1,msg:msg}):{valid:!0,msg:null}},createAllGrid(){let grid_opts={editable:!0,enableAddRow:!0,enableCellNavigation:!0,asyncEditorLoading:!1,autoEdit:!1};grid.groups=Util.createGrid("#groups_grid",scenario.groups,[{id:"start",name:"開始No.",field:"start",width:70,editor:Slick.Editors.Integer},{id:"end",name:"終了No.",field:"end",width:70,editor:Slick.Editors.Integer},{id:"title",name:"グループ名",field:"title",width:250,editor:Slick.Editors.Text},{id:"rule",name:"ルールid",field:"rule",width:70,editor:Slick.Editors.Integer},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"group",!1),grid.items=Util.createGrid("#items_grid",scenario.items,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"i","アイテム","items")}},{id:"name",name:"名前",field:"name",width:80,editor:Slick.Editors.Text},{id:"target",name:"効果対象",field:"target",width:60,editor:SelectEditor,options:["","hp","mp","state","str","int","dex","krm","free1","free2","free3","param","none"]},{id:"effect",name:"効果値",field:"effect",width:80,editor:Slick.Editors.Text},{id:"text",name:"説明",field:"text",width:250,editor:Slick.Editors.Text},{id:"shared",name:"共有",field:"shared",width:50,editor:SelectEditor,options:["","true"]},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"item"),grid.flags=Util.createGrid("#flags_grid",scenario.flags,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"f","フラグ","flags")}},{id:"text",name:"説明",field:"text",width:300,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"flag"),void 0===scenario.params&&(scenario.params=[]),grid.params=Util.createGrid("#params_grid",scenario.params,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"p","内部パラメーター","params")}},{id:"min",name:"最小値",field:"min",width:60,editor:Slick.Editors.Text},{id:"max",name:"最大値",field:"max",width:60,editor:Slick.Editors.Text},{id:"initial",name:"初期値",field:"initial",width:60,editor:Slick.Editors.Text},{id:"text",name:"説明",field:"text",width:300,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"param"),grid.enemies=Util.createGrid("#enemies_grid",scenario.enemies,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"m","モンスター","enemies")}},{id:"name",name:"名前",field:"name",width:80,editor:Slick.Editors.Text},{id:"element",name:"属性",field:"element",editor:SelectEditor,options:["","earth","water","fire","wind","spirit"]},{id:"attack",name:"攻撃",field:"attack",width:80,editor:SelectEditor,options:["","physics","magic","both","free1","free2","free3","poison","frozen","stone","curse","forget","str","int","dex","krm"]},{id:"func",name:"ダメージ式",field:"func",width:80,editor:Slick.Editors.LongText,validator:function(value){if(value.includes("<")){let msg="ダメージ式では「<」ではなく「>」を利用してください。";return toastr.error(msg,"Func Error"),{valid:!1,msg:msg}}if(value.includes("ML")||value.includes("MR")){let msg="「ML」は「LM」、「MR」は「RM」です。";return toastr.error(msg,"Func Error"),{valid:!1,msg:msg}}return{valid:!0,msg:null}}},{id:"drop",name:"ドロップ",field:"drop",width:80,editor:AutoCompleteEditor,dataSource:["mon/","tue/","wed/","thu/","fri/","sat/","sun/","free1/","free2/","free3"]},{id:"text",name:"説明",field:"text",width:180,editor:Slick.Editors.LongText},{id:"hp",name:"敵HP",field:"hp",width:40,editor:Slick.Editors.Text},{id:"func_opp",name:"敵ダメージ式",field:"func_opp",width:90,editor:Slick.Editors.LongText},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"enemy"),grid.results=Util.createGrid("#results_grid",scenario.results,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"r","実績","results")}},{id:"name",name:"名前",field:"name",width:100,editor:Slick.Editors.Text},{id:"level",name:"Lv.",field:"level",width:30,editor:SelectEditor,options:["1","2","3","4","5"]},{id:"text",name:"説明",field:"text",width:150,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"result"),grid.works=Util.createGrid("#works_grid",scenario.licence,[{id:"name",name:"名前",field:"name",width:100,editor:Slick.Editors.Text},{id:"category",name:"分類",field:"category",width:70,editor:SelectEditor,options:["","bgm","picture"]},{id:"creator",name:"作者",field:"creator",width:80,editor:Slick.Editors.Text},{id:"url",name:"URL",field:"url",width:230,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"work",!1)},createSelectSidebar:function(trigger,target,member,type,label,value,onSubmit){let dataset=scenario[member];"groups"===member&&(dataset=[{start:0,end:99999,title:"フィルター解除"}].concat(dataset)),Util.createSelectSidebarForDataset(trigger,target,dataset,type,label,value,onSubmit)},createSelectSidebarForDataset:function(trigger,target,dataset,type,label,value,onSubmit){let s_name=`sidr_${target}`,s_list=`#${s_name} #${s_name}_list`,s_submit=`#${s_name} #${s_name}_submit`,s_cancel=`#${s_name} #${s_name}_close`,s_lead=`#${s_name} .btn-lead`;$(trigger).sidr({name:s_name,displace:!1,onOpen:function(){let v_dataset;$(s_list).empty(),v_dataset="function"==typeof dataset?dataset():dataset;for(let obj of v_dataset){let elem,v_label,v_value;switch(v_label="function"==typeof label?label(obj):obj[label],v_value="function"==typeof value?value(obj):obj[value],type){case"check":elem=`
  • \n \n
  • `;break;case"radio":elem=`
  • \n \n
  • `;break;case"plus_minus":elem=`\n \n \n \n ${v_label}\n \n \n \n `;break;case"inputs":elem=`\n ${v_label}\n \n \n \n `;break;case"sort":elem=`
  • \n
    ${v_label}
    \n
  • `;break;default:throw new Error("type属性の値が不正です。")}$(s_list).append(elem)}"sort"===type&&$(s_list).sortable({forcePlaceholderSize:!0,cursor:"move",opacity:.2}),dataset.length>30?$(s_lead).show():$(s_lead).hide(),$(`${s_list} .sidr-item`).checkboxradio({icon:!1})}}),$(s_submit).click((function(){let result;switch(type){case"check":result=[],$(`${s_list} .sidr-item:checked`).each((function(){result.push($(this).val())})),result=result.join(",");break;case"radio":result=$(`${s_list} .sidr-item:checked`).val();break;case"plus_minus":result=[],$(`${s_list} .sidr_${target}_plus:checked`).each((function(){result.push($(this).val())})),$(`${s_list} .sidr_${target}_minus:checked`).each((function(){result.push("-"+$(this).val())})),result=result.join(",");break;case"inputs":result=[],$(`${s_list} .sidr-elem input[type="text"]`).each((function(){let v=$(this).val();if(void 0!==v&&""!==v.trim()){let id=$(this).attr("id");result.push(`${id.split("_")[1]}:${v}`)}})),result=result.join(",")}onSubmit?onSubmit(result,trigger,s_list):$(trigger).val(result).trigger("input"),$.sidr("close",s_name)})),$(s_cancel).click((function(){$.sidr("close",s_name)}))},closeAllSidebar(){$(".mysidr").each((function(index,e){$.sidr("close",$(e).attr("id"))}))},createQuestLink:function(group){let tmp_correct="",tmp_to=[];for(let value of group)value.correct?(tmp_to[0]=value.to,tmp_correct=value.correct):tmp_to[1]=value.to;return`[${tmp_correct},${tmp_to.join(",")}](Q)`},createFreeLink:function(group){let tmp_to=[];for(let value of group)tmp_to.push(value.to);return`[${tmp_to.join(",")}](X)`},createRandomLink:function(group){let tmp_label="",tmp_cache="",tmp_condition="",tmp_to=[];for(let value of group)value.cache&&(tmp_cache=value.cache),value.condition&&(tmp_condition=value.condition),value.label&&(tmp_label=value.label),tmp_to.push(value.to);let to=tmp_to.join(",");return tmp_cache&&(to+=`;${tmp_cache}`),tmp_condition?`[${tmp_label}](${to} "${tmp_condition}")`:`[${tmp_label}](${to})`},createStandardLink:function(link){return link.condition?`[${link.label}](${link.to} "${link.condition}")`:`[${link.label}](${link.to})`},createMoveButton:function(id){let result=[],output=[];scenario.edges.filter((function(value){return value.from===id})).sort((function(v1,v2){return v1.order||(v1.order=0),v2.order||(v2.order=0),Number(v1.order)-Number(v2.order)})).forEach((function(value){let last_out=output[output.length-1];last_out&&last_out[0].order===value.order?last_out.push(value):output.push([value])}));for(let group of output)switch(group[0].type){case"Q":result.push(Util.createQuestLink(group));break;case"X":result.push(Util.createFreeLink(group));break;case"R":result.push(Util.createRandomLink(group));break;default:for(let link of group)result.push(Util.createStandardLink(link))}return 0===result.length&&(Util.getSceneById(id).end||console.warn(`No Link: ${id}`)),result.join("\n")},enableTab:function(id){$("#edit-area").tabs("enable",id).tabs("option","active",id)},disableTab:function(){$("#edit-area").tabs("option","active",0).tabs("option","disabled",[Common_SCENE_INDEX,Common_EDGE_INDEX])},createXml:function(){let result=$(''),inits=$(""),groups=$(""),items=$(""),flags=$(""),params=$(""),enemies=$(""),results=$(""),licence=$("");result.attr("title",scenario.title),result.attr("author",scenario.author);let basic=Util.objToElement("basic",scenario.init.basic);basic&&inits.append(basic);let constraint=Util.objToElement("constraint",scenario.init.constraint);constraint&&inits.append(constraint);let bgm=Util.objToElement("bgm",scenario.init.bgm);bgm&&inits.append(bgm);let label=Util.objToElement("label",scenario.init.label);label&&inits.append(label);let intro=Util.objToElement("intro",scenario.init.intro);intro&&inits.append(intro),result.append(inits);for(let t_group of scenario.groups){let group=Util.objToElement("group",t_group);group&&groups.append(group)}result.append(groups);for(let t_item of scenario.items){let item=Util.objToElement("item",t_item);item&&items.append(item)}result.append(items);for(let t_flag of scenario.flags){let flag=Util.objToElement("flag",t_flag);flag&&flags.append(flag)}result.append(flags);for(let t_param of scenario.params){let param=Util.objToElement("param0",t_param);param&¶ms.append(param)}result.append(params);for(let t_enemy of scenario.enemies){let enemy=Util.objToElement("enemy",t_enemy);enemy&&enemies.append(enemy)}result.append(enemies);for(let t_result of scenario.results){let result=Util.objToElement("result",t_result);result&&results.append(result)}result.append(results);for(let t_work of scenario.licence){let work=Util.objToElement("work",t_work);work&&licence.append(work)}result.append(licence);for(let t_scene of scenario.scenes){let scene=Util.objToElement("scene",t_scene);scene.text(scene.text()+"\n\n"+Util.createMoveButton(scene.attr("id"))),scene&&result.append(scene)}return vkbeautify.xml('\n'+result.get(0).outerHTML.replace(//gi,"").replace(/<\/param0>/gi,""))},elementToObj:function(obj,isLabel){let result={},t_obj=obj.get(0);if(t_obj){let attrs=t_obj.attributes;for(let attr of attrs)result[attr.name]=attr.value;t_obj.textContent&&(result.text=t_obj.textContent),isLabel&&(result.label=t_obj.id+":\n"+t_obj.getAttribute("summary"))}return result},setGroupByEnd(attr_end,obj){switch(attr_end){case"happy":obj.group="happy";break;case"bad":obj.group="bad";break;default:delete obj.group}},createJson(data){let result=$.extend(!0,{},Common_INIT_DATA_EMPTY),parser,s_data=(new DOMParser).parseFromString(data,"text/xml");result.title=$("scenario",s_data).attr("title"),result.author=$("scenario",s_data).attr("author"),result.init.basic=Util.elementToObj($("init > basic",s_data)),result.init.constraint=Util.elementToObj($("init > constraint",s_data)),result.init.bgm=Util.elementToObj($("init > bgm",s_data)),result.init.label=Util.elementToObj($("init > label",s_data)),result.init.intro=Util.elementToObj($("init > intro",s_data)),$("groups > group",s_data).each((function(i,elem){result.groups.push(Util.elementToObj($(elem)))})),$("items > item",s_data).each((function(i,elem){result.items.push(Util.elementToObj($(elem)))})),$("flags > flag",s_data).each((function(i,elem){result.flags.push(Util.elementToObj($(elem)))})),$("params > param",s_data).each((function(i,elem){result.params.push(Util.elementToObj($(elem)))})),$("enemies > enemy",s_data).each((function(i,elem){result.enemies.push(Util.elementToObj($(elem)))})),$("results > result",s_data).each((function(i,elem){result.results.push(Util.elementToObj($(elem)))})),$("licence > work",s_data).each((function(i,elem){result.licence.push(Util.elementToObj($(elem)))}));var link=/\[(.+?)\]\(([\dQX,;]{1,})(?: "(.+?)")?\)/gi;return $("scene",s_data).each((function(i,elem){let body=$(elem).text(),order=0;for(;null!==(link_result=link.exec(body));){order++;let tmp_to=link_result[2],tmp_condition=link_result[3]?link_result[3]:"",tmp_label=link_result[1];switch(tmp_to){case"Q":tmp_label=tmp_label.split(","),result.edges.push({from:elem.id,to:tmp_label[1],label:"",type:"Q",correct:tmp_label[0],order:order}),result.edges.push({from:elem.id,to:tmp_label[2],label:"",type:"Q",order:order});break;case"X":tmp_label=tmp_label.split(",");for(let tmp of tmp_label)result.edges.push({from:elem.id,to:tmp,label:"",type:"X",order:order});break;default:if(-1===tmp_to.indexOf(","))result.edges.push({from:elem.id,to:tmp_to,label:tmp_label,condition:tmp_condition,order:order});else{tmp_cache=tmp_to.split(";"),tmp_to=tmp_cache[0].split(","),tmp_cache=tmp_cache[1],is_first=!0;for(let tmp of tmp_to){let tmp_link={from:elem.id,to:tmp,label:tmp_label,type:"R",condition:tmp_condition,order:order};is_first&&(tmp_link.cache=tmp_cache,is_first=!1),result.edges.push(tmp_link)}}}}let s_obj=Util.elementToObj($(elem).text(body.replace(link,"").trimEnd()),!0);0===Number(s_obj.id)?s_obj.group="prologue":s_obj.end&&Util.setGroupByEnd(s_obj.end,s_obj),result.scenes.push(s_obj)})),JSON.stringify(result)},numToKanji:function(nums){let result="",tbl={1:"一",2:"二",3:"三",4:"四",5:"五",6:"六",7:"七",8:"八",9:"九",0:"〇"};for(num of String(nums))result+=tbl[num];return result},createLinkTag:function(id,edges){let result=[];return edges.forEach((function(value){value.from===id&&result.push(`[${value.label} ${Util.numToKanji(value.to)}へ]`)})),result.join("
    ")},createHtml(){let html=$("").append($("").append($("").attr("charset","UTF-8")).append($("").text(scenario.title)).append($("").text("body {\n writing-mode: vertical-rl;\n text-orientation: upright;\n }"))),body=$("");return scenario.scenes.forEach((function(value){$('
    ').attr("id",value.id).html("

    【"+Util.numToKanji(value.id)+"】

    "+marked(value.text)+"

    "+Util.createLinkTag(value.id,scenario.edges)+"


    ").appendTo(body)})),html.append(body),""+html.get(0).outerHTML},createLinkText:function(id,edges){let result=[];return edges.forEach((function(value){value.from===id&&result.push(`[${value.label} ${Util.numToKanji(value.to)}へ]`)})),result.join("\n\n")},createEpub:function(){let result="";scenario.scenes.forEach((function(value){result+=`【${Util.numToKanji(value.id)} 】\n\n${value.text}\n\n${Util.createLinkText(value.id,scenario.edges)}\n\n==============\n\n`})),result+="\n# 付録\n\n## 敵情報\n\n名前|属性|攻撃|概要\n----|----|----|----\n";let elem={"":"無",earth:"地",fire:"火",water:"水",wind:"風",spirit:"霊"},atk={physics:"物理",magic:"魔法",both:"物理/魔法",str:"STR",int:"INT",dex:"DEX",krm:"KRM",free1:"FREE1",free2:"FREE2",free3:"FREE3"};return scenario.enemies.forEach((function(value){result+=`${value.name}|${elem[value.element]}|${atk[value.attack]}|${value.text}\n`})),result+="\n\n## アイテム情報\n\n名前|概要\n----|----\n",scenario.items.forEach((function(value){result+=`${value.name}|${value.text}\n`})),result+="\n\n## 実績情報\n\n名前|Lv|概要\n----|----|----\n",scenario.results.forEach((function(value){result+=`${value.name}|${Util.numToKanji(value.level)}|${value.text}\n`})),result},download:function(content,name){var blob=new Blob([content],{type:"application/octet-stream"}),anchor=document.createElement("a");anchor.href=window.URL.createObjectURL(blob),anchor.download=name,document.body.appendChild(anchor),anchor.click(),document.body.removeChild(anchor)}},global_config=Util.loadConfig(),scenario;localStorage.editor2flow&&(sessionStorage.setItem(Common_LOAD_NAME,Util.createJson(localStorage.editor2flow)),localStorage.removeItem("editor2flow"));try{scenario=JSON.parse(sessionStorage.getItem(Common_LOAD_NAME)),sessionStorage.removeItem(Common_LOAD_NAME)}catch(e){console.log(e)}scenario||(scenario=$.extend(!0,{},Common_INIT_DATA),scenario.author=global_config.author),scenario.init.basic||(scenario.init.basic={}),scenario.params||(scenario.params=[]),Util.sortScenario(),Util.createNetwork({fit:!0}),$("#title").val(scenario.title),$("#author").val(scenario.author),$("#basic-summary").prop("checked",!!scenario.init.basic.summary),$("#basic-imgset").prop("checked",!!scenario.init.basic.imgset),$("#constraint-race").val(scenario.init.constraint.race),$("#constraint-sex").val(scenario.init.constraint.sex),$("#constraint-age").val(scenario.init.constraint.age),$("#bgm-main").val(scenario.init.bgm.main),$("#bgm-happy").val(scenario.init.bgm.happy),$("#bgm-bad").val(scenario.init.bgm.bad),$("#label-hp").val(scenario.init.label.hp),$("#label-mp").val(scenario.init.label.mp),$("#label-state").val(scenario.init.label.state),$("#label-str").val(scenario.init.label.str),$("#label-int").val(scenario.init.label.int),$("#label-dex").val(scenario.init.label.dex),$("#label-krm").val(scenario.init.label.krm),$("#label-free1").val(scenario.init.label.free1),$("#label-free2").val(scenario.init.label.free2),$("#label-free3").val(scenario.init.label.free3),$("#intro-keywords").val(scenario.init.intro.keywords),$("#intro-description").val(scenario.init.intro.description),$("#basic input").on("input",(function(e){let id=e.target.id.split("-");1===id.length?scenario[id[0]]=$(this).val():(scenario.init[id[0]][id[1]]=$(this).val(),"summary"!==id[1]&&"imgset"!==id[1]||$(this).prop("checked")||(scenario.init[id[0]][id[1]]=void 0))})),$(".sidr-race-item, .sidr-age-item, .sidr-sex-item").checkboxradio({icon:!1}),$("#basic #constraint-race").sidr({name:"sidr_races",displace:!1}),$("#sidr_races_submit").click((function(){let result=[];$(".sidr-race-item:checked").each((function(){result.push($(this).val())})),$("#basic #constraint-race").val(result.join(",")).trigger("input"),$.sidr("close","sidr_races")})),$("#sidr_races_close").click((function(){$.sidr("close","sidr_races")})),$("#basic #constraint-age").sidr({name:"sidr_ages",displace:!1}),$("#sidr_ages_submit").click((function(){let result=[];$(".sidr-age-item:checked").each((function(){result.push($(this).val())})),$("#basic #constraint-age").val(result.join(",")).trigger("input"),$.sidr("close","sidr_ages")})),$("#sidr_ages_close").click((function(){$.sidr("close","sidr_ages")})),$("#basic #constraint-sex").sidr({name:"sidr_sexes",displace:!1}),$("#sidr_sexes_submit").click((function(){let result=[];$(".sidr-sex-item:checked").each((function(){result.push($(this).val())})),$("#basic #constraint-sex").val(result.join(",")).trigger("input"),$.sidr("close","sidr_sexes")})),$("#sidr_sexes_close").click((function(){$.sidr("close","sidr_sexes")})),$("#basic #bgm-main-ref").click((function(e){$("#basic #bgm-main-file").click()})),$("#basic #bgm-main-file").change((function(e){let name=$(this).get(0).files[0].name;$("#basic #bgm-main").val(name.substring(0,name.lastIndexOf(".mp3"))).trigger("input")})),$("#basic #bgm-happy-ref").click((function(e){$("#basic #bgm-happy-file").click()})),$("#basic #bgm-happy-file").change((function(e){let name=$(this).get(0).files[0].name;$("#basic #bgm-happy").val(name.substring(0,name.lastIndexOf(".mp3"))).trigger("input")})),$("#basic #bgm-bad-ref").click((function(e){$("#basic #bgm-bad-file").click()})),$("#basic #bgm-bad-file").change((function(e){let name=$(this).get(0).files[0].name;$("#basic #bgm-bad").val(name.substring(0,name.lastIndexOf(".mp3"))).trigger("input")})),$("#basic label, #scene label, .dynamic_help").dblclick((function(e){Util.showHelpDialog($(this).attr("data-help"))})),$("#basic label > input, #basic label > select, #scene label > input, #scene label > select").dblclick((function(e){e.stopPropagation()})),$("#help-dialog").dialog({autoOpen:!1,width:640,minHeight:300,maxHeight:500,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"center top",my:"left top"},open:function(){},buttons:{"閉じる":function(){$(this).dialog("close"),Util.closeAllSidebar()}}}),$("#pg-config").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#config-author").val(global_config.author),$("#config-disp").val(global_config.disp),$("#config-incre").val(global_config.increment)},buttons:{"確定":function(){global_config.author=$("#config-author").val(),global_config.disp=$("#config-disp").val(),global_config.increment=$("#config-incre").val(),$("#ctrl_incre").val(global_config.increment),Util.saveConfig(global_config),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}}}),$("#scene-dialog").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#node-id").val(""),$("#node-summary").val("")}}),$("#scene-dialog-link").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#node-link-id").val(Util.nextScene($("#scene-attr #id").val())),$("#node-link-summary").val(""),$("#node-link-caption").val("次へ")},buttons:{"追加":function(){let from=$("#scene-attr #id").val(),id=$("#node-link-id").val();Util.addNode(id,$("#node-link-summary").val())&&($(this).dialog("close"),Util.addLink(from,id,$("#node-link-caption").val()),Util.createNetwork({focus_id:from}))},"キャンセル":function(){$(this).dialog("close")}}}),$("#scene-change-dialog").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#old-id").val($("#scene-attr #id").val()),$("#new-id").val("")},buttons:{"変更":function(){let old_id=$("#old-id").val(),new_id=$("#new-id").val();Util.isDuplicateScene(new_id)?Util.swapNodeId(old_id,new_id):Util.changeNodeId(old_id,new_id),Util.createNetwork({focus_id:new_id}),Util.setSceneInfo(new_id),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}}}),$("#edge-dialog").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#from-id").text($("#scene-select #id").val()),$("#edge-dialog #edge-caption").val("次へ"),$("#to-id").val(""),$("#edge-kind").val(""),$("#edge-add").val(""),$("#edge-correct").val("")},buttons:{"追加":function(){let from=$("#edge-dialog #from-id").text(),to=$("#edge-dialog #to-id").val(),label=$("#edge-dialog #edge-caption").val();label||(label="次へ");let kind=$("#edge-dialog #edge-kind").val(),add=$("#edge-dialog #edge-add").val(),correct=$("#edge-dialog #edge-correct").val();to?Util.isNewScene(to)?toastr.error("リンク先のidが存在しません。","不正な値"):!["R","X","Q"].includes(kind)||add?"Q"===kind&&add.includes(",")?toastr.error("追加情報には間違い時のリンク先を指定してください。
    \n 正解時のリンク先はid欄に指定します。","不正な値"):"Q"!==kind||correct?(Util.addLink(from,to,label,kind,add,correct),Util.createNetwork({focus_id:from}),Util.setSceneInfo(from),$(this).dialog("close")):toastr.error("[テキスト入力]選択時には、正解文字列は必須です。","不正な値"):toastr.error("通常以外のリンクでは追加情報は必須です。","不正な値"):toastr.error("リンク先のidは必須です。","不正な値")},"キャンセル":function(){$(this).dialog("close")}}}),$("#edge-dialog #edge-kind").change((function(){let v=$(this).val();$("#edge-dialog #edge-add").attr("placeholder",(function(){return""===v?"":"R"===v||"X"===v?"他のリンク先(カンマ区切り)":"Q"===v?"間違いの時のリンク先":void 0}))})),$("#range-dialog").dialog({autoOpen:!1,width:400,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},buttons:{"絞り込み":function(){Util.createNetwork({fit:!0}),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}},open:function(){}}),$("#epub-dialog").dialog({autoOpen:!1,width:650,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},buttons:{"エクスポート":function(){Util.download(Util.createEpub(),"scenario.txt"),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}}}),$("#upload-dialog").dialog({autoOpen:!1,width:800,show:500,hide:500,modal:!0,buttons:{"投稿":function(){let key=localStorage.getItem("pgflow_key");key||(key=(new Date).getTime().toString(16),localStorage.setItem("pgflow_key",key));let p={email:$("#upload-email").val(),tag:$("#upload-tag").val(),level:$("#upload-level").val(),intro:$("#upload-intro").val(),comment:$("#upload-comment").val(),ftp:$("#upload-ftp").prop("checked")?$("#upload-ftp").val():""};localStorage.setItem("pgflow_post",JSON.stringify(p));let data=new FormData;data.append("key",key),data.append("email",p.email),data.append("tag",p.tag),data.append("level",p.level),data.append("intro",p.intro),data.append("comment",p.comment),data.append("ftp",p.ftp),data.append("scenario",new Blob([Util.createXml()],{type:"text/xml"}),"scenario.xml");let bgms=$("#upload-bgms").get(0).files,ses=$("#upload-ses").get(0).files,pics=$("#upload-pics").get(0).files;for(let i=0;i work",data).each((function(){$("#sidr_links_result_s").append($("").attr("value",$(this).attr("id")).text($(this).attr("title"))),tmp_scenario_set.push({id:$(this).attr("id"),title:$(this).attr("title")})})),Util.createSelectSidebarForDataset("#scene-select #nexts","nexts",tmp_scenario_set,"check","title","id")})),$("#sidr_links_result_s").change((function(e){$.get(`../stext/${$(this).val()}/scenario.xml`).done((function(data){$("#sidr_links_result").empty().append(""),$("results > result",data).each((function(){$("#sidr_links_result").append($("").attr("value",$(this).attr("id")+":"+$("#sidr_links_result_s").val()).text($(this).attr("name")))}))}))})),$("#edge #condition").sidr({name:"sidr_links",displace:!1,onOpen:function(){$("#sidr_links_cond").val(""),$("#sidr_links_item").empty().append("");for(let item of scenario.items)$("#sidr_links_item").append(``);$("#sidr_links_flag").empty().append("");for(let flag of scenario.flags)$("#sidr_links_flag").append(``);$("#sidr_links_param").empty().append("");for(let param of scenario.params)$("#sidr_links_param").append(``)}}),$("#sidr_links_list select:not(.no-update)").change((function(){let cond=$("#sidr_links_cond");cond.val(cond.val()+$(this).val())})),$("#sidr_links button").click((function(){let cond=$("#sidr_links_cond");cond.val(cond.val()+$(this).val())})),$("#sidr_links_submit").click((function(){$("#edge #condition").val($("#sidr_links_cond").val()).trigger("input"),$.sidr("close","sidr_links")})),$("#sidr_links_close").click((function(){$.sidr("close","sidr_links")})),Util.createAllGrid();let editor=ace.edit("scene-editor");ace.config.loadModule("ace/ext/language_tools",(function(lang){editor.completers=[lang.snippetCompleter],editor.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0});const snippetManager=ace.require("ace/snippets").snippetManager,config=ace.require("ace/config");ace.config.loadModule("ace/snippets/markdown",(function(m){if(m){snippetManager.files.markdown=m;let s_list=[{title:"image",body:"![${1:text}](${2:file})"},{title:"title",body:"\\${title}"},{title:"name",body:"\\${name}"},{title:"job",body:"\\${job}"},{title:"hp",body:"\\${hp}"},{title:"mp",body:"\\${mp}"},{title:"str",body:"\\${str}"},{title:"int",body:"\\${int}"},{title:"dex",body:"\\${dex}"},{title:"krm",body:"\\${krm}"},{title:"free1",body:"\\${free1}"},{title:"free2",body:"\\${free2}"},{title:"free3",body:"\\${free3}"},{title:"race",body:"\\${race?${1:fighter}:${2:wizard}:${3:dwarf}:${4:elf}}"},{title:"sex",body:"\\${sex?${1:male}:${2:female}}"},{title:"state",body:"\\${state?${1:normal}:${2:poison}:${3:frozen}:${4:stone}:${5:forget}}"},{title:"age",body:"\\${age?${1:young}:${2:adult}:${3:old}}"},{title:"rand",body:"\\${rand?${1:min}:${2:max}}"},{title:"msg",body:"\\${msg?${1:arg1}:${2:arg2}:...}"},{title:"enemy:name",body:"\\${var?m${1:id}:name}"},{title:"enemy:element",body:"\\${var?m${1:id}:element}"},{title:"enemy:text",body:"\\${var?m${1:id}:text}"},{title:"result:name",body:"\\${var?r${1:id}:name}"},{title:"result:level",body:"\\${var?r${1:id}:level}"},{title:"result:text",body:"\\${var?r${1:id}:text}"},{title:"param:text",body:"\\${var?p${1:id}:text}"},{title:"param:value",body:"\\${var?p${1:id}:value}"},{title:"result:count",body:"\\${result?${1:id}}"},{title:"result:rate",body:"\\${result_rate?${1:id}}"},{title:"import",body:"\\${import ${1:id}}"},{title:"input",body:"\\${input?${1:init}}"},{title:"if",body:"\\${if ${1:condition}}${2:body}\\${/if}"},{title:"effect",body:"\\${effect ${1:type}}${2:body}\\${/effect}"},{title:"ruby",body:"\\${${1:word}|${2:ruby}}"},{title:"blue",body:"%blue%${1:body}%/%"},{title:"red",body:"%red%${1:body}%/%"},{title:"purple",body:"%purple%${1:body}%/%"},{title:"white",body:"%white%${1:body}%/%"},{title:"tweet",body:"\\${tweet}${1:body}\\${/tweet}"}];m.snippets=[];for(let item of s_list)m.snippets.push({content:item.body,name:item.title,tabTrigger:item.title});snippetManager.register(m.snippets,m.scope)}}))})),editor.$blockScrolling=1/0,editor.getSession().setUseWrapMode(!0),editor.setTheme("ace/theme/chrome"),editor.session.setMode("ace/mode/markdown"),editor.on("input",(function(e){let id=$("#scene-select #id").val();if(id){let scene;Util.getSceneById(id).text=editor.getValue()}})),$("#scene #scene-ext").click((function(e){let sa=$("#scene-attr"),se=$("#scene-editor");se.hasClass("editor-big")?($(this).text("エディター領域を拡げる"),sa.show(),se.removeClass("editor-big").css("height","210px"),editor.resize(!0)):($(this).text("エディター領域を狭める"),sa.hide(),se.addClass("editor-big").css("height","630px"),editor.resize(!0))})),$("#scene #scene-delscene, #ctx-scene-remove").click((function(){if(!confirm("この操作は元には戻せません!\n現在のシーンを削除しても構いませんか?"))return;let id=$("#scene-attr #id").val();Util.deleteScene(id),Util.createNetwork(),$("#chart-menu").css("display","none")})),$("#scene #edges-list").focus((function(e){let id=$("#scene-attr #id").val();Util.createLinkList(id)})),$("#scene #scene-addedge, #chart-menu #ctx-edge-add").click((function(e){$("#edge-dialog").dialog("open"),$("#chart-menu").css("display","none")})),$("#scene #scene-addscene, #chart-menu #ctx-scene-add").click((function(e){$("#scene-dialog-link").dialog("open"),$("#chart-menu").css("display","none")})),$("#scene #scene-changescene").click((function(e){"0"!==$("#scene-select #id").val()?$("#scene-change-dialog").dialog("open"):toastr.error("Scene 0は変更できません。","変更不可")})),Util.createColorList("#scene #color"),Util.createSelectSidebar("#edge-dialog #to-id","scene","scenes","radio","label","id"),Util.createSelectSidebar("#edge-dialog #edge-add","scenes","scenes","check","label","id"),$("#edge #edge-deledge").click((function(){if(!confirm("この操作は元には戻せません!\n現在のリンクを削除しても構いませんか?"))return;let id=$("#edge #id").val();Util.deleteLink(id),Util.createNetwork()})),$("#edit-area").tabs().tabs({activate:function(e,ui){let keys=Object.keys(grid);for(let key of keys)grid[key].navigateNext();isUpdatedInGrid&&(Util.sortScenario(),Util.createAllGrid(),isUpdatedInGrid=!1),Util.closeAllSidebar()}}),Util.disableTab(),$("#ctrl_run").click((function(e){localStorage.setItem(Common_RUN_NAME,Util.createXml()),-1===location.host.indexOf("web-deli.com")?window.open("../index.html?id=pg2",Common_RUN_NAME):window.open("../game.aspx?id=pg2",Common_RUN_NAME)})),$("#ctrl_tag").click((function(e){$("#tag-menu").css({display:"block",top:e.pageY,left:e.pageX})})),$("#tag-menu li").click((function(e){var command;let comm={red:"%red%$0%/%",blue:"%blue%$0%/%",white:"%white%$0%/%",if:"${if condition}$0${/if}","*import":"${import 99999}",effect:"${effect type}$0${/effect}","*input":"${input?0}",ruby:"${$0|ruby}","*title":"${title}","*name":"${name}","*race":"${race?FIG:WIZ:DWA:ELF}","*sex":"${sex?M:F}","*state":"${state?NOR:POI:FRO:STO:FOR}","*age":"${age?Y:A:O}","*var":"${var?key:prop}","*random":"${rand?min:max}","*msg":"${msg?str1:str2:...}",tweet:"${tweet}%0%${/tweet}","*capture":"![caption](path)"}[$(this).data("command")];comm.startsWith("*")?editor.insert(comm):editor.insert(comm.replace("$0",editor.getCopyText())),editor.focus(),$("#tag-menu").css("display","none")})),$("#ctrl_dl").click((function(e){$("#dl-menu").css({display:"block",top:e.pageY,left:e.pageX})})),$("#dl-menu li").click((function(e){switch($(this).data("command")){case"json":scenario.scenes.forEach((function(scene){delete scene.x,delete scene.y})),Util.download(vkbeautify.json(JSON.stringify(scenario)),"stext.json");break;case"xml":Util.download(Util.createXml(),"scenario.xml");break;case"html":Util.download(Util.createHtml(),"scenario.html");break;case"epub":$("#epub-dialog").dialog("open");break;case"storage":window.alert("データをブラウザーに保存しました。\n保存済みのデータは[マイストレージ]テンプレートからロードできます。"),localStorage.setItem(Common_MY_STORAGE,JSON.stringify(scenario));break;default:console.log("Unknown Error!!")}$("#dl-menu").css("display","none")})),$("#ctrl_help").click((function(e){$("#help-menu").css({display:"block",top:e.pageY,left:e.pageX})})),Util.createSelectSidebar("#ctrl_filter","groups","groups","check",(function(obj){return`${obj.title}
    (${obj.start}-${obj.end})`}),(function(obj){return`${obj.start}-${obj.end}`}),(function(result){filter_where=[];for(let cond of result.split(",")){if(!cond)break;let tmp_cond=cond.split("-");filter_where.push({start:tmp_cond[0],end:tmp_cond[1]})}Util.createNetwork({fit:!0})})),$("#ctrl_shuffle").click((function(){if(!confirm("全シーンidをシャッフルします。\nこの操作は元に戻せませんが、続けますか?"))return;let s=new StextShuffle(scenario);s.run(),Util.refreshScenario(s.scenario),Util.sortScenes(),Util.createNetwork({fit:!0}),Util.disableTab()})),$("#ctrl_config").click((function(){$("#pg-config").dialog("open")})),$("#ctrl_template").change((function(e){var selected=$(this).val();if("storage"===selected){var save=localStorage.getItem(Common_MY_STORAGE);save?(sessionStorage.setItem(Common_LOAD_NAME,save),location.reload()):window.alert("セーブデータは存在しません。")}else if(selected){let path;path=selected.startsWith("@")?`../stext/${selected.substring(1)}/scenario.xml`:`./template/${selected}`,$.ajax(path,{dataType:"text"}).done((function(data){selected.startsWith("@")&&(data=Util.createJson(data)),sessionStorage.setItem(Common_LOAD_NAME,data),location.reload()}))}})),$("#ctrl_import").click((function(e){$("#ctrl_load").click()})),$("#ctrl_load").change((function(e){let inputs=$(this).get(0).files,name=inputs[0].name,reader=new FileReader;$(reader).on("load",(function(){name.endsWith(".json")?sessionStorage.setItem(Common_LOAD_NAME,reader.result):sessionStorage.setItem(Common_LOAD_NAME,Util.createJson(reader.result)),location.reload()})),reader.readAsText(inputs[0],"UTF-8")})),$("#ctrl_scene").mousedown((function(e){$("#ctrl_scene").empty(),$("").attr("value","").text("編集するシーンを選択").appendTo("#ctrl_scene");for(let scene of scenario.scenes)label=scene.label,(0==scene.id||scene.end)&&(label="★"+label),$("").attr("value",scene.id).text(label).appendTo("#ctrl_scene")})),$("#ctrl_scene").change((function(e){let id=$(this).val();Util.setSceneInfo(id),network.selectNodes([id])})),$("#ctrl_addscene").click((function(e){let incre=Number(global_config.increment);(!incre||incre<1)&&(incre=1),incre=Math.floor(incre);let new_id=Number(Util.maxSceneId())+incre;scenario.scenes.push({id:String(new_id),summary:"New",label:`${new_id}:\nNew`,text:""}),Util.createNetwork()})),$(":not(.cxt)").click((function(e){"ctrl_dl"!==e.target.id&&$("#dl-menu").css("display","none"),"ctrl_help"!==e.target.id&&$("#help-menu").css("display","none"),"ctrl_tag"!==e.target.id&&$("#tag-menu").css("display","none"),"chart-menu"!==e.target.id&&$("#chart-menu").css("display","none")})),$("#ctrl_flow2editor").click((function(){localStorage.flow2editor=Util.createXml(),window.open("./editor.html","pgeditor")})),$(window).on("beforeunload",(function(){return"ページを閉じてもよろしいですか?"}));let tips=["フローチャート上では、プロローグ/エピローグ(happy/bad)を表すシーンが色で区別されています。目的のシーンを探す手掛かりになるでしょう。","フローチャート上では、シーン単位にカラーリングが可能です。下書き、重要なフラグのあるシーンなどをマーキングしておくと良いでしょう。","フローチャートで目的のシーンが探しにくい場合には、右上のシーン選択ボックスを利用してみましょう。シーンid順に表示されています。","フローチャートやシーン選択ボックス上では、サマリーテキストが表示されます。シーンごとにできるだけ判りやすい名前を付けましょう。","シーン選択ボックス上では、プロローグとエピローグが★でマーキングされています。目的のシーンを探す手掛かりになるでしょう。","フローチャート上のリンクが見難い場合には、[シーン]タブからリンク選択ボックスを利用してみましょう。","Playgroundのデータは、.json形式(Playgroundの内部形式)、.xml形式(STextの実行形式)などで保存できます。","Playgroundのデータは、.txt形式(でんでんコンバーター向け)にも出力できます。EPUB形式の電子書籍も手軽に作成が可能です。","scenario.xml(STextの実行形式)を.json形式(Playgroundの内部形式)に変換することも可能です。既存のシナリオをPlayground Flowにインポートして、どんどん動作確認してみましょう。","Playgroundでは、.html形式での出力もできます。条件分岐、音楽機能などは利用できなくなりますが、Kindle配信などしている人にも利用して戴けると嬉しいです。",".json形式(Playgroundの内部形式)のファイルは、Playground上部のファイル選択ボタンからインポート&編集できます。","Playground Flowでは、個々のシーンをNode、リンクをEdgeと呼びます。","シーンを跨ってテキストを一括置換したい場合には、Playground Editorに切り替えると良いでしょう。[Ctrl]+[H]でテキストの一括置き換えが可能です(正規表現にも対応)。","[PgEditorで編集]ボタンを押すことで現在編集中のシナリオをPlayground Editorで編集できます。","[シーン]タブからはもシーンを追加できます。その場合、現在のシーンからのリンクも自動生成されるので、積極的に利用していきましょう。","フォーム上のラベルをダブルクリックすることで、該当する項目のヘルプページを表示できます。","アイテム/フラグ編集のグリッドからタイトル行をダブルクリックすることで、該当する項目のヘルプページを表示できます。","フィルター機能を利用することで、フローチャートに表示するシーン範囲を限定し、大きなシナリオでも見やすく表示できます。","[シンプルサンプル]は、5Sceneの中にも、戦闘、フラグ、アイテム、実績、エンディングなどの基本機能を備えています。STextの基礎を見渡すのに便利です。","[20Sceneサンプル]は、単方向で分岐と移動の枠組みだけを備えたサンプルです。20Sceneあるので、簡単な物語ならば、テキストを追加するだけでシナリオができてしまいます。","[実践サンプル]は、実際に公開されているシナをテンプレートとして公開したものです。実際の物語がどんなしくみで実装されているのかを確認してみてください。","[機能テスト]は、STextの動作確認のためのテンプレート。リンク関係など判りにくい動作例を載せています。","[セーブ]ボタンではブラウザーに一時的にデータを保存できます。保存したデータは[マイストレージ]テンプレートから取り出せますよ。","Playground Flowは現在β版です。バグかなと思ったら、Twitter(@yy7512)までお知らせください。","Playground Flowは現在β版です。こんな機能あったらいいなと思ったら、Twitter(@yy7512)までお気軽にお寄せください。","Playground Flowは現在β版です。ご利用に際しては、データのバックアップ/保存を小まめに行うようにしてください。","アイテム/フラグなどの項目はid値について昇順で自動ソートされます。番号の大小が乱れた時は一度開き直すと良いでしょう。","シーンはフローチャートとからだけでなく、右上の選択ボックスからも選べます。プロローグ/エンディングには★が付いているので、探す時の手懸りにどうぞ。","シーンテキストを編集するエディターには様々なショートカットが用意されています。詳しくはヘルプを参照してください。","[シーン]タブから[アイテム][フラグ][敵][実績]欄にフォーカスすると、サイドバーが開いて、設定済みの情報を選択できます。","[シーン]タブから[HP]~[FREE3]欄にフォーカスすると、入力可能なオプションがリスト表示されます。","複数のリンクを順序決めしたい場合、[シーン]タブの[表示ソート]をクリックします。リンクの順序をドラッグ&ドロップで変更できます。","[リンク]タブから[条件式]欄にフォーカスすると、サイドパネルに条件式生成エディターが開きます。","現在のシーンに紐づいたシーンを新規作成したいならば、[シーン]タブから[シーン追加]ボタンをクリックします。","[シーン]タブでidの[変更]ボタンをクリックすると、新しいidを振ったり、既存のidとスワップしたりできます。","シーンidはシャッフルすることも可能です。.html、.txt形式の出力前には一度シャッフルすることをお勧めします。"];toastr.options.closeButton=!0,toastr.options.positionClass="toast-bottom-full-width",toastr.options.showDuration=300,toastr.options.hideDuration=1e3,toastr.options.preventDuplicates=!0,toastr.options.timeOut=7e3,toastr.info(tips[Math.floor(Math.random()*tips.length)],"TIPS")})); \ No newline at end of file +$((function(){class LevelResolver{constructor(scenario){this.scenario=scenario,this.level={},this.maxLevel=1}run(){let that=this,over=this.getEdgeCount();this.traceScenes(0,1),this.scenario.scenes.forEach((function(scene){let level=that.level[scene.id];scene.level=level||that.maxLevel,over.includes(scene.id)&&(scene.level=that.maxLevel+1)}))}traceScenes(id,level){let that=this,children;this.level[id]||(this.level[id]=level,this.getToScenes(id).forEach((function(scene){that.traceScenes(scene.id,level+1)})),this.maxLevel15&&result.push(id)})),Object.keys(to_id).forEach((function(id){to_id[id]>15&&result.push(id)})),result}}let network=null,filter_where=[],grid={},isUpdatedInGrid=!1,help_page,Common_HELP_URL="https://sorcerian.hateblo.jp/entry/2018/11/01/211745#",Common_SCENE_INDEX=8,Common_EDGE_INDEX=9,Common_MY_STORAGE="pg2_save",Common_LOAD_NAME="pg2_load",Common_RUN_NAME="pg2_run",Common_CONFIG_NAME="pgflow_config",Common_INIT_CONFIG={author:"Unnamed",disp:"auto",increment:10},Common_INIT_DATA_EMPTY={title:"",author:"",init:{basic:{},constraint:{},bgm:{},label:{},intro:{}},groups:[],items:[],flags:[],params:[],enemies:[],results:[],licence:[],scenes:[],edges:[]},Common_INIT_DATA={title:"Untitled",author:"Unnamed",init:{basic:{summary:"",imgset:""},constraint:{race:"",sex:"",age:""},bgm:{main:"",happy:"",bad:""},label:{free1:"",free2:"",free3:""},intro:{keywords:"",description:""}},groups:[{start:0,end:1,title:"Introduction",rule:""}],items:[{id:"i01",name:"Item-01",text:"Item description..."}],flags:[{id:"f01",text:"Flag description..."}],params:[{id:"p01",min:0,max:100,initial:50,text:"Param description..."}],enemies:[{id:"m01",name:"Enemy-01",element:"earth",attack:"physics",func:"L+R-STR",drop:"mon/2",text:"Enemy description..."}],results:[{id:"r01",name:"Result-01",level:1,text:"Result description..."}],licence:[{name:"Bgm-01",category:"bgm",creator:"SText",url:"https://example.com/"}],scenes:[{id:"0",summary:"プロローグ",label:"0:\nプロローグ",text:"ここにプロローグを書きます。",group:"prologue"},{id:"1",summary:"本文",label:"1:\n本文",text:"ここからが本文です。"}],edges:[{from:"0",to:"1",label:"次へ"}]},Util={refreshScenario:function(new_data){scenario=JSON.parse(JSON.stringify(new_data)),Util.createAllGrid()},loadConfig:function(){let conf=localStorage[Common_CONFIG_NAME];try{return conf?JSON.parse(conf):Common_INIT_CONFIG}catch(e){return Common_INIT_CONFIG}},saveConfig:function(data){return!!data&&(localStorage[Common_CONFIG_NAME]=JSON.stringify(data),!0)},updateLevel(){let lr=new LevelResolver(scenario);return lr.run(),lr.scenario},sortFn:function(m,n){try{return Number(m.id.substring(1))-Number(n.id.substring(1))}catch(e){return console.error(e),0}},transferQuery:function(selector){return selector.replace(/\//g," > ")},getHelpPage:function(selector){$.get("./lib/reference.xml").done((function(result){help_page=result,Util.showHelpDialog(selector)}))},showHelpDialog:function(selector){if(help_page){let el=$(Util.transferQuery(selector),help_page),txt=el.text(),ref=el.attr("ref");ref&&(txt+=$(Util.transferQuery(ref),help_page).text()),$("#help-dialog > #help-body").html(marked(txt)),$("#help-dialog").dialog("open")}else Util.getHelpPage(selector);Util.closeAllSidebar()},maxSceneId:function(){return Math.max.apply(null,scenario.scenes.map((function(s){return s.id>=9e4?0:s.id})))},sortScenario:function(){scenario.groups.sort((function(m,n){return Number(m.start)-Number(n.start)})),scenario.items.sort(Util.sortFn),scenario.flags.sort(Util.sortFn),scenario.enemies.sort(Util.sortFn),scenario.results.sort(Util.sortFn)},sortScenes:function(){scenario.scenes.sort((m,n)=>Number(m.id)-Number(n.id))},sortEdges:function(){scenario.edges.sort((m,n)=>{let m_from=Number(m.from),n_from=Number(n.from),m_order=Number(m.order),n_order=Number(n.order);return m_from!==n_from?m_from-n_from:m_order-n_order})},isDuplicateOrderedEdge:function(from,order){return scenario.edges.some((function(value){return Number(value.from)===Number(from)&&Number(value.order)===Number(order)}))},detectLinkOrder:function(from,start){for(;;){if(!Util.isDuplicateOrderedEdge(from,start))return start;start++}},isDuplicateId:function(id,data){return data.some((function(value){return value.id===id}))},isDuplicateScene:function(id){return scenario.scenes.some((function(value){return Number(value.id)===Number(id)}))},isNewScene:function(id){return!Util.isDuplicateScene(id)},nextScene:function(id){let next_id=Number(id);for(;;)if(next_id+=Number(global_config.increment),Util.isNewScene(next_id))return next_id},addNode:(id,summary)=>Util.isDuplicateScene(id)?(toastr.error("id値が重複しています。","不正なid"),!1):(scenario.scenes.push({id:String(id),summary:summary,label:`${id}:\n${summary}`,text:""}),Util.sortScenes(),!0),changeNodeId(old_id,new_id){scenario.scenes.forEach((function(scene){String(scene.id)===old_id&&(scene.id=new_id,scene.label=`${new_id}\n${scene.summary}`)})),scenario.edges.forEach((function(edge){String(edge.from)===old_id&&(edge.from=new_id),String(edge.to)===old_id&&(edge.to=new_id)}))},swapNodeId(old_id,new_id){scenario.scenes.forEach((function(scene){if(String(scene.id)===old_id)return scene.id=new_id,void(scene.label=`${new_id}\n${scene.summary}`);String(scene.id)===new_id&&(scene.id=old_id,scene.label=`${old_id}\n${scene.summary}`)})),scenario.edges.forEach((function(edge){let done_from=!1,done_to=!1;String(edge.from)===old_id&&(edge.from=new_id,done_from=!0),String(edge.to)===old_id&&(edge.to=new_id,done_to=!0),done_from||String(edge.from)!==new_id||(edge.from=old_id),done_to||String(edge.to)!==new_id||(edge.to=old_id)})),console.log(scenario)},generateLinkId:function(from,to){return`custom${from}-${to}-${Math.floor(1e5*Math.random())}`},addLink:function(from,to,label,kind="",add="",correct=""){let order=Util.detectLinkOrder(from,90);if(kind)if("R"===kind||"X"===kind){let tos=[];tos.push(to),tos=tos.concat(add.split(",")),tos=[...new Set(tos)];for(let tmp_to of tos)scenario.edges.push({from:from,to:tmp_to,label:label,type:kind,order:order,id:Util.generateLinkId(from,tmp_to)})}else"Q"===kind&&(scenario.edges.push({from:from,to:to,label:label,type:"Q",correct:correct,order:order,id:Util.generateLinkId(from,to)}),scenario.edges.push({from:from,to:add,label:label,type:"Q",order:order,id:Util.generateLinkId(from,add)}));else scenario.edges.push({from:from,to:to,label:label,id:Util.generateLinkId(from,to)})},deleteLink(id){let index=scenario.edges.findIndex((function(edge){return edge.id===id}));return scenario.edges.splice(index,1)},deleteScene(id){if(0==id)return void toastr.error("id=0のシーンは削除できません。","不正な操作");let index=scenario.scenes.findIndex((function(scene){return scene.id===id}));for(scenario.scenes.splice(index,1);;){let e_index=scenario.edges.findIndex((function(edge){return edge.from===id||edge.to===id}));if(console.log(e_index),-1===e_index)break;scenario.edges.splice(e_index,1)}return!0},getSceneById:function(id){return scenario.scenes.find((function(elem){return elem.id===id}))},createLinkList:function(id){$("#scene-select #edges-list").empty(),$("#scene-select #edges-list").append(''),Util.sortEdges(),scenario.edges.forEach((function(value){value.from===id&&$("").attr("value",value.id).text(`${value.to}: ${value.label}`).appendTo("#scene-select #edges-list")}))},createSortLinkList:function(id){return Util.sortEdges(),scenario.edges.filter((function(value){return value.from===id}))},createColorList:function(id,colors=["Purple","Olive","Blue","Gray","Green","Silver","Teal","Red","Fuchsia","Aqua","Yellow"]){let elem=$(id);elem.empty(),elem.append('');for(let color of colors)elem.append($("").val(color).text(color).css("background-color",color))},setSceneInfo:function(id){if(void 0!==id){Util.enableTab(Common_SCENE_INDEX);let scene=Util.getSceneById(id);$("#scene-select #id").val(scene.id),$("#scene-select #summary").val(scene.summary),$("#scene-select #end").val(scene.end),$("#scene-select #items").val(scene.items),$("#scene-select #flags").val(scene.flags),$("#scene-select #params").val(scene.params),$("#scene-select #enemies").val(scene.enemies),$("#scene-select #dice").val(scene.dice),$("#scene-select #result").val(scene.result),$("#scene-select #nexts").val(scene.nexts),$("#scene-select #rule").val(scene.rule),$("#scene-select #bgm").val(scene.bgm),$("#scene-select #se").val(scene.se),$("#scene-select #hp").val(scene.hp),$("#scene-select #mp").val(scene.mp),$("#scene-select #state").val(scene.state),$("#scene-select #str").val(scene.str),$("#scene-select #int").val(scene.int),$("#scene-select #dex").val(scene.dex),$("#scene-select #krm").val(scene.krm),$("#scene-select #stars").val(scene.stars),$("#scene-select #free1").val(scene.free1),$("#scene-select #free2").val(scene.free2),$("#scene-select #free3").val(scene.free3),$("#scene-select #hp_max").val(scene.hp_max),$("#scene-select #mp_max").val(scene.mp_max),$("#scene-select #str_max").val(scene.str_max),$("#scene-select #int_max").val(scene.int_max),$("#scene-select #dex_max").val(scene.dex_max),$("#scene-select #krm_max").val(scene.krm_max),$("#scene-select #fixed").prop("checked",!!scene.fixed),$("#scene-select #exclude").prop("checked",!!scene.exclude),$("#scene-select #exclude").prop("checked",!!scene.exclude),$("#scene-select #color").val(scene.color),scene.text?editor.setValue(scene.text):editor.setValue(""),editor.focus(),editor.clearSelection(),Util.createLinkList(id)}},getEdgeById:function(id){return scenario.edges.find((function(elem){return elem.id===id}))},setEdgeInfo:function(id){Util.enableTab(Common_EDGE_INDEX);let edge=Util.getEdgeById(id);$("#edge #id").val(edge.id),$("#edge #from").val(edge.from),$("#edge #to").val(edge.to),$("#edge #order").val(edge.order),$("#edge #label").val(edge.label),$("#edge #condition").val(edge.condition),$("#edge #type").val(edge.type),$("#edge #correct").val(edge.correct),$("#edge #cache").val(edge.cache)},objToElement:function(name,data){let flag=!1,result=$(`<${name}>`);for(let key of Object.keys(data))void 0!==data[key]&&""!==data[key]&&("text"===key?result.text(data[key]):"label"===key||"X"===key||"y"===key||result.attr(key,data[key]),flag=!0);return!!flag&&result},createNetwork:function(opts={}){(opts=Object.assign({level:!0,focus_id:null,fit:!1},opts)).level&&Util.updateLevel();let scale=1;network&&(scale=network.getScale()),Util.destroyNetwork(),0===filter_where.length&&(filter_where=[{start:0,end:99999}]),network=new vis.Network(document.getElementById("flow-area"),{autoResize:!1,nodes:new vis.DataSet(scenario.scenes.filter((function(value){let result=!1;for(let cond of filter_where)if(Number(cond.start)<=Number(value.id)&&Number(value.id)<=Number(cond.end)){result=!0;break}return result}))),edges:new vis.DataSet(scenario.edges)},{physics:!1,interaction:{hover:!0},groups:{prologue:{color:"#3f0"},happy:{color:"#ffc"},bad:{color:"#96f"}},layout:{improvedLayout:!1,hierarchical:{enabled:!0,levelSeparation:100,nodeSpacing:100,blockShifting:!0,edgeMinimization:!0,direction:"UD",sortMethod:"directed",treeSpacing:70}},manipulation:{enabled:!1,addNode:function(data,callback){document.getElementById("node-add").onclick=function(data,callback){if(data.id=$("#node-id").val(),data.summary=$("#node-summary").val(),data.label=data.id+":\n"+data.summary,scenario.scenes.some((function(value){return value.id===data.id})))return window.alert("重複したidは登録できません。"),void callback(null);{$("#scene-dialog").dialog("close"),scenario.scenes.push(data),scenario.scenes.sort((m,n)=>Number(m.id)-Number(n.id)),callback(data);let tmp_pos=network.getViewPosition();network.moveNode(data.id,tmp_pos.x,tmp_pos.y)}}.bind(this,data,callback),document.getElementById("node-cancel").onclick=function(){$("#scene-dialog").dialog("close")},$("#scene-dialog").dialog("open")},addEdge:function(data,callback){scenario.edges.push(data),callback(data)},editEdge:function(data,callback){let edge=Util.getEdgeById(data.id);edge.from=data.from,edge.to=data.to,Util.disableTab(),callback(data)},deleteNode:function(data,callback){if(confirm("Sceneを削除しても良いですか?")){let node=Util.getSceneById(data.nodes[0]);if(0===Number(node.id))return window.alert("id=0のノードは削除できません。"),void callback(null);scenario.scenes=scenario.scenes.filter((function(value){return value.id!==node.id})),scenario.edges=scenario.edges.filter((function(value){return value.from!==node.id&&value.to!==node.id})),Util.disableTab(),callback(data)}else callback(null)},deleteEdge:function(data,callback){if(confirm("Edgeを削除しても良いですか?")){for(ed of data.edges)scenario.edges=scenario.edges.filter((function(value){return console.log(value),console.log(ed),console.log("----"),value.id!==ed}));Util.disableTab(),callback(data)}else callback(null)}},locale:"ja",locales:{ja:{edit:"Edit",del:"Delete Selected",back:"Back",addNode:"Add Scene",addEdge:"Add Link",editNode:"Edit Scene",editEdge:"Edit Link",addDescription:"Click in an empty space to place a new scene.",edgeDescription:"Click on a scene and drag the link to another scene to connect them.",editEdgeDescription:"Click on the control points and drag them to a scene to connect to it.",createEdgeError:"Cannot link edges to a cluster.",deleteClusterError:"Clusters cannot be deleted.",editClusterError:"Clusters cannot be edited."}},nodes:{shape:"box",size:20,font:{size:12},color:{background:"skyblue",highlight:{border:"#f00",background:"#f90"}}},edges:{arrows:"to",smooth:{enabled:!0,type:"curvedCCW",roundness:.1},font:{size:12,color:"rgba(0,0,0,0)",strokeWidth:0},chosen:{label:function(values){values.color="#f00",values.strokeWidth=2,values.mod="bold"}},color:{color:"skyblue",hover:"#f90",highlight:"#f00"}}}),network.moveTo({scale:scale}),opts.focus_id&&(network.focus(opts.focus_id),network.selectNodes([opts.focus_id])),opts.fit&&network.fit(),network.on("selectNode",(function(e){let id=this.getNodeAt(e.pointer.DOM);Util.setSceneInfo(id)})),network.on("selectEdge",(function(e){if(0!==e.nodes.length)return;let id=network.getEdgeAt(e.pointer.DOM);void 0!==id&&Util.setEdgeInfo(id)})),network.on("oncontext",(function(e){let org_e=e.event;$("#scene-select #id").val()===e.nodes[0]&&($("#chart-menu").css({display:"block",top:org_e.pageY,left:org_e.pageX}),org_e.preventDefault())}))},destroyNetwork:function(){null!==network&&(network.destroy(),network=null)},createGrid:function(selector,data,cols,opts,helpName,checkid=!0){void 0===data&&(data=[]);let grid=new Slick.Grid(selector,data,cols,opts);return grid.setSelectionModel(new Slick.CellSelectionModel),grid.onClick.subscribe((function(e,args){$(e.target).hasClass("btn-delete")&&(data.splice(args.row,1),grid.invalidate())})),grid.onCellChange.subscribe((function(e,args){0===args.cell&&(isUpdatedInGrid=!0)})),grid.onAddNewRow.subscribe((function(e,args){let item=args.item;if(checkid){if(!item.id)return void toastr.error("idを入力してください。","Id Error");if(Util.isDuplicateId(item.id,data))return void toastr.error("idが重複しています。","Id Error")}grid.invalidateRow(data.length),data.push(item),grid.updateRowCount(),grid.render(),isUpdatedInGrid=!0})),grid.onHeaderClick.subscribe((function(e,args){Util.showHelpDialog(`${helpName}/${args.column.id}`)})),grid},validateId:function(value,prefix,name,name_e){let msg="";return null==value||""===value.trim()?msg=`${name}のidは空にはできません。`:value.startsWith(prefix)?Util.isDuplicateId(value,scenario[name_e])&&(msg=`${name}のidが重複しています。`):msg=`${name}のidは「${prefix}~」形式で入力してください。`,msg?(toastr.error(msg,"Id Error"),{valid:!1,msg:msg}):{valid:!0,msg:null}},createAllGrid(){let grid_opts={editable:!0,enableAddRow:!0,enableCellNavigation:!0,asyncEditorLoading:!1,autoEdit:!1};grid.groups=Util.createGrid("#groups_grid",scenario.groups,[{id:"start",name:"開始No.",field:"start",width:70,editor:Slick.Editors.Integer},{id:"end",name:"終了No.",field:"end",width:70,editor:Slick.Editors.Integer},{id:"title",name:"グループ名",field:"title",width:250,editor:Slick.Editors.Text},{id:"rule",name:"ルールid",field:"rule",width:70,editor:Slick.Editors.Integer},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"group",!1),grid.items=Util.createGrid("#items_grid",scenario.items,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"i","アイテム","items")}},{id:"name",name:"名前",field:"name",width:80,editor:Slick.Editors.Text},{id:"target",name:"効果対象",field:"target",width:60,editor:SelectEditor,options:["","hp","mp","state","str","int","dex","krm","free1","free2","free3","param","none"]},{id:"effect",name:"効果値",field:"effect",width:80,editor:Slick.Editors.Text},{id:"text",name:"説明",field:"text",width:250,editor:Slick.Editors.Text},{id:"shared",name:"共有",field:"shared",width:50,editor:SelectEditor,options:["","true"]},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"item"),grid.flags=Util.createGrid("#flags_grid",scenario.flags,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"f","フラグ","flags")}},{id:"text",name:"説明",field:"text",width:300,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"flag"),void 0===scenario.params&&(scenario.params=[]),grid.params=Util.createGrid("#params_grid",scenario.params,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"p","内部パラメーター","params")}},{id:"min",name:"最小値",field:"min",width:60,editor:Slick.Editors.Text},{id:"max",name:"最大値",field:"max",width:60,editor:Slick.Editors.Text},{id:"initial",name:"初期値",field:"initial",width:60,editor:Slick.Editors.Text},{id:"text",name:"説明",field:"text",width:300,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"param"),grid.enemies=Util.createGrid("#enemies_grid",scenario.enemies,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"m","モンスター","enemies")}},{id:"name",name:"名前",field:"name",width:80,editor:Slick.Editors.Text},{id:"element",name:"属性",field:"element",editor:SelectEditor,options:["","earth","water","fire","wind","spirit"]},{id:"attack",name:"攻撃",field:"attack",width:80,editor:SelectEditor,options:["","physics","magic","both","free1","free2","free3","poison","frozen","stone","curse","forget","str","int","dex","krm"]},{id:"func",name:"ダメージ式",field:"func",width:80,editor:Slick.Editors.LongText,validator:function(value){if(value.includes("<")){let msg="ダメージ式では「<」ではなく「>」を利用してください。";return toastr.error(msg,"Func Error"),{valid:!1,msg:msg}}if(value.includes("ML")||value.includes("MR")){let msg="「ML」は「LM」、「MR」は「RM」です。";return toastr.error(msg,"Func Error"),{valid:!1,msg:msg}}return{valid:!0,msg:null}}},{id:"drop",name:"ドロップ",field:"drop",width:80,editor:AutoCompleteEditor,dataSource:["mon/","tue/","wed/","thu/","fri/","sat/","sun/","free1/","free2/","free3"]},{id:"text",name:"説明",field:"text",width:180,editor:Slick.Editors.LongText},{id:"hp",name:"敵HP",field:"hp",width:40,editor:Slick.Editors.Text},{id:"func_opp",name:"敵ダメージ式",field:"func_opp",width:90,editor:Slick.Editors.LongText},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"enemy"),grid.results=Util.createGrid("#results_grid",scenario.results,[{id:"id",name:"id",field:"id",width:50,editor:Slick.Editors.Text,validator:function(value){return Util.validateId(value,"r","実績","results")}},{id:"name",name:"名前",field:"name",width:100,editor:Slick.Editors.Text},{id:"level",name:"Lv.",field:"level",width:30,editor:SelectEditor,options:["1","2","3","4","5"]},{id:"text",name:"説明",field:"text",width:150,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"result"),grid.works=Util.createGrid("#works_grid",scenario.licence,[{id:"name",name:"名前",field:"name",width:100,editor:Slick.Editors.Text},{id:"category",name:"分類",field:"category",width:70,editor:SelectEditor,options:["","bgm","picture"]},{id:"creator",name:"作者",field:"creator",width:80,editor:Slick.Editors.Text},{id:"url",name:"URL",field:"url",width:230,editor:Slick.Editors.Text},{id:"delete",name:"削除",field:"",width:35,formatter:function(){return''}}],grid_opts,"work",!1)},createSelectSidebar:function(trigger,target,member,type,label,value,onSubmit){let dataset=scenario[member];"groups"===member&&(dataset=[{start:0,end:99999,title:"フィルター解除"}].concat(dataset)),Util.createSelectSidebarForDataset(trigger,target,dataset,type,label,value,onSubmit)},createSelectSidebarForDataset:function(trigger,target,dataset,type,label,value,onSubmit){let s_name=`sidr_${target}`,s_list=`#${s_name} #${s_name}_list`,s_submit=`#${s_name} #${s_name}_submit`,s_cancel=`#${s_name} #${s_name}_close`,s_lead=`#${s_name} .btn-lead`;$(trigger).sidr({name:s_name,displace:!1,onOpen:function(){let v_dataset;$(s_list).empty(),v_dataset="function"==typeof dataset?dataset():dataset;for(let obj of v_dataset){let elem,v_label,v_value;switch(v_label="function"==typeof label?label(obj):obj[label],v_value="function"==typeof value?value(obj):obj[value],type){case"check":elem=`
  • \n \n
  • `;break;case"radio":elem=`
  • \n \n
  • `;break;case"plus_minus":elem=`\n \n \n \n ${v_label}\n \n \n \n `;break;case"inputs":elem=`\n ${v_label}\n \n \n \n `;break;case"sort":elem=`
  • \n
    ${v_label}
    \n
  • `;break;default:throw new Error("type属性の値が不正です。")}$(s_list).append(elem)}"sort"===type&&$(s_list).sortable({forcePlaceholderSize:!0,cursor:"move",opacity:.2}),dataset.length>30?$(s_lead).show():$(s_lead).hide(),$(`${s_list} .sidr-item`).checkboxradio({icon:!1})}}),$(s_submit).click((function(){let result;switch(type){case"check":result=[],$(`${s_list} .sidr-item:checked`).each((function(){result.push($(this).val())})),result=result.join(",");break;case"radio":result=$(`${s_list} .sidr-item:checked`).val();break;case"plus_minus":result=[],$(`${s_list} .sidr_${target}_plus:checked`).each((function(){result.push($(this).val())})),$(`${s_list} .sidr_${target}_minus:checked`).each((function(){result.push("-"+$(this).val())})),result=result.join(",");break;case"inputs":result=[],$(`${s_list} .sidr-elem input[type="text"]`).each((function(){let v=$(this).val();if(void 0!==v&&""!==v.trim()){let id=$(this).attr("id");result.push(`${id.split("_")[1]}:${v}`)}})),result=result.join(",")}onSubmit?onSubmit(result,trigger,s_list):$(trigger).val(result).trigger("input"),$.sidr("close",s_name)})),$(s_cancel).click((function(){$.sidr("close",s_name)}))},closeAllSidebar(){$(".mysidr").each((function(index,e){$.sidr("close",$(e).attr("id"))}))},createQuestLink:function(group){let tmp_correct="",tmp_to=[];for(let value of group)value.correct?(tmp_to[0]=value.to,tmp_correct=value.correct):tmp_to[1]=value.to;return`[${tmp_correct},${tmp_to.join(",")}](Q)`},createFreeLink:function(group){let tmp_to=[];for(let value of group)tmp_to.push(value.to);return`[${tmp_to.join(",")}](X)`},createRandomLink:function(group){let tmp_label="",tmp_cache="",tmp_condition="",tmp_to=[];for(let value of group)value.cache&&(tmp_cache=value.cache),value.condition&&(tmp_condition=value.condition),value.label&&(tmp_label=value.label),tmp_to.push(value.to);let to=tmp_to.join(",");return tmp_cache&&(to+=`;${tmp_cache}`),tmp_condition?`[${tmp_label}](${to} "${tmp_condition}")`:`[${tmp_label}](${to})`},createStandardLink:function(link){return link.condition?`[${link.label}](${link.to} "${link.condition}")`:`[${link.label}](${link.to})`},createMoveButton:function(id){let result=[],output=[];scenario.edges.filter((function(value){return value.from===id})).sort((function(v1,v2){return v1.order||(v1.order=0),v2.order||(v2.order=0),Number(v1.order)-Number(v2.order)})).forEach((function(value){let last_out=output[output.length-1];last_out&&last_out[0].order===value.order?last_out.push(value):output.push([value])}));for(let group of output)switch(group[0].type){case"Q":result.push(Util.createQuestLink(group));break;case"X":result.push(Util.createFreeLink(group));break;case"R":result.push(Util.createRandomLink(group));break;default:for(let link of group)result.push(Util.createStandardLink(link))}return 0===result.length&&(Util.getSceneById(id).end||console.warn(`No Link: ${id}`)),result.join("\n")},enableTab:function(id){$("#edit-area").tabs("enable",id).tabs("option","active",id)},disableTab:function(){$("#edit-area").tabs("option","active",0).tabs("option","disabled",[Common_SCENE_INDEX,Common_EDGE_INDEX])},createXml:function(){let result=$(''),inits=$(""),groups=$(""),items=$(""),flags=$(""),params=$(""),enemies=$(""),results=$(""),licence=$("");result.attr("title",scenario.title),result.attr("author",scenario.author);let basic=Util.objToElement("basic",scenario.init.basic);basic&&inits.append(basic);let constraint=Util.objToElement("constraint",scenario.init.constraint);constraint&&inits.append(constraint);let bgm=Util.objToElement("bgm",scenario.init.bgm);bgm&&inits.append(bgm);let label=Util.objToElement("label",scenario.init.label);label&&inits.append(label);let intro=Util.objToElement("intro",scenario.init.intro);intro&&inits.append(intro),result.append(inits);for(let t_group of scenario.groups){let group=Util.objToElement("group",t_group);group&&groups.append(group)}result.append(groups);for(let t_item of scenario.items){let item=Util.objToElement("item",t_item);item&&items.append(item)}result.append(items);for(let t_flag of scenario.flags){let flag=Util.objToElement("flag",t_flag);flag&&flags.append(flag)}result.append(flags);for(let t_param of scenario.params){let param=Util.objToElement("param0",t_param);param&¶ms.append(param)}result.append(params);for(let t_enemy of scenario.enemies){let enemy=Util.objToElement("enemy",t_enemy);enemy&&enemies.append(enemy)}result.append(enemies);for(let t_result of scenario.results){let result=Util.objToElement("result",t_result);result&&results.append(result)}result.append(results);for(let t_work of scenario.licence){let work=Util.objToElement("work",t_work);work&&licence.append(work)}result.append(licence);for(let t_scene of scenario.scenes){let scene=Util.objToElement("scene",t_scene);scene.text(scene.text()+"\n\n"+Util.createMoveButton(scene.attr("id"))),scene&&result.append(scene)}return vkbeautify.xml('\n'+result.get(0).outerHTML.replace(//gi,"").replace(/<\/param0>/gi,""))},elementToObj:function(obj,isLabel){let result={},t_obj=obj.get(0);if(t_obj){let attrs=t_obj.attributes;for(let attr of attrs)result[attr.name]=attr.value;t_obj.textContent&&(result.text=t_obj.textContent),isLabel&&(result.label=t_obj.id+":\n"+t_obj.getAttribute("summary"))}return result},setGroupByEnd(attr_end,obj){switch(attr_end){case"happy":obj.group="happy";break;case"bad":obj.group="bad";break;default:delete obj.group}},createJson(data){let result=$.extend(!0,{},Common_INIT_DATA_EMPTY),parser,s_data=(new DOMParser).parseFromString(data,"text/xml");result.title=$("scenario",s_data).attr("title"),result.author=$("scenario",s_data).attr("author"),result.init.basic=Util.elementToObj($("init > basic",s_data)),result.init.constraint=Util.elementToObj($("init > constraint",s_data)),result.init.bgm=Util.elementToObj($("init > bgm",s_data)),result.init.label=Util.elementToObj($("init > label",s_data)),result.init.intro=Util.elementToObj($("init > intro",s_data)),$("groups > group",s_data).each((function(i,elem){result.groups.push(Util.elementToObj($(elem)))})),$("items > item",s_data).each((function(i,elem){result.items.push(Util.elementToObj($(elem)))})),$("flags > flag",s_data).each((function(i,elem){result.flags.push(Util.elementToObj($(elem)))})),$("params > param",s_data).each((function(i,elem){result.params.push(Util.elementToObj($(elem)))})),$("enemies > enemy",s_data).each((function(i,elem){result.enemies.push(Util.elementToObj($(elem)))})),$("results > result",s_data).each((function(i,elem){result.results.push(Util.elementToObj($(elem)))})),$("licence > work",s_data).each((function(i,elem){result.licence.push(Util.elementToObj($(elem)))}));var link=/\[(.+?)\]\(([\dQX,;]{1,})(?: "(.+?)")?\)/gi;return $("scene",s_data).each((function(i,elem){let body=$(elem).text(),order=0;for(;null!==(link_result=link.exec(body));){order++;let tmp_to=link_result[2],tmp_condition=link_result[3]?link_result[3]:"",tmp_label=link_result[1];switch(tmp_to){case"Q":tmp_label=tmp_label.split(","),result.edges.push({from:elem.id,to:tmp_label[1],label:"",type:"Q",correct:tmp_label[0],order:order}),result.edges.push({from:elem.id,to:tmp_label[2],label:"",type:"Q",order:order});break;case"X":tmp_label=tmp_label.split(",");for(let tmp of tmp_label)result.edges.push({from:elem.id,to:tmp,label:"",type:"X",order:order});break;default:if(-1===tmp_to.indexOf(","))result.edges.push({from:elem.id,to:tmp_to,label:tmp_label,condition:tmp_condition,order:order});else{tmp_cache=tmp_to.split(";"),tmp_to=tmp_cache[0].split(","),tmp_cache=tmp_cache[1],is_first=!0;for(let tmp of tmp_to){let tmp_link={from:elem.id,to:tmp,label:tmp_label,type:"R",condition:tmp_condition,order:order};is_first&&(tmp_link.cache=tmp_cache,is_first=!1),result.edges.push(tmp_link)}}}}let s_obj=Util.elementToObj($(elem).text(body.replace(link,"").trimEnd()),!0);0===Number(s_obj.id)?s_obj.group="prologue":s_obj.end&&Util.setGroupByEnd(s_obj.end,s_obj),result.scenes.push(s_obj)})),JSON.stringify(result)},numToKanji:function(nums){let result="",tbl={1:"一",2:"二",3:"三",4:"四",5:"五",6:"六",7:"七",8:"八",9:"九",0:"〇"};for(num of String(nums))result+=tbl[num];return result},createLinkTag:function(id,edges){let result=[];return edges.forEach((function(value){value.from===id&&result.push(`[${value.label} ${Util.numToKanji(value.to)}へ]`)})),result.join("
    ")},createHtml(){let html=$("").append($("").append($("").attr("charset","UTF-8")).append($("").text(scenario.title)).append($("").text("body {\n writing-mode: vertical-rl;\n text-orientation: upright;\n }"))),body=$("");return scenario.scenes.forEach((function(value){$('
    ').attr("id",value.id).html("

    【"+Util.numToKanji(value.id)+"】

    "+marked(value.text)+"

    "+Util.createLinkTag(value.id,scenario.edges)+"


    ").appendTo(body)})),html.append(body),""+html.get(0).outerHTML},createLinkText:function(id,edges){let result=[];return edges.forEach((function(value){value.from===id&&result.push(`[${value.label} ${Util.numToKanji(value.to)}へ]`)})),result.join("\n\n")},createEpub:function(){let result="";scenario.scenes.forEach((function(value){result+=`【${Util.numToKanji(value.id)} 】\n\n${value.text}\n\n${Util.createLinkText(value.id,scenario.edges)}\n\n==============\n\n`})),result+="\n# 付録\n\n## 敵情報\n\n名前|属性|攻撃|概要\n----|----|----|----\n";let elem={"":"無",earth:"地",fire:"火",water:"水",wind:"風",spirit:"霊"},atk={physics:"物理",magic:"魔法",both:"物理/魔法",str:"STR",int:"INT",dex:"DEX",krm:"KRM",free1:"FREE1",free2:"FREE2",free3:"FREE3"};return scenario.enemies.forEach((function(value){result+=`${value.name}|${elem[value.element]}|${atk[value.attack]}|${value.text}\n`})),result+="\n\n## アイテム情報\n\n名前|概要\n----|----\n",scenario.items.forEach((function(value){result+=`${value.name}|${value.text}\n`})),result+="\n\n## 実績情報\n\n名前|Lv|概要\n----|----|----\n",scenario.results.forEach((function(value){result+=`${value.name}|${Util.numToKanji(value.level)}|${value.text}\n`})),result},download:function(content,name){var blob=new Blob([content],{type:"application/octet-stream"}),anchor=document.createElement("a");anchor.href=window.URL.createObjectURL(blob),anchor.download=name,document.body.appendChild(anchor),anchor.click(),document.body.removeChild(anchor)}},global_config=Util.loadConfig(),scenario;localStorage.editor2flow&&(sessionStorage.setItem(Common_LOAD_NAME,Util.createJson(localStorage.editor2flow)),localStorage.removeItem("editor2flow"));try{scenario=JSON.parse(sessionStorage.getItem(Common_LOAD_NAME)),sessionStorage.removeItem(Common_LOAD_NAME)}catch(e){console.log(e)}scenario||(scenario=$.extend(!0,{},Common_INIT_DATA),scenario.author=global_config.author),scenario.init.basic||(scenario.init.basic={}),scenario.params||(scenario.params=[]),Util.sortScenario(),Util.createNetwork({fit:!0}),$("#title").val(scenario.title),$("#author").val(scenario.author),$("#basic-summary").prop("checked",!!scenario.init.basic.summary),$("#basic-imgset").prop("checked",!!scenario.init.basic.imgset),$("#constraint-race").val(scenario.init.constraint.race),$("#constraint-sex").val(scenario.init.constraint.sex),$("#constraint-age").val(scenario.init.constraint.age),$("#bgm-main").val(scenario.init.bgm.main),$("#bgm-happy").val(scenario.init.bgm.happy),$("#bgm-bad").val(scenario.init.bgm.bad),$("#label-hp").val(scenario.init.label.hp),$("#label-mp").val(scenario.init.label.mp),$("#label-state").val(scenario.init.label.state),$("#label-str").val(scenario.init.label.str),$("#label-int").val(scenario.init.label.int),$("#label-dex").val(scenario.init.label.dex),$("#label-krm").val(scenario.init.label.krm),$("#label-free1").val(scenario.init.label.free1),$("#label-free2").val(scenario.init.label.free2),$("#label-free3").val(scenario.init.label.free3),$("#intro-keywords").val(scenario.init.intro.keywords),$("#intro-description").val(scenario.init.intro.description),$("#basic input").on("input",(function(e){let id=e.target.id.split("-");1===id.length?scenario[id[0]]=$(this).val():(scenario.init[id[0]][id[1]]=$(this).val(),"summary"!==id[1]&&"imgset"!==id[1]||$(this).prop("checked")||(scenario.init[id[0]][id[1]]=void 0))})),$(".sidr-race-item, .sidr-age-item, .sidr-sex-item").checkboxradio({icon:!1}),$("#basic #constraint-race").sidr({name:"sidr_races",displace:!1}),$("#sidr_races_submit").click((function(){let result=[];$(".sidr-race-item:checked").each((function(){result.push($(this).val())})),$("#basic #constraint-race").val(result.join(",")).trigger("input"),$.sidr("close","sidr_races")})),$("#sidr_races_close").click((function(){$.sidr("close","sidr_races")})),$("#basic #constraint-age").sidr({name:"sidr_ages",displace:!1}),$("#sidr_ages_submit").click((function(){let result=[];$(".sidr-age-item:checked").each((function(){result.push($(this).val())})),$("#basic #constraint-age").val(result.join(",")).trigger("input"),$.sidr("close","sidr_ages")})),$("#sidr_ages_close").click((function(){$.sidr("close","sidr_ages")})),$("#basic #constraint-sex").sidr({name:"sidr_sexes",displace:!1}),$("#sidr_sexes_submit").click((function(){let result=[];$(".sidr-sex-item:checked").each((function(){result.push($(this).val())})),$("#basic #constraint-sex").val(result.join(",")).trigger("input"),$.sidr("close","sidr_sexes")})),$("#sidr_sexes_close").click((function(){$.sidr("close","sidr_sexes")})),$("#basic #bgm-main-ref").click((function(e){$("#basic #bgm-main-file").click()})),$("#basic #bgm-main-file").change((function(e){let name=$(this).get(0).files[0].name;$("#basic #bgm-main").val(name.substring(0,name.lastIndexOf(".mp3"))).trigger("input")})),$("#basic #bgm-happy-ref").click((function(e){$("#basic #bgm-happy-file").click()})),$("#basic #bgm-happy-file").change((function(e){let name=$(this).get(0).files[0].name;$("#basic #bgm-happy").val(name.substring(0,name.lastIndexOf(".mp3"))).trigger("input")})),$("#basic #bgm-bad-ref").click((function(e){$("#basic #bgm-bad-file").click()})),$("#basic #bgm-bad-file").change((function(e){let name=$(this).get(0).files[0].name;$("#basic #bgm-bad").val(name.substring(0,name.lastIndexOf(".mp3"))).trigger("input")})),$("#basic label, #scene label, .dynamic_help").dblclick((function(e){Util.showHelpDialog($(this).attr("data-help"))})),$("#basic label > input, #basic label > select, #scene label > input, #scene label > select").dblclick((function(e){e.stopPropagation()})),$("#help-dialog").dialog({autoOpen:!1,width:640,minHeight:300,maxHeight:500,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"center top",my:"left top"},open:function(){},buttons:{"閉じる":function(){$(this).dialog("close"),Util.closeAllSidebar()}}}),$("#pg-config").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#config-author").val(global_config.author),$("#config-disp").val(global_config.disp),$("#config-incre").val(global_config.increment)},buttons:{"確定":function(){global_config.author=$("#config-author").val(),global_config.disp=$("#config-disp").val(),global_config.increment=$("#config-incre").val(),$("#ctrl_incre").val(global_config.increment),Util.saveConfig(global_config),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}}}),$("#scene-dialog").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#node-id").val(""),$("#node-summary").val("")}}),$("#scene-dialog-link").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#node-link-id").val(Util.nextScene($("#scene-attr #id").val())),$("#node-link-summary").val(""),$("#node-link-caption").val("次へ")},buttons:{"追加":function(){let from=$("#scene-attr #id").val(),id=$("#node-link-id").val();Util.addNode(id,$("#node-link-summary").val())&&($(this).dialog("close"),Util.addLink(from,id,$("#node-link-caption").val()),Util.createNetwork({focus_id:from}))},"キャンセル":function(){$(this).dialog("close")}}}),$("#scene-change-dialog").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#old-id").val($("#scene-attr #id").val()),$("#new-id").val("")},buttons:{"変更":function(){let old_id=$("#old-id").val(),new_id=$("#new-id").val();Util.isDuplicateScene(new_id)?Util.swapNodeId(old_id,new_id):Util.changeNodeId(old_id,new_id),Util.createNetwork({focus_id:new_id}),Util.setSceneInfo(new_id),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}}}),$("#edge-dialog").dialog({autoOpen:!1,width:320,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},open:function(){$("#from-id").text($("#scene-select #id").val()),$("#edge-dialog #edge-caption").val("次へ"),$("#to-id").val(""),$("#edge-kind").val(""),$("#edge-add").val(""),$("#edge-correct").val("")},buttons:{"追加":function(){let from=$("#edge-dialog #from-id").text(),to=$("#edge-dialog #to-id").val(),label=$("#edge-dialog #edge-caption").val();label||(label="次へ");let kind=$("#edge-dialog #edge-kind").val(),add=$("#edge-dialog #edge-add").val(),correct=$("#edge-dialog #edge-correct").val();to?Util.isNewScene(to)?toastr.error("リンク先のidが存在しません。","不正な値"):!["R","X","Q"].includes(kind)||add?"Q"===kind&&add.includes(",")?toastr.error("追加情報には間違い時のリンク先を指定してください。
    \n 正解時のリンク先はid欄に指定します。","不正な値"):"Q"!==kind||correct?(Util.addLink(from,to,label,kind,add,correct),Util.createNetwork({focus_id:from}),Util.setSceneInfo(from),$(this).dialog("close")):toastr.error("[テキスト入力]選択時には、正解文字列は必須です。","不正な値"):toastr.error("通常以外のリンクでは追加情報は必須です。","不正な値"):toastr.error("リンク先のidは必須です。","不正な値")},"キャンセル":function(){$(this).dialog("close")}}}),$("#edge-dialog #edge-kind").change((function(){let v=$(this).val();$("#edge-dialog #edge-add").attr("placeholder",(function(){return""===v?"":"R"===v||"X"===v?"他のリンク先(カンマ区切り)":"Q"===v?"間違いの時のリンク先":void 0}))})),$("#range-dialog").dialog({autoOpen:!1,width:400,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},buttons:{"絞り込み":function(){Util.createNetwork({fit:!0}),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}},open:function(){}}),$("#epub-dialog").dialog({autoOpen:!1,width:650,show:500,hide:500,modal:!0,position:{of:"#flow-area",at:"left top",my:"left top"},buttons:{"エクスポート":function(){Util.download(Util.createEpub(),"scenario.txt"),$(this).dialog("close")},"キャンセル":function(){$(this).dialog("close")}}}),$("#upload-dialog").dialog({autoOpen:!1,width:800,show:500,hide:500,modal:!0,buttons:{"投稿":function(){let key=localStorage.getItem("pgflow_key");key||(key=(new Date).getTime().toString(16),localStorage.setItem("pgflow_key",key));let p={email:$("#upload-email").val(),tag:$("#upload-tag").val(),level:$("#upload-level").val(),intro:$("#upload-intro").val(),comment:$("#upload-comment").val(),ftp:$("#upload-ftp").prop("checked")?$("#upload-ftp").val():""};localStorage.setItem("pgflow_post",JSON.stringify(p));let data=new FormData;data.append("key",key),data.append("email",p.email),data.append("tag",p.tag),data.append("level",p.level),data.append("intro",p.intro),data.append("comment",p.comment),data.append("ftp",p.ftp),data.append("scenario",new Blob([Util.createXml()],{type:"text/xml"}),"scenario.xml");let bgms=$("#upload-bgms").get(0).files,ses=$("#upload-ses").get(0).files,pics=$("#upload-pics").get(0).files;for(let i=0;i work",data).each((function(){$("#sidr_links_result_s").append($("").attr("value",$(this).attr("id")).text($(this).attr("title"))),tmp_scenario_set.push({id:$(this).attr("id"),title:$(this).attr("title")})})),Util.createSelectSidebarForDataset("#scene-select #nexts","nexts",tmp_scenario_set,"check","title","id")})),$("#sidr_links_result_s").change((function(e){$.get(`../stext/${$(this).val()}/scenario.xml`).done((function(data){$("#sidr_links_result").empty().append(""),$("results > result",data).each((function(){$("#sidr_links_result").append($("").attr("value",$(this).attr("id")+":"+$("#sidr_links_result_s").val()).text($(this).attr("name")))}))}))})),$("#edge #condition").sidr({name:"sidr_links",displace:!1,onOpen:function(){$("#sidr_links_cond").val(""),$("#sidr_links_item").empty().append("");for(let item of scenario.items)$("#sidr_links_item").append(``);$("#sidr_links_flag").empty().append("");for(let flag of scenario.flags)$("#sidr_links_flag").append(``);$("#sidr_links_param").empty().append("");for(let param of scenario.params)$("#sidr_links_param").append(``)}}),$("#sidr_links_list select:not(.no-update)").change((function(){let cond=$("#sidr_links_cond");cond.val(cond.val()+$(this).val())})),$("#sidr_links button").click((function(){let cond=$("#sidr_links_cond");cond.val(cond.val()+$(this).val())})),$("#sidr_links_submit").click((function(){$("#edge #condition").val($("#sidr_links_cond").val()).trigger("input"),$.sidr("close","sidr_links")})),$("#sidr_links_close").click((function(){$.sidr("close","sidr_links")})),Util.createAllGrid();let editor=ace.edit("scene-editor");ace.config.loadModule("ace/ext/language_tools",(function(lang){editor.completers=[lang.snippetCompleter],editor.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0});const snippetManager=ace.require("ace/snippets").snippetManager,config=ace.require("ace/config");ace.config.loadModule("ace/snippets/markdown",(function(m){if(m){snippetManager.files.markdown=m;let s_list=[{title:"image",body:"![${1:text}](${2:file})"},{title:"title",body:"\\${title}"},{title:"name",body:"\\${name}"},{title:"job",body:"\\${job}"},{title:"hp",body:"\\${hp}"},{title:"mp",body:"\\${mp}"},{title:"str",body:"\\${str}"},{title:"int",body:"\\${int}"},{title:"dex",body:"\\${dex}"},{title:"krm",body:"\\${krm}"},{title:"free1",body:"\\${free1}"},{title:"free2",body:"\\${free2}"},{title:"free3",body:"\\${free3}"},{title:"race",body:"\\${race?${1:fighter}:${2:wizard}:${3:dwarf}:${4:elf}}"},{title:"sex",body:"\\${sex?${1:male}:${2:female}}"},{title:"state",body:"\\${state?${1:normal}:${2:poison}:${3:frozen}:${4:stone}:${5:forget}}"},{title:"age",body:"\\${age?${1:young}:${2:adult}:${3:old}}"},{title:"rand",body:"\\${rand?${1:min}:${2:max}}"},{title:"msg",body:"\\${msg?${1:arg1}:${2:arg2}:...}"},{title:"enemy:name",body:"\\${var?m${1:id}:name}"},{title:"enemy:element",body:"\\${var?m${1:id}:element}"},{title:"enemy:text",body:"\\${var?m${1:id}:text}"},{title:"result:name",body:"\\${var?r${1:id}:name}"},{title:"result:level",body:"\\${var?r${1:id}:level}"},{title:"result:text",body:"\\${var?r${1:id}:text}"},{title:"param:text",body:"\\${var?p${1:id}:text}"},{title:"param:value",body:"\\${var?p${1:id}:value}"},{title:"result:count",body:"\\${result?${1:id}}"},{title:"result:rate",body:"\\${result_rate?${1:id}}"},{title:"import",body:"\\${import ${1:id}}"},{title:"input",body:"\\${input?${1:init}}"},{title:"if",body:"\\${if ${1:condition}}${2:body}\\${/if}"},{title:"effect",body:"\\${effect ${1:type}}${2:body}\\${/effect}"},{title:"ruby",body:"\\${${1:word}|${2:ruby}}"},{title:"blue",body:"%blue%${1:body}%/%"},{title:"red",body:"%red%${1:body}%/%"},{title:"purple",body:"%purple%${1:body}%/%"},{title:"white",body:"%white%${1:body}%/%"},{title:"tweet",body:"\\${tweet}${1:body}\\${/tweet}"}];m.snippets=[];for(let item of s_list)m.snippets.push({content:item.body,name:item.title,tabTrigger:item.title});snippetManager.register(m.snippets,m.scope)}}))})),editor.$blockScrolling=1/0,editor.getSession().setUseWrapMode(!0),editor.setTheme("ace/theme/chrome"),editor.session.setMode("ace/mode/markdown"),editor.on("input",(function(e){let id=$("#scene-select #id").val();if(id){let scene;Util.getSceneById(id).text=editor.getValue()}})),$("#scene #scene-ext").click((function(e){let sa=$("#scene-attr"),se=$("#scene-editor");se.hasClass("editor-big")?($(this).text("エディター領域を拡げる"),sa.show(),se.removeClass("editor-big").css("height","210px"),editor.resize(!0)):($(this).text("エディター領域を狭める"),sa.hide(),se.addClass("editor-big").css("height","630px"),editor.resize(!0))})),$("#scene #scene-delscene, #ctx-scene-remove").click((function(){if(!confirm("この操作は元には戻せません!\n現在のシーンを削除しても構いませんか?"))return;let id=$("#scene-attr #id").val();Util.deleteScene(id),Util.createNetwork(),$("#chart-menu").css("display","none")})),$("#scene #edges-list").focus((function(e){let id=$("#scene-attr #id").val();Util.createLinkList(id)})),$("#scene #scene-addedge, #chart-menu #ctx-edge-add").click((function(e){$("#edge-dialog").dialog("open"),$("#chart-menu").css("display","none")})),$("#scene #scene-addscene, #chart-menu #ctx-scene-add").click((function(e){$("#scene-dialog-link").dialog("open"),$("#chart-menu").css("display","none")})),$("#scene #scene-changescene").click((function(e){"0"!==$("#scene-select #id").val()?$("#scene-change-dialog").dialog("open"):toastr.error("Scene 0は変更できません。","変更不可")})),Util.createColorList("#scene #color"),Util.createSelectSidebar("#edge-dialog #to-id","scene","scenes","radio","label","id"),Util.createSelectSidebar("#edge-dialog #edge-add","scenes","scenes","check","label","id"),$("#edge #edge-deledge").click((function(){if(!confirm("この操作は元には戻せません!\n現在のリンクを削除しても構いませんか?"))return;let id=$("#edge #id").val();Util.deleteLink(id),Util.createNetwork()})),$("#edit-area").tabs().tabs({activate:function(e,ui){let keys=Object.keys(grid);for(let key of keys)grid[key].navigateNext();isUpdatedInGrid&&(Util.sortScenario(),Util.createAllGrid(),isUpdatedInGrid=!1),Util.closeAllSidebar()}}),Util.disableTab(),$("#ctrl_run").click((function(e){localStorage.setItem(Common_RUN_NAME,Util.createXml()),-1===location.host.indexOf("web-deli.com")?window.open("../index.html?id=pg2",Common_RUN_NAME):window.open("../game.aspx?id=pg2",Common_RUN_NAME)})),$("#ctrl_tag").click((function(e){$("#tag-menu").css({display:"block",top:e.pageY,left:e.pageX})})),$("#tag-menu li").click((function(e){var command;let comm={red:"%red%$0%/%",blue:"%blue%$0%/%",white:"%white%$0%/%",if:"${if condition}$0${/if}","*import":"${import 99999}",effect:"${effect type}$0${/effect}","*input":"${input?0}",ruby:"${$0|ruby}","*title":"${title}","*name":"${name}","*race":"${race?FIG:WIZ:DWA:ELF}","*sex":"${sex?M:F}","*state":"${state?NOR:POI:FRO:STO:FOR}","*age":"${age?Y:A:O}","*var":"${var?key:prop}","*random":"${rand?min:max}","*msg":"${msg?str1:str2:...}",tweet:"${tweet}%0%${/tweet}","*capture":"![caption](path)"}[$(this).data("command")];comm.startsWith("*")?editor.insert(comm):editor.insert(comm.replace("$0",editor.getCopyText())),editor.focus(),$("#tag-menu").css("display","none")})),$("#ctrl_dl").click((function(e){$("#dl-menu").css({display:"block",top:e.pageY,left:e.pageX})})),$("#dl-menu li").click((function(e){switch($(this).data("command")){case"json":scenario.scenes.forEach((function(scene){delete scene.x,delete scene.y})),Util.download(vkbeautify.json(JSON.stringify(scenario)),"stext.json");break;case"xml":Util.download(Util.createXml(),"scenario.xml");break;case"html":Util.download(Util.createHtml(),"scenario.html");break;case"epub":$("#epub-dialog").dialog("open");break;case"storage":window.alert("データをブラウザーに保存しました。\n保存済みのデータは[マイストレージ]テンプレートからロードできます。"),localStorage.setItem(Common_MY_STORAGE,JSON.stringify(scenario));break;default:console.log("Unknown Error!!")}$("#dl-menu").css("display","none")})),$("#ctrl_help").click((function(e){$("#help-menu").css({display:"block",top:e.pageY,left:e.pageX})})),Util.createSelectSidebar("#ctrl_filter","groups","groups","check",(function(obj){return`${obj.title}
    (${obj.start}-${obj.end})`}),(function(obj){return`${obj.start}-${obj.end}`}),(function(result){filter_where=[];for(let cond of result.split(",")){if(!cond)break;let tmp_cond=cond.split("-");filter_where.push({start:tmp_cond[0],end:tmp_cond[1]})}Util.createNetwork({fit:!0})})),$("#ctrl_shuffle").click((function(){if(!confirm("全シーンidをシャッフルします。\nこの操作は元に戻せませんが、続けますか?"))return;let s=new StextShuffle(scenario);s.run(),Util.refreshScenario(s.scenario),Util.sortScenes(),Util.createNetwork({fit:!0}),Util.disableTab()})),$("#ctrl_config").click((function(){$("#pg-config").dialog("open")})),$("#ctrl_template").change((function(e){var selected=$(this).val();if("storage"===selected){var save=localStorage.getItem(Common_MY_STORAGE);save?(sessionStorage.setItem(Common_LOAD_NAME,save),location.reload()):window.alert("セーブデータは存在しません。")}else if(selected){let path;path=selected.startsWith("@")?`../stext/${selected.substring(1)}/scenario.xml`:`./template/${selected}`,$.ajax(path,{dataType:"text"}).done((function(data){selected.startsWith("@")&&(data=Util.createJson(data)),sessionStorage.setItem(Common_LOAD_NAME,data),location.reload()}))}})),$("#ctrl_import").click((function(e){$("#ctrl_load").click()})),$("#ctrl_load").change((function(e){let inputs=$(this).get(0).files,name=inputs[0].name,reader=new FileReader;$(reader).on("load",(function(){name.endsWith(".json")?sessionStorage.setItem(Common_LOAD_NAME,reader.result):sessionStorage.setItem(Common_LOAD_NAME,Util.createJson(reader.result)),location.reload()})),reader.readAsText(inputs[0],"UTF-8")})),$("#ctrl_scene").mousedown((function(e){$("#ctrl_scene").empty(),$("").attr("value","").text("編集するシーンを選択").appendTo("#ctrl_scene");for(let scene of scenario.scenes)label=scene.label,(0==scene.id||scene.end)&&(label="★"+label),$("").attr("value",scene.id).text(label).appendTo("#ctrl_scene")})),$("#ctrl_scene").change((function(e){let id=$(this).val();Util.setSceneInfo(id),network.selectNodes([id])})),$("#ctrl_addscene").click((function(e){let incre=Number(global_config.increment);(!incre||incre<1)&&(incre=1),incre=Math.floor(incre);let new_id=Number(Util.maxSceneId())+incre;scenario.scenes.push({id:String(new_id),summary:"New",label:`${new_id}:\nNew`,text:""}),Util.createNetwork()})),$(":not(.cxt)").click((function(e){"ctrl_dl"!==e.target.id&&$("#dl-menu").css("display","none"),"ctrl_help"!==e.target.id&&$("#help-menu").css("display","none"),"ctrl_tag"!==e.target.id&&$("#tag-menu").css("display","none"),"chart-menu"!==e.target.id&&$("#chart-menu").css("display","none")})),$("#ctrl_flow2editor").click((function(){$("body").css("opacity",.2),localStorage.flow2editor=Util.createXml(),window.open("./editor.html","pgeditor")})),$(window).on("beforeunload",(function(){return"ページを閉じてもよろしいですか?"}));let tips=["フローチャート上では、プロローグ/エピローグ(happy/bad)を表すシーンが色で区別されています。目的のシーンを探す手掛かりになるでしょう。","フローチャート上では、シーン単位にカラーリングが可能です。下書き、重要なフラグのあるシーンなどをマーキングしておくと良いでしょう。","フローチャートで目的のシーンが探しにくい場合には、右上のシーン選択ボックスを利用してみましょう。シーンid順に表示されています。","フローチャートやシーン選択ボックス上では、サマリーテキストが表示されます。シーンごとにできるだけ判りやすい名前を付けましょう。","シーン選択ボックス上では、プロローグとエピローグが★でマーキングされています。目的のシーンを探す手掛かりになるでしょう。","フローチャート上のリンクが見難い場合には、[シーン]タブからリンク選択ボックスを利用してみましょう。","Playgroundのデータは、.json形式(Playgroundの内部形式)、.xml形式(STextの実行形式)などで保存できます。","Playgroundのデータは、.txt形式(でんでんコンバーター向け)にも出力できます。EPUB形式の電子書籍も手軽に作成が可能です。","scenario.xml(STextの実行形式)を.json形式(Playgroundの内部形式)に変換することも可能です。既存のシナリオをPlayground Flowにインポートして、どんどん動作確認してみましょう。","Playgroundでは、.html形式での出力もできます。条件分岐、音楽機能などは利用できなくなりますが、Kindle配信などしている人にも利用して戴けると嬉しいです。",".json形式(Playgroundの内部形式)のファイルは、Playground上部のファイル選択ボタンからインポート&編集できます。","Playground Flowでは、個々のシーンをNode、リンクをEdgeと呼びます。","シーンを跨ってテキストを一括置換したい場合には、Playground Editorに切り替えると良いでしょう。[Ctrl]+[H]でテキストの一括置き換えが可能です(正規表現にも対応)。","[PgEditorで編集]ボタンを押すことで現在編集中のシナリオをPlayground Editorで編集できます。","[シーン]タブからはもシーンを追加できます。その場合、現在のシーンからのリンクも自動生成されるので、積極的に利用していきましょう。","フォーム上のラベルをダブルクリックすることで、該当する項目のヘルプページを表示できます。","アイテム/フラグ編集のグリッドからタイトル行をダブルクリックすることで、該当する項目のヘルプページを表示できます。","フィルター機能を利用することで、フローチャートに表示するシーン範囲を限定し、大きなシナリオでも見やすく表示できます。","[シンプルサンプル]は、5Sceneの中にも、戦闘、フラグ、アイテム、実績、エンディングなどの基本機能を備えています。STextの基礎を見渡すのに便利です。","[20Sceneサンプル]は、単方向で分岐と移動の枠組みだけを備えたサンプルです。20Sceneあるので、簡単な物語ならば、テキストを追加するだけでシナリオができてしまいます。","[実践サンプル]は、実際に公開されているシナをテンプレートとして公開したものです。実際の物語がどんなしくみで実装されているのかを確認してみてください。","[機能テスト]は、STextの動作確認のためのテンプレート。リンク関係など判りにくい動作例を載せています。","[セーブ]ボタンではブラウザーに一時的にデータを保存できます。保存したデータは[マイストレージ]テンプレートから取り出せますよ。","Playground Flowは現在β版です。バグかなと思ったら、Twitter(@yy7512)までお知らせください。","Playground Flowは現在β版です。こんな機能あったらいいなと思ったら、Twitter(@yy7512)までお気軽にお寄せください。","Playground Flowは現在β版です。ご利用に際しては、データのバックアップ/保存を小まめに行うようにしてください。","アイテム/フラグなどの項目はid値について昇順で自動ソートされます。番号の大小が乱れた時は一度開き直すと良いでしょう。","シーンはフローチャートとからだけでなく、右上の選択ボックスからも選べます。プロローグ/エンディングには★が付いているので、探す時の手懸りにどうぞ。","シーンテキストを編集するエディターには様々なショートカットが用意されています。詳しくはヘルプを参照してください。","[シーン]タブから[アイテム][フラグ][敵][実績]欄にフォーカスすると、サイドバーが開いて、設定済みの情報を選択できます。","[シーン]タブから[HP]~[FREE3]欄にフォーカスすると、入力可能なオプションがリスト表示されます。","複数のリンクを順序決めしたい場合、[シーン]タブの[表示ソート]をクリックします。リンクの順序をドラッグ&ドロップで変更できます。","[リンク]タブから[条件式]欄にフォーカスすると、サイドパネルに条件式生成エディターが開きます。","現在のシーンに紐づいたシーンを新規作成したいならば、[シーン]タブから[シーン追加]ボタンをクリックします。","[シーン]タブでidの[変更]ボタンをクリックすると、新しいidを振ったり、既存のidとスワップしたりできます。","シーンidはシャッフルすることも可能です。.html、.txt形式の出力前には一度シャッフルすることをお勧めします。"];toastr.options.closeButton=!0,toastr.options.positionClass="toast-bottom-full-width",toastr.options.showDuration=300,toastr.options.hideDuration=1e3,toastr.options.preventDuplicates=!0,toastr.options.timeOut=7e3,toastr.info(tips[Math.floor(Math.random()*tips.length)],"TIPS")})); \ No newline at end of file diff --git a/playground/lib/playground_editor.js b/playground/lib/playground_editor.js index 29f6aba3..d675b250 100644 --- a/playground/lib/playground_editor.js +++ b/playground/lib/playground_editor.js @@ -301,6 +301,7 @@ $(function() { // Editor2Flow $('#pg_editor2flow').click(function(e){ + $('body').css('opacity', 0.2); localStorage['editor2flow'] = editor.getValue(); window.open('./', 'pgflow'); }); diff --git a/playground/lib/playground_editor.min.js b/playground/lib/playground_editor.min.js index 497c4a2e..07991eba 100644 --- a/playground/lib/playground_editor.min.js +++ b/playground/lib/playground_editor.min.js @@ -1 +1 @@ -$((function(){let wordList=[{name:"scenario",meta:"element",score:666},{name:"title",meta:"attr(scenario)",score:777},{name:"author",meta:"attr(scenario)",score:777},{name:"init",meta:"element",score:666},{name:"constraint",meta:"element",score:888},{name:"race",meta:"attr(constraint)",score:888},{name:"FIGHTER",meta:"const(race)",score:888},{name:"WIZARD",meta:"const(race)",score:888},{name:"DWARF",meta:"const(race)",score:888},{name:"ELF",meta:"const(race)",score:888},{name:"sex",meta:"attr(constraint)",score:888},{name:"MALE",meta:"const(sex)",score:888},{name:"FEMALE",meta:"const(sex)",score:888},{name:"age",meta:"attr(constraint)",score:888},{name:"YOUNG",meta:"const(age)",score:888},{name:"ADULT",meta:"const(age)",score:888},{name:"OLD",meta:"const(age)",score:888},{name:"bgm",meta:"element",score:888},{name:"main",meta:"attr(bgm)",score:888},{name:"happy",meta:"attr(bgm)",score:888},{name:"bad",meta:"attr(bgm)",score:888},{name:"label",meta:"element",score:888},{name:"free1",meta:"attr(label)",score:888},{name:"free2",meta:"attr(label)",score:888},{name:"free3",meta:"attr(label)",score:888},{name:"intro",meta:"element",score:888},{name:"description",meta:"attr(intro)",score:888},{name:"items",meta:"element",score:666},{name:"item",meta:"element",score:999},{name:"id",value:'id="i',meta:"attr(item)",score:999},{name:"name",meta:"attr(item)",score:999},{name:"flags",meta:"element",score:666},{name:"flag",meta:"element",score:999},{name:"id",value:'id="f',meta:"attr(flag)",score:999},{name:"enemies",meta:"element",score:666},{name:"enemy",meta:"element",score:999},{name:"id",value:'id="m',meta:"attr(enemy)",score:999},{name:"name",meta:"attr(enemy)",score:999},{name:"element",meta:"attr(enemy)",score:999},{name:"earth",meta:"const(element)",score:888},{name:"fire",meta:"const(element)",score:888},{name:"water",meta:"const(element)",score:888},{name:"wind",meta:"const(element)",score:888},{name:"spirit",meta:"const(element)",score:888},{name:"attack",meta:"attr(enemy)",score:999},{name:"physics",meta:"const(attack)",score:888},{name:"magic",meta:"const(attack)",score:888},{name:"both",meta:"const(attack)",score:888},{name:"free1",meta:"const(attack)",score:888},{name:"free2",meta:"const(attack)",score:888},{name:"free3",meta:"const(attack)",score:888},{name:"poison",meta:"const(attack)",score:888},{name:"frozen",meta:"const(attack)",score:888},{name:"stone",meta:"const(attack)",score:888},{name:"curse",meta:"const(attack)",score:888},{name:"forget",meta:"const(attack)",score:888},{name:"func",meta:"attr(enemy)",score:999},{name:"STR",meta:"const(func)",score:888},{name:"INT",meta:"const(func)",score:888},{name:"DEX",meta:"const(func)",score:888},{name:"KRM",meta:"const(func)",score:888},{name:"FREE1",meta:"const(func)",score:888},{name:"FREE2",meta:"const(func)",score:888},{name:"FREE3",meta:"const(func)",score:888},{name:"drop",meta:"attr(enemy)",score:999},{name:"mon",meta:"const(drop)",score:888},{name:"tue",meta:"const(drop)",score:888},{name:"wed",meta:"const(drop)",score:888},{name:"thu",meta:"const(drop)",score:888},{name:"fri",meta:"const(drop)",score:888},{name:"sat",meta:"const(drop)",score:888},{name:"sun",meta:"const(drop)",score:888},{name:"results",meta:"element",score:666},{name:"result",meta:"element",score:999},{name:"id",value:'id="r',meta:"attr(result)",score:999},{name:"name",meta:"attr(result)",score:999},{name:"level",meta:"attr(result)",score:999},{name:"licence",meta:"element",score:666},{name:"work",meta:"element",score:888},{name:"category",meta:"attr(work)",score:888},{name:"bgm",meta:"const(category)",score:777},{name:"picture",meta:"const(category)",score:777},{name:"creator",meta:"attr(work)",score:888},{name:"url",meta:"attr(work)",score:888},{name:"scene",meta:"element",score:999},{name:"id",meta:"attr(scene)",score:999},{name:"items",meta:"attr(scene)",score:888},{name:"flags",meta:"attr(scene)",score:888},{name:"enemies",meta:"attr(scene)",score:888},{name:"stars",meta:"attr(scene)",score:888},{name:"hp",meta:"attr(scene)",score:888},{name:"mp",meta:"attr(scene)",score:888},{name:"free1",meta:"attr(scene)",score:888},{name:"free2",meta:"attr(scene)",score:888},{name:"free3",meta:"attr(scene)",score:888},{name:"result",meta:"attr(scene)",score:888},{name:"bgm",meta:"attr(scene)",score:888},{name:"se",meta:"attr(scene)",score:888},{name:"end",meta:"attr(scene)",score:888},{name:"happy",meta:"const(end)",score:777},{name:"bad",meta:"const(end)",score:777}],editor=ace.edit("editor"),langTools;editor.$blockScrolling=1/0,editor.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0}),editor.getSession().setUseWrapMode(!0),editor.setTheme("ace/theme/chrome"),editor.session.setMode("ace/mode/markdown"),ace.require("ace/ext/language_tools").addCompleter({getCompletions:function(editor,session,pos,prefix,callback){0!==prefix.length?callback(null,wordList.filter((function(ea){return 0===ea.name.indexOf(prefix)})).map((function(ea){return{name:ea.name,value:void 0===ea.value?ea.name:ea.value,score:ea.score,meta:ea.meta}}))):callback(null,[])}}),$("#pg_tag").click((function(e){$("#addmenu").css({display:"block",top:e.pageY,left:e.pageX})})),$(".addcom").click((function(e){var command={scene:'',scene_simple:'',item:'Item description...',flag:'Flag description...',param:'Param description...',enemy:'Enemy description...',result:'Result description...',work:'',basic:'',constraint:'',bgm:'',label:'',intro:''};editor.insert(command[$(this).data("command")]),editor.focus(),$("#addmenu").css("display","none")})),$("#pg_md").click((function(e){$("#addmd").css({display:"block",top:e.pageY,left:e.pageX})})),$("#addmd li").click((function(e){let command,comm={link:"[$0](num)",red:"%red%$0%/%",blue:"%blue%$0%/%",white:"%white%$0%/%",if:"${if condition}$0${/if}","*import":"${import 99999}",effect:"${effect type}$0${/effect}","*input":"${input?0}",ruby:"${$0|ruby}","*title":"${title}","*name":"${name}","*race":"${race?FIG:WIZ:DWA:ELF}","*sex":"${sex?M:F}","*state":"${state?NOR:POI:FRO:STO:FOR}","*age":"${age?Y:A:O}","*var":"${var?key:prop}","*random":"${rand?min:max}","*msg":"${msg?str1:str2:...}",tweet:"${tweet}%0%${/tweet}","*capture":"![caption](path)"}[$(this).data("command")];comm.startsWith("*")?editor.insert(comm):editor.insert(comm.replace("$0",editor.getCopyText())),$("#addmd").css("display","none")})),$("#pg_run").click((function(e){const RUN_NAME="pg2_run";localStorage.setItem(RUN_NAME,editor.getValue()),-1===location.host.indexOf("web-deli.com")?window.open("../index.html?id=pg2",RUN_NAME):window.open("../game.aspx?id=pg2",RUN_NAME)})),$("#pg_save").click((function(e){localStorage.playground_editor=editor.getValue(),window.alert("シナリオデータをブラウザーに保存しました。")})),$("#pg_gbat").click((function(e){$("#gbat").click()})),$("#pg_help").click((function(e){$("#helpmenu").css({display:"block",top:e.pageY,left:e.pageX})})),$("#helpmenu").click((function(e){$("#helpmenu").css("display","none")})),$(":not(#addmenu,#helpmenu)").click((function(e){"pg_tag"!==e.target.id&&$("#addmenu").css("display","none"),"pg_md"!==e.target.id&&$("#addmd").css("display","none"),"pg_help"!==e.target.id&&$("#helpmenu").css("display","none")})),$("#pg_dl").click((function(e){var blob=new Blob([editor.getValue()],{type:"application/octet-stream"}),anchor=document.createElement("a");anchor.href=window.URL.createObjectURL(blob),anchor.download="scenario.xml",document.body.appendChild(anchor),anchor.click(),document.body.removeChild(anchor)})),$("#pg_clear").click((function(e){confirm("編集内容をクリアしても良いですか?")&&editor.setValue("")})),$(window).on("beforeunload",(function(){return"ページを閉じてもよろしいですか?"})),$("#pg_editor2flow").click((function(e){localStorage.editor2flow=editor.getValue(),window.open("./","pgflow")})),$('[name="lang"]').change((function(){console.log($('[name="lang"]:checked').val()),editor.session.setMode("ace/mode/"+$('[name="lang"]:checked').val())})),$("#gbat").gbat2stext((function(result){editor.setValue(vkbeautify.xml('\n'+result.get(0).outerHTML))}));var loadTemplate=function(selected,isFirst){selected&&$.ajax("../stext/playground/"+selected,{dataType:"text"}).done((function(data){editor.setValue(vkbeautify.xml(data)),isFirst&&window.alert("チュートリアルシナリオをロードしています。\r開始するには、上部のツールバーから[▶]ボタンを押してください。")}))};function getPath(current){let path=$(current).prop("tagName");return $(current).parents().each((function(index,e){path=`${$(e).prop("tagName")}/${path}`})),path}function setChildNode(parent,parent_node,num){let ch=(parent=$(parent)).children();if(0!==ch.length){let subtree=$("
      ");ch.each((function(index,e){let short_name=$(e).prop("tagName"),c_name=`${$(e).prop("tagName")} ―― ${$(e).attr("overview")}`;if(["outline","common","edge_flow","edge_common"].includes($(e).prop("tagName")))return!0;let c_node=$("
    • ").attr("data-help",getPath(e));0===$(e).children().length?c_node.attr("data-jstree",'{ "icon" : "jstree-file" }').text(`#${c_name}`):(c_node.text(c_name),num<1&&"scene"!==short_name&&c_node.attr("data-jstree",'{ "opened" : true }'));let alias=$(e).attr("name");alias&&c_node.text(`#${alias} ―― ${$(e).attr("overview")}`),subtree.append(c_node),0!==$(e).children().length&&setChildNode(e,c_node,num+1)})),$(parent_node).append(subtree)}}function transferQuery(selector){return selector.replace(/\//g," > ")}let ref_data;$("#template").change((function(e){var selected=$(this).val();if("storage"===selected){var save=localStorage.playground_editor;save?editor.setValue(save):window.alert("セーブデータは存在しません。")}else loadTemplate(selected)})),localStorage.flow2editor?(editor.setValue(vkbeautify.xml(localStorage.flow2editor)),localStorage.removeItem("flow2editor")):localStorage.tutorial_off?loadTemplate("scenario_empty.xml"):(loadTemplate("tutorial1.xml",!0),localStorage.tutorial_off=1),$("#region").sidr({name:"sidr_help",displace:!1,side:"right"}),$(".sidr-btn").click((function(){$.sidr("close","sidr_help")}));let tree=$("#sgml_tree_body");$.get("./lib/reference.xml").done((function(result){ref_data=$(result),tree.empty(),ref_data.children().each((function(index,e){let name=`${$(e).prop("tagName")} ―― ${$(e).attr("overview")}`,c_node=$(`
    • ${name}
    • `).attr("data-help","scenario");tree.append(c_node),setChildNode(e,c_node,0)})),$("#help-tree").on("select_node.jstree",(function(e,data){let selector=transferQuery(data.node.data.help),txt,el=$(selector,ref_data);txt=0===el.children().length?el.text():el.children("outline").text();let ref=el.attr("ref");ref&&(txt+=$(transferQuery(ref),ref_data).text()),$("#sidr_help > #sidr_help_body").html(marked(txt)),$.sidr("open","sidr_help")})).jstree({plugins:["search"],search:{show_only_matches:!0,show_only_matches_children:!0}});let to=!1;$("#tree_keywd").on("input",(function(){to&&clearTimeout(to),to=setTimeout((function(){$("#help-tree").jstree(!0).search($("#tree_keywd").val())}),250)}))}));var tips=["左側のツリーから要素/属性を選択すると、右のサイドバーにヘルプドキュメントが表示されます。","ヘルプツリー上部のテキストボックスからキーワードを入力すると、合致する要素/属性のみ表示されます。","[試作用サンプル]テンプレートでは、あらかじめダミーデータが用意されています。これを書き換えることで、簡単なシナリオを手軽に作成できます。","テストプレイ画面の上部に表示されているのは、デバッグパネルです。シーンidを入力することで、強制的にページを移動できます。","テストプレイ画面の上部に表示されているのは、デバッグパネルです。アイテム/フラグidを入力することで、強制的にステータスを更新できます。","シナリオ開発に慣れてきたら、空のテンプレートがお勧めです。余計なデータが含まれない、最低限の枠組みだけを自動生成してくれます。","提供されている構文ハイライトはXML、Markdownの2種類。タグを編集する場合にはXMLを、テキストを編集する際にはMarkdownを利用します。","GBATはゲームブック作成に特化したクライアントアプリ。Playgroundでは、GBATで作成した.gbatファイルを変換し、エディター上にインポートすることもできます。","Playground Flowに作業環境を切り替えることで、シナリオのフローチャートを生成し、一望できます。最終的なリンクのチェックにどうぞ。","テンプレートには、チュートリアルも用意されています。初めてPlaygroundに触るならば、こちらから確認してみると良いでしょう。","Playground Editorでは、沢山のキーボードショートカットを用意しており、検索/置換はもちろん、行移動、コメントアウト、折り畳み、Undo/Redoなどの操作をキーボードだけで実行できます。","[<+>]ボタンでは、現在のカーソル位置にタグを挿入できます。","[<+>]ボタンでは、リンクや条件分岐も挿入できます。対象となるテキストを選択状態にしてから、メニューをクリックしてみましょう。","[機能テスト]テンプレートでは、ソーサリアン Textの主な機能を網羅したデータが含まれています。詳細な機能を発見し、確認するのに役立つかもしれません。","[ブラウザーに保存]ボタンで保存したデータは、テンプレートの「マイストレージ」から読み出すことができます。","[ブラウザーに保存]ボタンで、現在のシナリオをブラウザーに一時的に保存できます。ただし、きちんと保存するには[ダウンロード]でファイルに保存しましょう。"];toastr.options.closeButton=!0,toastr.options.positionClass="toast-bottom-full-width",toastr.options.showDuration=300,toastr.options.hideDuration=1e3,toastr.options.timeOut=7e3,toastr.info(tips[Math.floor(Math.random()*tips.length)],"TIPS")})); \ No newline at end of file +$((function(){let wordList=[{name:"scenario",meta:"element",score:666},{name:"title",meta:"attr(scenario)",score:777},{name:"author",meta:"attr(scenario)",score:777},{name:"init",meta:"element",score:666},{name:"constraint",meta:"element",score:888},{name:"race",meta:"attr(constraint)",score:888},{name:"FIGHTER",meta:"const(race)",score:888},{name:"WIZARD",meta:"const(race)",score:888},{name:"DWARF",meta:"const(race)",score:888},{name:"ELF",meta:"const(race)",score:888},{name:"sex",meta:"attr(constraint)",score:888},{name:"MALE",meta:"const(sex)",score:888},{name:"FEMALE",meta:"const(sex)",score:888},{name:"age",meta:"attr(constraint)",score:888},{name:"YOUNG",meta:"const(age)",score:888},{name:"ADULT",meta:"const(age)",score:888},{name:"OLD",meta:"const(age)",score:888},{name:"bgm",meta:"element",score:888},{name:"main",meta:"attr(bgm)",score:888},{name:"happy",meta:"attr(bgm)",score:888},{name:"bad",meta:"attr(bgm)",score:888},{name:"label",meta:"element",score:888},{name:"free1",meta:"attr(label)",score:888},{name:"free2",meta:"attr(label)",score:888},{name:"free3",meta:"attr(label)",score:888},{name:"intro",meta:"element",score:888},{name:"description",meta:"attr(intro)",score:888},{name:"items",meta:"element",score:666},{name:"item",meta:"element",score:999},{name:"id",value:'id="i',meta:"attr(item)",score:999},{name:"name",meta:"attr(item)",score:999},{name:"flags",meta:"element",score:666},{name:"flag",meta:"element",score:999},{name:"id",value:'id="f',meta:"attr(flag)",score:999},{name:"enemies",meta:"element",score:666},{name:"enemy",meta:"element",score:999},{name:"id",value:'id="m',meta:"attr(enemy)",score:999},{name:"name",meta:"attr(enemy)",score:999},{name:"element",meta:"attr(enemy)",score:999},{name:"earth",meta:"const(element)",score:888},{name:"fire",meta:"const(element)",score:888},{name:"water",meta:"const(element)",score:888},{name:"wind",meta:"const(element)",score:888},{name:"spirit",meta:"const(element)",score:888},{name:"attack",meta:"attr(enemy)",score:999},{name:"physics",meta:"const(attack)",score:888},{name:"magic",meta:"const(attack)",score:888},{name:"both",meta:"const(attack)",score:888},{name:"free1",meta:"const(attack)",score:888},{name:"free2",meta:"const(attack)",score:888},{name:"free3",meta:"const(attack)",score:888},{name:"poison",meta:"const(attack)",score:888},{name:"frozen",meta:"const(attack)",score:888},{name:"stone",meta:"const(attack)",score:888},{name:"curse",meta:"const(attack)",score:888},{name:"forget",meta:"const(attack)",score:888},{name:"func",meta:"attr(enemy)",score:999},{name:"STR",meta:"const(func)",score:888},{name:"INT",meta:"const(func)",score:888},{name:"DEX",meta:"const(func)",score:888},{name:"KRM",meta:"const(func)",score:888},{name:"FREE1",meta:"const(func)",score:888},{name:"FREE2",meta:"const(func)",score:888},{name:"FREE3",meta:"const(func)",score:888},{name:"drop",meta:"attr(enemy)",score:999},{name:"mon",meta:"const(drop)",score:888},{name:"tue",meta:"const(drop)",score:888},{name:"wed",meta:"const(drop)",score:888},{name:"thu",meta:"const(drop)",score:888},{name:"fri",meta:"const(drop)",score:888},{name:"sat",meta:"const(drop)",score:888},{name:"sun",meta:"const(drop)",score:888},{name:"results",meta:"element",score:666},{name:"result",meta:"element",score:999},{name:"id",value:'id="r',meta:"attr(result)",score:999},{name:"name",meta:"attr(result)",score:999},{name:"level",meta:"attr(result)",score:999},{name:"licence",meta:"element",score:666},{name:"work",meta:"element",score:888},{name:"category",meta:"attr(work)",score:888},{name:"bgm",meta:"const(category)",score:777},{name:"picture",meta:"const(category)",score:777},{name:"creator",meta:"attr(work)",score:888},{name:"url",meta:"attr(work)",score:888},{name:"scene",meta:"element",score:999},{name:"id",meta:"attr(scene)",score:999},{name:"items",meta:"attr(scene)",score:888},{name:"flags",meta:"attr(scene)",score:888},{name:"enemies",meta:"attr(scene)",score:888},{name:"stars",meta:"attr(scene)",score:888},{name:"hp",meta:"attr(scene)",score:888},{name:"mp",meta:"attr(scene)",score:888},{name:"free1",meta:"attr(scene)",score:888},{name:"free2",meta:"attr(scene)",score:888},{name:"free3",meta:"attr(scene)",score:888},{name:"result",meta:"attr(scene)",score:888},{name:"bgm",meta:"attr(scene)",score:888},{name:"se",meta:"attr(scene)",score:888},{name:"end",meta:"attr(scene)",score:888},{name:"happy",meta:"const(end)",score:777},{name:"bad",meta:"const(end)",score:777}],editor=ace.edit("editor"),langTools;editor.$blockScrolling=1/0,editor.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0}),editor.getSession().setUseWrapMode(!0),editor.setTheme("ace/theme/chrome"),editor.session.setMode("ace/mode/markdown"),ace.require("ace/ext/language_tools").addCompleter({getCompletions:function(editor,session,pos,prefix,callback){0!==prefix.length?callback(null,wordList.filter((function(ea){return 0===ea.name.indexOf(prefix)})).map((function(ea){return{name:ea.name,value:void 0===ea.value?ea.name:ea.value,score:ea.score,meta:ea.meta}}))):callback(null,[])}}),$("#pg_tag").click((function(e){$("#addmenu").css({display:"block",top:e.pageY,left:e.pageX})})),$(".addcom").click((function(e){var command={scene:'',scene_simple:'',item:'Item description...',flag:'Flag description...',param:'Param description...',enemy:'Enemy description...',result:'Result description...',work:'',basic:'',constraint:'',bgm:'',label:'',intro:''};editor.insert(command[$(this).data("command")]),editor.focus(),$("#addmenu").css("display","none")})),$("#pg_md").click((function(e){$("#addmd").css({display:"block",top:e.pageY,left:e.pageX})})),$("#addmd li").click((function(e){let command,comm={link:"[$0](num)",red:"%red%$0%/%",blue:"%blue%$0%/%",white:"%white%$0%/%",if:"${if condition}$0${/if}","*import":"${import 99999}",effect:"${effect type}$0${/effect}","*input":"${input?0}",ruby:"${$0|ruby}","*title":"${title}","*name":"${name}","*race":"${race?FIG:WIZ:DWA:ELF}","*sex":"${sex?M:F}","*state":"${state?NOR:POI:FRO:STO:FOR}","*age":"${age?Y:A:O}","*var":"${var?key:prop}","*random":"${rand?min:max}","*msg":"${msg?str1:str2:...}",tweet:"${tweet}%0%${/tweet}","*capture":"![caption](path)"}[$(this).data("command")];comm.startsWith("*")?editor.insert(comm):editor.insert(comm.replace("$0",editor.getCopyText())),$("#addmd").css("display","none")})),$("#pg_run").click((function(e){const RUN_NAME="pg2_run";localStorage.setItem(RUN_NAME,editor.getValue()),-1===location.host.indexOf("web-deli.com")?window.open("../index.html?id=pg2",RUN_NAME):window.open("../game.aspx?id=pg2",RUN_NAME)})),$("#pg_save").click((function(e){localStorage.playground_editor=editor.getValue(),window.alert("シナリオデータをブラウザーに保存しました。")})),$("#pg_gbat").click((function(e){$("#gbat").click()})),$("#pg_help").click((function(e){$("#helpmenu").css({display:"block",top:e.pageY,left:e.pageX})})),$("#helpmenu").click((function(e){$("#helpmenu").css("display","none")})),$(":not(#addmenu,#helpmenu)").click((function(e){"pg_tag"!==e.target.id&&$("#addmenu").css("display","none"),"pg_md"!==e.target.id&&$("#addmd").css("display","none"),"pg_help"!==e.target.id&&$("#helpmenu").css("display","none")})),$("#pg_dl").click((function(e){var blob=new Blob([editor.getValue()],{type:"application/octet-stream"}),anchor=document.createElement("a");anchor.href=window.URL.createObjectURL(blob),anchor.download="scenario.xml",document.body.appendChild(anchor),anchor.click(),document.body.removeChild(anchor)})),$("#pg_clear").click((function(e){confirm("編集内容をクリアしても良いですか?")&&editor.setValue("")})),$(window).on("beforeunload",(function(){return"ページを閉じてもよろしいですか?"})),$("#pg_editor2flow").click((function(e){$("body").css("opacity",.2),localStorage.editor2flow=editor.getValue(),window.open("./","pgflow")})),$('[name="lang"]').change((function(){console.log($('[name="lang"]:checked').val()),editor.session.setMode("ace/mode/"+$('[name="lang"]:checked').val())})),$("#gbat").gbat2stext((function(result){editor.setValue(vkbeautify.xml('\n'+result.get(0).outerHTML))}));var loadTemplate=function(selected,isFirst){selected&&$.ajax("../stext/playground/"+selected,{dataType:"text"}).done((function(data){editor.setValue(vkbeautify.xml(data)),isFirst&&window.alert("チュートリアルシナリオをロードしています。\r開始するには、上部のツールバーから[▶]ボタンを押してください。")}))};function getPath(current){let path=$(current).prop("tagName");return $(current).parents().each((function(index,e){path=`${$(e).prop("tagName")}/${path}`})),path}function setChildNode(parent,parent_node,num){let ch=(parent=$(parent)).children();if(0!==ch.length){let subtree=$("
        ");ch.each((function(index,e){let short_name=$(e).prop("tagName"),c_name=`${$(e).prop("tagName")} ―― ${$(e).attr("overview")}`;if(["outline","common","edge_flow","edge_common"].includes($(e).prop("tagName")))return!0;let c_node=$("
      • ").attr("data-help",getPath(e));0===$(e).children().length?c_node.attr("data-jstree",'{ "icon" : "jstree-file" }').text(`#${c_name}`):(c_node.text(c_name),num<1&&"scene"!==short_name&&c_node.attr("data-jstree",'{ "opened" : true }'));let alias=$(e).attr("name");alias&&c_node.text(`#${alias} ―― ${$(e).attr("overview")}`),subtree.append(c_node),0!==$(e).children().length&&setChildNode(e,c_node,num+1)})),$(parent_node).append(subtree)}}function transferQuery(selector){return selector.replace(/\//g," > ")}let ref_data;$("#template").change((function(e){var selected=$(this).val();if("storage"===selected){var save=localStorage.playground_editor;save?editor.setValue(save):window.alert("セーブデータは存在しません。")}else loadTemplate(selected)})),localStorage.flow2editor?(editor.setValue(vkbeautify.xml(localStorage.flow2editor)),localStorage.removeItem("flow2editor")):localStorage.tutorial_off?loadTemplate("scenario_empty.xml"):(loadTemplate("tutorial1.xml",!0),localStorage.tutorial_off=1),$("#region").sidr({name:"sidr_help",displace:!1,side:"right"}),$(".sidr-btn").click((function(){$.sidr("close","sidr_help")}));let tree=$("#sgml_tree_body");$.get("./lib/reference.xml").done((function(result){ref_data=$(result),tree.empty(),ref_data.children().each((function(index,e){let name=`${$(e).prop("tagName")} ―― ${$(e).attr("overview")}`,c_node=$(`
      • ${name}
      • `).attr("data-help","scenario");tree.append(c_node),setChildNode(e,c_node,0)})),$("#help-tree").on("select_node.jstree",(function(e,data){let selector=transferQuery(data.node.data.help),txt,el=$(selector,ref_data);txt=0===el.children().length?el.text():el.children("outline").text();let ref=el.attr("ref");ref&&(txt+=$(transferQuery(ref),ref_data).text()),$("#sidr_help > #sidr_help_body").html(marked(txt)),$.sidr("open","sidr_help")})).jstree({plugins:["search"],search:{show_only_matches:!0,show_only_matches_children:!0}});let to=!1;$("#tree_keywd").on("input",(function(){to&&clearTimeout(to),to=setTimeout((function(){$("#help-tree").jstree(!0).search($("#tree_keywd").val())}),250)}))}));var tips=["左側のツリーから要素/属性を選択すると、右のサイドバーにヘルプドキュメントが表示されます。","ヘルプツリー上部のテキストボックスからキーワードを入力すると、合致する要素/属性のみ表示されます。","[試作用サンプル]テンプレートでは、あらかじめダミーデータが用意されています。これを書き換えることで、簡単なシナリオを手軽に作成できます。","テストプレイ画面の上部に表示されているのは、デバッグパネルです。シーンidを入力することで、強制的にページを移動できます。","テストプレイ画面の上部に表示されているのは、デバッグパネルです。アイテム/フラグidを入力することで、強制的にステータスを更新できます。","シナリオ開発に慣れてきたら、空のテンプレートがお勧めです。余計なデータが含まれない、最低限の枠組みだけを自動生成してくれます。","提供されている構文ハイライトはXML、Markdownの2種類。タグを編集する場合にはXMLを、テキストを編集する際にはMarkdownを利用します。","GBATはゲームブック作成に特化したクライアントアプリ。Playgroundでは、GBATで作成した.gbatファイルを変換し、エディター上にインポートすることもできます。","Playground Flowに作業環境を切り替えることで、シナリオのフローチャートを生成し、一望できます。最終的なリンクのチェックにどうぞ。","テンプレートには、チュートリアルも用意されています。初めてPlaygroundに触るならば、こちらから確認してみると良いでしょう。","Playground Editorでは、沢山のキーボードショートカットを用意しており、検索/置換はもちろん、行移動、コメントアウト、折り畳み、Undo/Redoなどの操作をキーボードだけで実行できます。","[<+>]ボタンでは、現在のカーソル位置にタグを挿入できます。","[<+>]ボタンでは、リンクや条件分岐も挿入できます。対象となるテキストを選択状態にしてから、メニューをクリックしてみましょう。","[機能テスト]テンプレートでは、ソーサリアン Textの主な機能を網羅したデータが含まれています。詳細な機能を発見し、確認するのに役立つかもしれません。","[ブラウザーに保存]ボタンで保存したデータは、テンプレートの「マイストレージ」から読み出すことができます。","[ブラウザーに保存]ボタンで、現在のシナリオをブラウザーに一時的に保存できます。ただし、きちんと保存するには[ダウンロード]でファイルに保存しましょう。"];toastr.options.closeButton=!0,toastr.options.positionClass="toast-bottom-full-width",toastr.options.showDuration=300,toastr.options.hideDuration=1e3,toastr.options.timeOut=7e3,toastr.info(tips[Math.floor(Math.random()*tips.length)],"TIPS")})); \ No newline at end of file