From 469cb98bc7a8cfb104ae473bb0f737b2f9bf9c84 Mon Sep 17 00:00:00 2001 From: strawberry42271 <2806566736@qq.com> Date: Wed, 25 Dec 2024 00:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=83=8C=E6=99=AF=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E4=BA=8B=E4=BB=B6=EF=BC=8C=E6=A2=B3=E7=90=86=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E4=BA=8B=E4=BB=B6C0=5F1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/MotaAction.g4 | 19 + _server/MotaActionParser.js | 4787 ++++++++++++++++++++++------------- _server/config.json | 2 +- project/events.js | 381 ++- project/floors/street01.js | 6 + project/plugins.js | 385 ++- 6 files changed, 3703 insertions(+), 1877 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 2c0efb1..92f5744 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -857,6 +857,7 @@ action | battle_1_s | openDoor_s | closeDoor_s + | changebg_s | changeFloor_s | changePos_s | setViewport_s @@ -1889,6 +1890,20 @@ var code = '{"type": "sleep", "time": '+Int_0+Bool_0+'},\n'; return code; */; +changebg_s + : '上一个背景' EvalString? '下一个背景' EvalString? '切换时长' Int '转场方式' Changebg_List Newline + + +/* changebg_s +tooltip : changebg: 剧情转场 +helpUrl : /_docs/#/instruction +default : ["","",30,"引入"] +colour : this.soundColor +allImages : ['EvalString_0','EvalString_1'] +var code = '{"type": "changebg", "img1": "'+EvalString_0+'","img2": "'+EvalString_1+'","time": '+Int_0+',"style": "'+Changebg_List_0+'"},\n'; +return code; +*/; + drawWarning_s : '警告坐标x' PosString 'y' PosString '文字大小'Int '警告内容' EvalString? '副标题' EvalString? '不播放音效' Bool? Newline @@ -4194,6 +4209,10 @@ Bg_Fg_List : '背景层'|'前景层' /*Bg_Fg_List ['bg','fg']*/; +Changebg_List + : '引入'|'引出'|'场景切换' + /*Changebg_List ['引入','引出','场景切换']*/; + Bg_Fg2_List : '背景层'|'前景层'|'自适配' /*Bg_Fg2_List ['bg','fg','auto']*/; diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index 8cbbef1..fa30b1d 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -1,1788 +1,3119 @@ -MotaActionParser=function(){ -function ActionParser(){ -} +MotaActionParser = function () { + function ActionParser() {} -ActionParser.prototype.parse = function (obj,type) { - switch (type) { - case 'event': - if(!obj)obj={}; - if(typeof(obj)===typeof('')) obj={'data':[obj]}; - if(obj instanceof Array) obj={'data':obj}; - if (!obj.filter) obj.filter={}; - return MotaActionBlocks['event_m'].xmlText([ - obj.trigger==='action',obj.enable,obj.noPass,obj.displayDamage,obj.opacity, - obj.filter.blur,obj.filter.hue,obj.filter.grayscale,obj.filter.invert,obj.filter.shadow,this.parseList(obj.data) - ]); - - case 'autoEvent': - if(!obj)obj={}; - return MotaActionBlocks['autoEvent_m'].xmlText([ - obj.condition,obj.priority,obj.currentFloor,obj.delayExecute,obj.multiExecute,this.parseList(obj.data) - ]); - - case 'changeFloor': - if(!obj)obj={}; - if (!obj.loc) { - obj.loc = obj.loc || ['','']; - obj.stair = obj.stair || ':now'; - } - if (obj.floorId==':before'||obj.floorId==':next'||obj.floorId==':now') { - obj.floorType=obj.floorId; - delete obj.floorId; - } - return MotaActionBlocks['changeFloor_m'].xmlText([ - obj.floorType||'floorId',obj.floorId,obj.stair||'loc',obj.loc[0],obj.loc[1],obj.direction, - obj.time,obj.ignoreChangeFloor - ]); - - case 'afterGetItem': - if (!obj) obj = []; - if (obj instanceof Array) obj = {'data': obj}; - return MotaActionBlocks['afterGetItem_m'].xmlText([ - obj.disableOnGentleClick||false, this.parseList(obj.data) - ]); + ActionParser.prototype.parse = function (obj, type) { + switch (type) { + case "event": + if (!obj) obj = {}; + if (typeof obj === typeof "") obj = { data: [obj] }; + if (obj instanceof Array) obj = { data: obj }; + if (!obj.filter) obj.filter = {}; + return MotaActionBlocks["event_m"].xmlText([ + obj.trigger === "action", + obj.enable, + obj.noPass, + obj.displayDamage, + obj.opacity, + obj.filter.blur, + obj.filter.hue, + obj.filter.grayscale, + obj.filter.invert, + obj.filter.shadow, + this.parseList(obj.data), + ]); - case 'level': - if(!obj)obj={}; - var text_choices = null; - for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { - text_choices=MotaActionBlocks['levelCase'].xmlText([ - this.expandEvalBlock([choice.need]),choice.title,choice.clear||false,this.parseList(choice.action),text_choices]); - } - return MotaActionBlocks['level_m'].xmlText([text_choices]); + case "autoEvent": + if (!obj) obj = {}; + return MotaActionBlocks["autoEvent_m"].xmlText([ + obj.condition, + obj.priority, + obj.currentFloor, + obj.delayExecute, + obj.multiExecute, + this.parseList(obj.data), + ]); - case 'levelChoose': - if(!obj) obj=[]; - var text_choices = null; - for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { - text_choices=MotaActionBlocks['levelChooseChoice'].xmlText([ - choice.title, choice.name, choice.hard||0, choice.color, 'rgba('+choice.color+')', this.parseList(choice.action), text_choices]); - } - return MotaActionBlocks['levelChoose_m'].xmlText([text_choices]); + case "changeFloor": + if (!obj) obj = {}; + if (!obj.loc) { + obj.loc = obj.loc || ["", ""]; + obj.stair = obj.stair || ":now"; + } + if ( + obj.floorId == ":before" || + obj.floorId == ":next" || + obj.floorId == ":now" + ) { + obj.floorType = obj.floorId; + delete obj.floorId; + } + return MotaActionBlocks["changeFloor_m"].xmlText([ + obj.floorType || "floorId", + obj.floorId, + obj.stair || "loc", + obj.loc[0], + obj.loc[1], + obj.direction, + obj.time, + obj.ignoreChangeFloor, + ]); - case 'floorPartition': - if(!obj) obj=[]; - var text_choices = null; - for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { - text_choices=MotaActionBlocks['floorPartitionItem'].xmlText([choice[0], choice[1]||"", text_choices]); - } - return MotaActionBlocks['floorPartition_m'].xmlText([text_choices]); + case "afterGetItem": + if (!obj) obj = []; + if (obj instanceof Array) obj = { data: obj }; + return MotaActionBlocks["afterGetItem_m"].xmlText([ + obj.disableOnGentleClick || false, + this.parseList(obj.data), + ]); - case 'equip': - if(!obj) obj={}; - var buildEquip = function (obj) { - obj = obj || {}; + case "level": + if (!obj) obj = {}; var text_choices = null; - var knownEquipListKeys = MotaActionBlocks['Equip_List'].options.map(function (one) {return one[1];}) - Object.keys(obj).sort().forEach(function (key) { - var one = knownEquipListKeys.indexOf(key) >= 0 ? 'equipKnown' : 'equipUnknown'; - text_choices = MotaActionBlocks[one].xmlText([ - key, obj[key], text_choices + for (var ii = obj.length - 1, choice; (choice = obj[ii]); ii--) { + text_choices = MotaActionBlocks["levelCase"].xmlText([ + this.expandEvalBlock([choice.need]), + choice.title, + choice.clear || false, + this.parseList(choice.action), + text_choices, ]); - }) - return text_choices; - } - return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage), - this.parseList(obj.equipEvent), this.parseList(obj.unequipEvent)]); + } + return MotaActionBlocks["level_m"].xmlText([text_choices]); - case 'doorInfo': - if(!obj) obj={}; + case "levelChoose": + if (!obj) obj = []; + var text_choices = null; + for (var ii = obj.length - 1, choice; (choice = obj[ii]); ii--) { + text_choices = MotaActionBlocks["levelChooseChoice"].xmlText([ + choice.title, + choice.name, + choice.hard || 0, + choice.color, + "rgba(" + choice.color + ")", + this.parseList(choice.action), + text_choices, + ]); + } + return MotaActionBlocks["levelChoose_m"].xmlText([text_choices]); + + case "floorPartition": + if (!obj) obj = []; + var text_choices = null; + for (var ii = obj.length - 1, choice; (choice = obj[ii]); ii--) { + text_choices = MotaActionBlocks["floorPartitionItem"].xmlText([ + choice[0], + choice[1] || "", + text_choices, + ]); + } + return MotaActionBlocks["floorPartition_m"].xmlText([text_choices]); + + case "equip": + if (!obj) obj = {}; + var buildEquip = function (obj) { + obj = obj || {}; + var text_choices = null; + var knownEquipListKeys = MotaActionBlocks["Equip_List"].options.map( + function (one) { + return one[1]; + } + ); + Object.keys(obj) + .sort() + .forEach(function (key) { + var one = + knownEquipListKeys.indexOf(key) >= 0 + ? "equipKnown" + : "equipUnknown"; + text_choices = MotaActionBlocks[one].xmlText([ + key, + obj[key], + text_choices, + ]); + }); + return text_choices; + }; + return MotaActionBlocks["equip_m"].xmlText([ + obj.type, + obj.animate, + buildEquip(obj.value), + buildEquip(obj.percentage), + this.parseList(obj.equipEvent), + this.parseList(obj.unequipEvent), + ]); + + case "doorInfo": + if (!obj) obj = {}; var buildKeys = function (obj) { obj = obj || {}; var text_choices = null; - var knownListKeys = MotaActionBlocks['Key_List'].options.map(function (one) {return one[1];}) - Object.keys(obj).sort().forEach(function (key) { - var noNeed = key.endsWith(':o'); - if (noNeed) key = key.substring(0, key.length - 2); - var one = knownListKeys.indexOf(key) >= 0 ? 'doorKeyKnown' : 'doorKeyUnknown'; - text_choices = MotaActionBlocks[one].xmlText([ - one == 'doorKeyUnknown' ? MotaActionFunctions.replaceToName_token(key) : key, obj[key], noNeed, text_choices - ]); - }) + var knownListKeys = MotaActionBlocks["Key_List"].options.map( + function (one) { + return one[1]; + } + ); + Object.keys(obj) + .sort() + .forEach(function (key) { + var noNeed = key.endsWith(":o"); + if (noNeed) key = key.substring(0, key.length - 2); + var one = + knownListKeys.indexOf(key) >= 0 + ? "doorKeyKnown" + : "doorKeyUnknown"; + text_choices = MotaActionBlocks[one].xmlText([ + one == "doorKeyUnknown" + ? MotaActionFunctions.replaceToName_token(key) + : key, + obj[key], + noNeed, + text_choices, + ]); + }); return text_choices; - } - return MotaActionBlocks['doorInfo_m'].xmlText([obj.time || 160, obj.openSound, obj.closeSound, buildKeys(obj.keys), this.parseList(obj.afterOpenDoor)]); - - case 'floorImage': - if(!obj) obj=[]; - var text_choices = null; - for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { - text_choices=MotaActionBlocks['floorOneImage'].xmlText([ - choice.name, choice.reverse, choice.canvas||'bg', choice.x||0, choice.y||0, choice.disable||false, - choice.sx, choice.sy, choice.w, choice.h, choice.frame, text_choices]); - } - return MotaActionBlocks['floorImage_m'].xmlText([text_choices]); - - case 'faceIds': - if(!obj) obj={}; - return MotaActionBlocks['faceIds_m'].xmlText([obj.down||"", obj.left||"", obj.right||"", obj.up||""]); - - case 'splitImages': - if(!obj) obj=[]; - var text_choices = null; - for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { - text_choices=MotaActionBlocks['splitImagesOne'].xmlText([ - choice.name, choice.width, choice.height, choice.prefix, text_choices]); - } - return MotaActionBlocks['splitImages_m'].xmlText([text_choices]); - - case 'mainStyle': - if(!obj) obj={}; - return MotaActionBlocks['mainStyle_m'].xmlText([ - obj.startBackground, obj.startVerticalBackground || obj.startBackground, obj.startLogoStyle, obj.startButtonsStyle, - obj.statusLeftBackground, obj.statusTopBackground, obj.toolsBackground, obj.floorChangingStyle, - obj.statusBarColor, 'rgba('+obj.statusBarColor+')', obj.borderColor, 'rgba('+obj.borderColor+')', - obj.selectColor, 'rgba(' + obj.selectColor + ')', obj.font - ]); - - case 'nameMap': - if (!obj) obj={}; - var items = Object.keys(obj); - var result = null; - for (var ii=items.length-1,one;one=items[ii];ii--) { - var value = obj[one]; - var knownItems = MotaActionBlocks['NameMap_List'].options.map(function (one) {return one[1];}) - if (knownItems.indexOf(one) >= 0) { - result = MotaActionBlocks['nameMapSoundKnown'].xmlText([one, value, result]); - continue; - } - if (main.bgms.indexOf(value) >= 0) { - result = MotaActionBlocks['nameMapBgm'].xmlText([one, value, result]); - continue; - } - if (main.sounds.indexOf(value) >= 0) { - result = MotaActionBlocks['nameMapSoundUnknown'].xmlText([one, value, result]); - continue; - } - if (main.images.indexOf(value) >= 0) { - result = MotaActionBlocks['nameMapImage'].xmlText([one, value, result]); - continue; - } - if (main.animates.indexOf(value) >= 0) { - result = MotaActionBlocks['nameMapAnimate'].xmlText([one, value, result]); - continue; - } - result = MotaActionBlocks['nameMapUnknown'].xmlText([one, value, result]); - } - return MotaActionBlocks['nameMap_m'].xmlText([result]); - - case 'shop': - var buildsub = function(obj,parser,next){ - var text_choices = null; - for(var ii=obj.choices.length-1,choice;choice=obj.choices[ii];ii--) { - text_choices=MotaActionBlocks['shopChoices'].xmlText([ - choice.text,choice.need||'',choice.icon,choice.color,'rgba('+choice.color+')',choice.condition,parser.parseList(choice.action),text_choices]); - } - var info = parser.getTitleAndPosition(obj.text || ''); - return MotaActionBlocks['shopsub'].xmlText([ - obj.id,info[0],info[1],info[3],obj.textInList,obj.mustEnable,obj.disablePreview,text_choices,next + }; + return MotaActionBlocks["doorInfo_m"].xmlText([ + obj.time || 160, + obj.openSound, + obj.closeSound, + buildKeys(obj.keys), + this.parseList(obj.afterOpenDoor), ]); - } - var buildcommentevent = function(obj,parser,next){ - if (obj.args instanceof Array) { - obj.args = JSON.stringify(obj.args); - } - else obj.args = null; - return MotaActionBlocks['shopcommonevent'].xmlText([ - obj.id,parser.EvalString(obj.textInList),obj.mustEnable,parser.EvalString(obj.commonEvent),obj.args,next - ]); - } - var builditem = function (obj,parser,next){ + + case "floorImage": + if (!obj) obj = []; var text_choices = null; - for(var ii=obj.choices.length-1,choice;choice=obj.choices[ii];ii--) { - text_choices = MotaActionBlocks['shopItemChoices'].xmlText([ - choice.id, choice.number == null ? "" : (""+choice.number), choice.money == null ? "" : (""+choice.money), - choice.sell == null ? "" : (""+choice.sell), choice.condition || "", text_choices + for (var ii = obj.length - 1, choice; (choice = obj[ii]); ii--) { + text_choices = MotaActionBlocks["floorOneImage"].xmlText([ + choice.name, + choice.reverse, + choice.canvas || "bg", + choice.x || 0, + choice.y || 0, + choice.disable || false, + choice.sx, + choice.sy, + choice.w, + choice.h, + choice.frame, + text_choices, ]); } - return MotaActionBlocks['shopitem'].xmlText([ - obj.id,obj.textInList,obj.use||'money',obj.mustEnable,text_choices,next + return MotaActionBlocks["floorImage_m"].xmlText([text_choices]); + + case "faceIds": + if (!obj) obj = {}; + return MotaActionBlocks["faceIds_m"].xmlText([ + obj.down || "", + obj.left || "", + obj.right || "", + obj.up || "", ]); - } - var next=null; - if(!obj)obj=[]; - while(obj.length){ - var shopobj=obj.pop() - if(shopobj.item) - next=builditem(shopobj,this,next); - else if(shopobj.choices) - next=buildsub(shopobj,this,next); - else if(shopobj.commonEvent) - next=buildcommentevent(shopobj,this,next); - else - throw new Error("[警告]出错啦!\n"+shopobj.id+" 无效的商店"); - } - return MotaActionBlocks['shop_m'].xmlText([next]); - - default: - return MotaActionBlocks[type+'_m'].xmlText([this.parseList(obj)]); - } -} -////// 开始解析一系列自定义事件 ////// -ActionParser.prototype.parseList = function (list) { - if (!this.isset(list)) return MotaActionBlocks['pass_s'].xmlText([],true); - if (!(list instanceof Array)) { - list = [list]; - } - if (list.length===0) return MotaActionBlocks['pass_s'].xmlText([],true); - this.event = {'id': 'action', 'data': { - 'list': list - }} - this.next = null; - this.result = null; - this.parseAction(); - return this.result; -} - -////// 解析当前自定义事件列表中的最后一个事件 ////// -ActionParser.prototype.parseAction = function() { - - // 事件处理完毕 - if (this.event.data.list.length==0) { - this.result = this.next; - this.next = null; - return; - } - - var data = this.event.data.list.pop(); - this.event.data.current = data; - - // 不同种类的事件 - - // 如果是文字:显示 - if (typeof data == "string") { - data={"type": "text", "text": data} - } - this.event.data.type=data.type; - switch (data.type) { - case "_next": - this.result = this.next; - this.next = data.next; - return; - case "text": // 文字/对话 - var info = this.getTitleAndPosition(data.text); - var textDrawing = []; - info[3] = (info[3] || "").replace(/(\f|\\f)\[(.*?)]/g, function (text, sympol, str) { - var ss = str.split(","); - if (ss.length == 3 || ss.length == 5 || ss.length >=9) { - var swap = function (i, j) { var x = ss[i]; ss[i] = ss[j]; ss[j] = x;} - if (ss.length >= 9) { - swap(1,5); swap(2,6); swap(3,7); swap(4,8); - } - textDrawing.push(ss); + case "splitImages": + if (!obj) obj = []; + var text_choices = null; + for (var ii = obj.length - 1, choice; (choice = obj[ii]); ii--) { + text_choices = MotaActionBlocks["splitImagesOne"].xmlText([ + choice.name, + choice.width, + choice.height, + choice.prefix, + text_choices, + ]); } - return ''; - }); - if (textDrawing.length > 0) { - var buildTextDrawing = function (obj) { - if(!obj) obj=[]; - var text_choices = null; - for(var ii=obj.length-1,choice;choice=obj[ii];ii--) { - var reverse = 'null'; - if (choice[0].endsWith(':o') || choice[0].endsWith(':x') || choice[0].endsWith(':y')) { - reverse = choice[0].substring(choice[0].length - 2); - choice[0] = choice[0].substring(0, choice[0].length - 2); + return MotaActionBlocks["splitImages_m"].xmlText([text_choices]); + + case "mainStyle": + if (!obj) obj = {}; + return MotaActionBlocks["mainStyle_m"].xmlText([ + obj.startBackground, + obj.startVerticalBackground || obj.startBackground, + obj.startLogoStyle, + obj.startButtonsStyle, + obj.statusLeftBackground, + obj.statusTopBackground, + obj.toolsBackground, + obj.floorChangingStyle, + obj.statusBarColor, + "rgba(" + obj.statusBarColor + ")", + obj.borderColor, + "rgba(" + obj.borderColor + ")", + obj.selectColor, + "rgba(" + obj.selectColor + ")", + obj.font, + ]); + + case "nameMap": + if (!obj) obj = {}; + var items = Object.keys(obj); + var result = null; + for (var ii = items.length - 1, one; (one = items[ii]); ii--) { + var value = obj[one]; + var knownItems = MotaActionBlocks["NameMap_List"].options.map( + function (one) { + return one[1]; } - text_choices=MotaActionBlocks['textDrawing'].xmlText([ - choice[0], reverse, choice[1], choice[2], choice[3], choice[4], choice[5], choice[6], - choice[7], choice[8], choice[9], choice[10], text_choices]); + ); + if (knownItems.indexOf(one) >= 0) { + result = MotaActionBlocks["nameMapSoundKnown"].xmlText([ + one, + value, + result, + ]); + continue; } - return text_choices; + if (main.bgms.indexOf(value) >= 0) { + result = MotaActionBlocks["nameMapBgm"].xmlText([ + one, + value, + result, + ]); + continue; + } + if (main.sounds.indexOf(value) >= 0) { + result = MotaActionBlocks["nameMapSoundUnknown"].xmlText([ + one, + value, + result, + ]); + continue; + } + if (main.images.indexOf(value) >= 0) { + result = MotaActionBlocks["nameMapImage"].xmlText([ + one, + value, + result, + ]); + continue; + } + if (main.animates.indexOf(value) >= 0) { + result = MotaActionBlocks["nameMapAnimate"].xmlText([ + one, + value, + result, + ]); + continue; + } + result = MotaActionBlocks["nameMapUnknown"].xmlText([ + one, + value, + result, + ]); } - data.pos = data.pos || []; - this.next = MotaActionFunctions.xmlText('text_2_s', [ - info[0], info[1], info[2], data.pos[0], data.pos[1], data.pos[2], data.code||0, data.async||false, info[3], buildTextDrawing(textDrawing), this.next - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - } else if (info[0] || info[1] || info[2] || data.pos || data.code) { - data.pos = data.pos || []; - this.next = MotaActionFunctions.xmlText('text_1_s',[ - info[0], info[1], info[2], data.pos[0], data.pos[1], data.pos[2], data.code||0, data.async||false, info[3], this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - } - else { - this.next = MotaActionFunctions.xmlText('text_0_s', [info[3],this.next], - /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - } - break; - case "cgtext": // cg对话框 - var buildcgDrawing= function (obj) { - obj = MotaActionFunctions.processcgDrawing(obj||[]); - var res = null; - for(var ii=obj.length-1,one;one=obj[ii];ii--) { - - res=MotaActionBlocks['textcgDrawing'].xmlText([one[0],one[1],one[2], res]); - } - return res; + return MotaActionBlocks["nameMap_m"].xmlText([result]); + + case "shop": + var buildsub = function (obj, parser, next) { + var text_choices = null; + for ( + var ii = obj.choices.length - 1, choice; + (choice = obj.choices[ii]); + ii-- + ) { + text_choices = MotaActionBlocks["shopChoices"].xmlText([ + choice.text, + choice.need || "", + choice.icon, + choice.color, + "rgba(" + choice.color + ")", + choice.condition, + parser.parseList(choice.action), + text_choices, + ]); + } + var info = parser.getTitleAndPosition(obj.text || ""); + return MotaActionBlocks["shopsub"].xmlText([ + obj.id, + info[0], + info[1], + info[3], + obj.textInList, + obj.mustEnable, + obj.disablePreview, + text_choices, + next, + ]); + }; + var buildcommentevent = function (obj, parser, next) { + if (obj.args instanceof Array) { + obj.args = JSON.stringify(obj.args); + } else obj.args = null; + return MotaActionBlocks["shopcommonevent"].xmlText([ + obj.id, + parser.EvalString(obj.textInList), + obj.mustEnable, + parser.EvalString(obj.commonEvent), + obj.args, + next, + ]); + }; + var builditem = function (obj, parser, next) { + var text_choices = null; + for ( + var ii = obj.choices.length - 1, choice; + (choice = obj.choices[ii]); + ii-- + ) { + text_choices = MotaActionBlocks["shopItemChoices"].xmlText([ + choice.id, + choice.number == null ? "" : "" + choice.number, + choice.money == null ? "" : "" + choice.money, + choice.sell == null ? "" : "" + choice.sell, + choice.condition || "", + text_choices, + ]); + } + return MotaActionBlocks["shopitem"].xmlText([ + obj.id, + obj.textInList, + obj.use || "money", + obj.mustEnable, + text_choices, + next, + ]); + }; + var next = null; + if (!obj) obj = []; + while (obj.length) { + var shopobj = obj.pop(); + if (shopobj.item) next = builditem(shopobj, this, next); + else if (shopobj.choices) next = buildsub(shopobj, this, next); + else if (shopobj.commonEvent) + next = buildcommentevent(shopobj, this, next); + else throw new Error("[警告]出错啦!\n" + shopobj.id + " 无效的商店"); + } + return MotaActionBlocks["shop_m"].xmlText([next]); + + default: + return MotaActionBlocks[type + "_m"].xmlText([this.parseList(obj)]); } - this.next = MotaActionBlocks['cgtext_s'].xmlText([ - data.bg,data.WindowSkin,data.head.name, data.name||"", data.head.px||-300,data.time, data.sound,data.text,buildcgDrawing(data.bodyList), this.next]); - - break; - case "moveTextBox": // 移动对话框 - data.loc = data.loc || ['','']; - this.next = MotaActionBlocks['moveTextBox_s'].xmlText([ - data.code, data.loc[0], data.loc[1], data.relative||false, data.moveMode, data.time, data.async, this.next]); - break; - case "clearTextBox": // 清除对话框 - this.next = MotaActionBlocks['clearTextBox_s'].xmlText([(data.code||"").toString(),this.next]); - break; - case "autoText": // 自动剧情文本 - var info = this.getTitleAndPosition(data.text); - this.next = MotaActionBlocks['autoText_s'].xmlText([ - info[0],info[1],info[2],data.time,info[3],this.next]); - break; - case "scrollText": - this.next = MotaActionBlocks['scrollText_s'].xmlText([ - data.time, data.lineHeight||1.4, data.async||false, this.EvalString_Multi(data.text), this.next]); + }; + + ////// 开始解析一系列自定义事件 ////// + ActionParser.prototype.parseList = function (list) { + if (!this.isset(list)) return MotaActionBlocks["pass_s"].xmlText([], true); + if (!(list instanceof Array)) { + list = [list]; + } + if (list.length === 0) return MotaActionBlocks["pass_s"].xmlText([], true); + this.event = { + id: "action", + data: { + list: list, + }, + }; + this.next = null; + this.result = null; + this.parseAction(); + return this.result; + }; + + ////// 解析当前自定义事件列表中的最后一个事件 ////// + ActionParser.prototype.parseAction = function () { + // 事件处理完毕 + if (this.event.data.list.length == 0) { + this.result = this.next; + this.next = null; + return; + } + + var data = this.event.data.list.pop(); + this.event.data.current = data; + + // 不同种类的事件 + + // 如果是文字:显示 + if (typeof data == "string") { + data = { type: "text", text: data }; + } + this.event.data.type = data.type; + switch (data.type) { + case "_next": + this.result = this.next; + this.next = data.next; + return; + case "text": // 文字/对话 + var info = this.getTitleAndPosition(data.text); + var textDrawing = []; + info[3] = (info[3] || "").replace( + /(\f|\\f)\[(.*?)]/g, + function (text, sympol, str) { + var ss = str.split(","); + if (ss.length == 3 || ss.length == 5 || ss.length >= 9) { + var swap = function (i, j) { + var x = ss[i]; + ss[i] = ss[j]; + ss[j] = x; + }; + if (ss.length >= 9) { + swap(1, 5); + swap(2, 6); + swap(3, 7); + swap(4, 8); + } + textDrawing.push(ss); + } + return ""; + } + ); + if (textDrawing.length > 0) { + var buildTextDrawing = function (obj) { + if (!obj) obj = []; + var text_choices = null; + for (var ii = obj.length - 1, choice; (choice = obj[ii]); ii--) { + var reverse = "null"; + if ( + choice[0].endsWith(":o") || + choice[0].endsWith(":x") || + choice[0].endsWith(":y") + ) { + reverse = choice[0].substring(choice[0].length - 2); + choice[0] = choice[0].substring(0, choice[0].length - 2); + } + text_choices = MotaActionBlocks["textDrawing"].xmlText([ + choice[0], + reverse, + choice[1], + choice[2], + choice[3], + choice[4], + choice[5], + choice[6], + choice[7], + choice[8], + choice[9], + choice[10], + text_choices, + ]); + } + return text_choices; + }; + data.pos = data.pos || []; + this.next = MotaActionFunctions.xmlText( + "text_2_s", + [ + info[0], + info[1], + info[2], + data.pos[0], + data.pos[1], + data.pos[2], + data.code || 0, + data.async || false, + info[3], + buildTextDrawing(textDrawing), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + } else if (info[0] || info[1] || info[2] || data.pos || data.code) { + data.pos = data.pos || []; + this.next = MotaActionFunctions.xmlText( + "text_1_s", + [ + info[0], + info[1], + info[2], + data.pos[0], + data.pos[1], + data.pos[2], + data.code || 0, + data.async || false, + info[3], + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + } else { + this.next = MotaActionFunctions.xmlText( + "text_0_s", + [info[3], this.next], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + } + break; + case "cgtext": // cg对话框 + var buildcgDrawing = function (obj) { + obj = MotaActionFunctions.processcgDrawing(obj || []); + var res = null; + for (var ii = obj.length - 1, one; (one = obj[ii]); ii--) { + res = MotaActionBlocks["textcgDrawing"].xmlText([ + one[0], + one[1], + one[2], + res, + ]); + } + return res; + }; + this.next = MotaActionBlocks["cgtext_s"].xmlText([ + data.bg, + data.WindowSkin, + data.head.name, + data.name || "", + data.head.px || -300, + data.time, + data.sound, + data.text, + buildcgDrawing(data.bodyList), + this.next, + ]); + + break; + case "moveTextBox": // 移动对话框 + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["moveTextBox_s"].xmlText([ + data.code, + data.loc[0], + data.loc[1], + data.relative || false, + data.moveMode, + data.time, + data.async, + this.next, + ]); + break; + case "clearTextBox": // 清除对话框 + this.next = MotaActionBlocks["clearTextBox_s"].xmlText([ + (data.code || "").toString(), + this.next, + ]); + break; + case "autoText": // 自动剧情文本 + var info = this.getTitleAndPosition(data.text); + this.next = MotaActionBlocks["autoText_s"].xmlText([ + info[0], + info[1], + info[2], + data.time, + info[3], + this.next, + ]); + break; + case "scrollText": + this.next = MotaActionBlocks["scrollText_s"].xmlText([ + data.time, + data.lineHeight || 1.4, + data.async || false, + this.EvalString_Multi(data.text), + this.next, + ]); + break; + case "comment": // 注释 + this.next = MotaActionBlocks["comment_s"].xmlText([ + this.EvalString_Multi(data.text), + this.next, + ]); + break; + case "setText": // 设置剧情文本的属性 + data.title = this.Colour(data.title); + data.text = this.Colour(data.text); + if (!/^\w+\.png$/.test(data.background)) + data.background = this.Colour(data.background); + this.next = MotaActionBlocks["setText_s"].xmlText([ + data.position, + data.offset, + data.align, + data.bold, + data.title, + "rgba(" + data.title + ")", + data.text, + "rgba(" + data.text + ")", + data.background, + "rgba(" + data.background + ")", + data.titlefont, + data.textfont, + data.lineHeight, + data.time, + data.letterSpacing, + data.animateTime, + this.next, + ]); + break; + case "addPop": + this.next = MotaActionBlocks["addPop_s"].xmlText([ + data.value, + data.px, + data.py, + data.color, + "rgba(" + data.color + ")", + data.boldColor, + "rgba(" + data.boldColor + ")", + data.left, + data.jump, + data.time, + data.show, + data.font, + data.speed, + this.next, + ]); break; - case "comment": // 注释 - this.next = MotaActionBlocks['comment_s'].xmlText([this.EvalString_Multi(data.text),this.next]); - break; - case "setText": // 设置剧情文本的属性 - data.title=this.Colour(data.title); - data.text=this.Colour(data.text); - if (!/^\w+\.png$/.test(data.background)) - data.background=this.Colour(data.background); - this.next = MotaActionBlocks['setText_s'].xmlText([ - data.position,data.offset,data.align,data.bold,data.title,'rgba('+data.title+')', - data.text,'rgba('+data.text+')',data.background,'rgba('+data.background+')', - data.titlefont,data.textfont,data.lineHeight,data.time,data.letterSpacing,data.animateTime,this.next]); - break; - case "addPop": - this.next = MotaActionBlocks['addPop_s'].xmlText([ - data.value,data.px, data.py, data.color,'rgba('+data.color+')', data.boldColor,'rgba('+data.boldColor+')', data.left, data.jump, data.time, data.show, data.font, data.speed,this.next]); - break; case "over": - this.next = MotaActionBlocks['over_s'].xmlText([ - data.text??"",data.image??"", data.time??3000, data.hidetime??100,data.sound??"", data.textColor,'rgba('+data.textColor+')', data.boldColor,'rgba('+data.boldColor+')', data.font??"bold 48px Verdana",this.next]); - break; - case "tip": - this.next = MotaActionBlocks['tip_s'].xmlText([ - data.text,data.icon||"",this.next]); - break; - case "show": // 显示 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['show_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',data.time,data.async||false,this.next]); - break; - case "hide": // 消失 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['hide_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',data.remove||false,data.time,data.async||false,this.next]); - break; - case "setBlock": // 设置图块 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['setBlock_s'].xmlText([ - data.number||0,x_str.join(','),y_str.join(','),data.floorId||'',data.time,data.async||false,this.next]); - break; - case "setBlockOpacity": // 设置图块不透明度 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['setBlockOpacity_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',data.opacity,data.time,data.async||false,this.next]); - break; - case "setBlockFilter": // 设置图块不透明度 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['setBlockFilter_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',data.blur,data.hue,data.grayscale,data.invert||false,data.shadow,this.next]); - break; - case "turnBlock": // 事件转向 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['turnBlock_s'].xmlText([ - data.direction,x_str.join(','),y_str.join(','),data.floorId||'',this.next]); - break; - case "showFloorImg": // 显示贴图 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['showFloorImg_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',this.next]); - break; - case "hideFloorImg": // 隐藏贴图 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['hideFloorImg_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',this.next]); - break; - case "showBgFgMap": // 显示图层块 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['showBgFgMap_s'].xmlText([ - data.name||'bg', x_str.join(','),y_str.join(','),data.floorId||'',this.next]); - break; - case "hideBgFgMap": // 隐藏图层块 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['hideBgFgMap_s'].xmlText([ - data.name||'bg', x_str.join(','),y_str.join(','),data.floorId||'',this.next]); - break; - case "setBgFgBlock": // 设置图块 - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['setBgFgBlock_s'].xmlText([ - data.name||'bg', data.number||0, x_str.join(','),y_str.join(','),data.floorId||'',this.next]); - break; - case "setHeroIcon": // 改变勇士 - this.next = MotaActionBlocks['setHeroIcon_s'].xmlText([ - data.name||"", data.noDraw || false, this.next]); - break; - case "move": // 移动事件 - data.loc=data.loc||['','']; - var buildMoveDirection= function (obj) { - obj = MotaActionFunctions.processMoveDirections(obj||[]); - var res = null; - for(var ii=obj.length-1,one;one=obj[ii];ii--) { - var v = one.split(':'); - res=MotaActionBlocks['moveDirection'].xmlText([v[0], parseInt(v[1]), res]); - } - return res; - } - this.next = MotaActionBlocks['move_s'].xmlText([ - data.loc[0],data.loc[1],data.time,data.keep||false,data.async||false,buildMoveDirection(data.steps),this.next]); - break; - case "moveAction": // 前进一格或撞击 - this.next = MotaActionBlocks['moveAction_s'].xmlText([this.next]); - break; - case "moveHero": // 无视地形移动勇士 - var buildMoveDirection= function (obj) { - obj = MotaActionFunctions.processMoveDirections(obj||[]); - var res = null; - for(var ii=obj.length-1,one;one=obj[ii];ii--) { - var v = one.split(':'); - res=MotaActionBlocks['moveDirection'].xmlText([v[0], parseInt(v[1]), res]); - } - return res; - } - this.next = MotaActionBlocks['moveHero_s'].xmlText([ - data.time,data.async||false,buildMoveDirection(data.steps),this.next]); - break; - case "jump": // 跳跃事件 - data.from=data.from||['','']; - if (data.dxy) { - this.next = MotaActionBlocks['jump_1_s'].xmlText([ - data.from[0],data.from[1],data.dxy[0],data.dxy[1],data.time,data.keep||false,data.async||false,this.next]); - } else { - data.to=data.to||['','']; - this.next = MotaActionBlocks['jump_s'].xmlText([ - data.from[0],data.from[1],data.to[0],data.to[1],data.time,data.keep||false,data.async||false,this.next]); - } - break; - case "jumpHero": // 跳跃勇士 - if (data.dxy) { - this.next = MotaActionBlocks['jumpHero_1_s'].xmlText([ - data.dxy[0],data.dxy[1],data.time,data.async||false,this.next]); - } else { - data.loc=data.loc||['',''] - this.next = MotaActionBlocks['jumpHero_s'].xmlText([ - data.loc[0],data.loc[1],data.time,data.async||false,this.next]); - } - break; - case "changeFloor": // 楼层转换 - if (!data.loc) { - data.loc = data.loc || ['','']; - data.stair = data.stair || ':now'; - } - if (data.floorId==':before'||data.floorId==':next'||data.floorId==':now') { - data.floorType=data.floorId; - delete data.floorId; - } - this.next = MotaActionBlocks['changeFloor_s'].xmlText([ - data.floorType||'floorId',data.floorId,data.stair||'loc',data.loc[0],data.loc[1],data.direction, - data.time, this.next]); - break; - case "changePos": // 直接更换勇士位置, 不切换楼层 - data.loc=data.loc||['',''] - this.next = MotaActionBlocks['changePos_s'].xmlText([ - data.loc[0],data.loc[1],data.direction,this.next]); - break; - case "follow": // 跟随勇士 - this.next = MotaActionBlocks['follow_s'].xmlText([data.name||"", this.next]); - break; - case "unfollow": // 取消跟随 - this.next = MotaActionBlocks['unfollow_s'].xmlText([data.name||"", this.next]); - break; - case "animate": // 显示动画 - if (data.loc == 'hero') { - this.next = MotaActionBlocks['animate_1_s'].xmlText([ - data.name,data.async||false,this.next]); - } else { - data.loc=data.loc||['','']; - this.next = MotaActionBlocks['animate_s'].xmlText([ - data.name,data.loc[0],data.loc[1],data.alignWindow||false,data.async||false,this.next]); - } - break; - case "stopAnimate": // 停止所有动画 - this.next = MotaActionBlocks['stopAnimate_s'].xmlText([data.doCallback||false,this.next]); - break; - case "setViewport": // 设置视角 - if (data.dxy) { - this.next = MotaActionBlocks['setViewport_1_s'].xmlText([ - data.dxy[0],data.dxy[1],data.moveMode||'', data.time||0,data.async||false,this.next]); - } else { - data.loc = data.loc||['','']; - this.next = MotaActionBlocks['setViewport_s'].xmlText([ - data.loc[0],data.loc[1],data.moveMode||'', data.time||0,data.async||false,this.next]); - } - break; - case "lockViewport": - this.next = MotaActionBlocks['lockViewport_s'].xmlText([data.lock, - this.next]); - break; - case "vibrate": // 画面震动 - this.next = MotaActionBlocks['vibrate_s'].xmlText([data.direction||'horizontal', - data.time||0, data.speed, data.power, data.async||false, this.next]); - break; - case "showImage": // 显示图片 - data.loc=data.loc||['',''] - if (data.sloc) { - this.next = MotaActionBlocks['showImage_1_s'].xmlText([ - data.code,data.image||data.name,data.reverse,data.sloc[0],data.sloc[1],data.sloc[2],data.sloc[3],data.opacity, - data.loc[0],data.loc[1],data.loc[2],data.loc[3],data.time||0,data.async||false,this.next + this.next = MotaActionBlocks["over_s"].xmlText([ + data.text ?? "", + data.image ?? "", + data.time ?? 3000, + data.hidetime ?? 100, + data.sound ?? "", + data.textColor, + "rgba(" + data.textColor + ")", + data.boldColor, + "rgba(" + data.boldColor + ")", + data.font ?? "bold 48px Verdana", + this.next, ]); - } - else { - this.next = MotaActionBlocks['showImage_s'].xmlText([ - data.code,data.image||data.name,data.reverse,data.loc[0],data.loc[1],data.opacity,data.time||0,data.async||false,this.next]); - } - break; - case "hideImage": // 清除图片 - this.next = MotaActionBlocks['hideImage_s'].xmlText([ - data.code,data.time||0,data.async||false,this.next]); - break; - case "showTextImage": // 显示图片化文本 - data.loc=data.loc||['',''] - this.next = MotaActionBlocks['showTextImage_s'].xmlText([ - this.EvalString_Multi(data.text),data.code,data.loc[0],data.loc[1],data.lineHeight||1.4,data.reverse,data.opacity,data.time||0,data.async||false,this.next]); - break; - case "moveImage": // 移动图片 - data.to=data.to||['',''] - this.next = MotaActionBlocks['moveImage_s'].xmlText([ - data.code, data.to[0], data.to[1], data.opacity, data.moveMode||'', data.time||0, data.async||false, this.next]); - break; - case "rotateImage": // 旋转图片 - data.center=data.center||['',''] - this.next = MotaActionBlocks['rotateImage_s'].xmlText([ - data.code, data.center[0], data.center[1], data.moveMode||'', data.angle||0, data.time||0, data.async||false, this.next]); - break; - case "scaleImage": // 放缩图片 - data.center=data.center||['',''] - this.next = MotaActionBlocks['scaleImage_s'].xmlText([ - data.code, data.center[0], data.center[1], data.moveMode||'', data.scale, data.time||0, data.async||false, this.next]); - break; - case "showGif": // 显示动图 - data.loc=data.loc||['',''] - this.next = MotaActionBlocks['showGif_s'].xmlText([ - data.name,data.loc[0],data.loc[1],this.next]); - break; - case "setCurtain": // 颜色渐变 - if(this.isset(data.color)){ - data.color = this.Colour(data.color); - this.next = MotaActionBlocks['setCurtain_0_s'].xmlText([ - data.color,'rgba('+data.color+')',data.time,data.moveMode,data.keep||false,data.async||false,this.next]); - } else { - this.next = MotaActionBlocks['setCurtain_1_s'].xmlText([ - data.time,data.moveMode,data.async||false,this.next]); - } - break; - case "screenFlash": // 画面闪烁 - data.color = this.Colour(data.color); - this.next = MotaActionBlocks['screenFlash_s'].xmlText([ - data.color,'rgba('+data.color+')',data.time||500,data.times,data.moveMode,data.async||false,this.next]); - break; - case "setWeather": // 更改天气 - this.next = MotaActionBlocks['setWeather_s'].xmlText([ - data.name,data.level||1,data.keep||false,this.next]); - break; - case "openDoor": // 开一个门, 包括暗墙 - data.loc=data.loc||['',''] - this.next = MotaActionBlocks['openDoor_s'].xmlText([ - data.loc[0],data.loc[1],data.floorId||'',data.needKey||false,data.async||false,this.next]); - break; - case "closeDoor": // 关一个门,需要该点无事件 - data.loc=data.loc||['',''] - this.next = MotaActionBlocks['closeDoor_s'].xmlText([ - data.loc[0],data.loc[1],data.id,data.async||false,this.next]); - break; - case "useItem": // 使用道具 - this.next = MotaActionBlocks['useItem_s'].xmlText([ - MotaActionFunctions.replaceToName_token(data.id),this.next]); - break; - case "loadEquip": // 装上装备 - this.next = MotaActionBlocks['loadEquip_s'].xmlText([ - MotaActionFunctions.replaceToName_token(data.id),this.next]); - break; - case "unloadEquip": // 卸下装备 - this.next = MotaActionBlocks['unloadEquip_s'].xmlText([ - data.pos,this.next]); - break; - case "openShop": // 打开一个全局商店 - this.next = MotaActionBlocks['openShop_s'].xmlText([ - data.id,data.open||false,this.next]); - break; - case "disableShop": // 禁用一个全局商店 - this.next = MotaActionBlocks['disableShop_s'].xmlText([ - data.id,this.next]); - break; - case "battle": // 强制战斗 - if (data.id) { - this.next = MotaActionBlocks['battle_s'].xmlText([ - MotaActionFunctions.replaceToName_token(data.id),this.next]); - } - else { + break; + case "tip": + this.next = MotaActionBlocks["tip_s"].xmlText([ + data.text, + data.icon || "", + this.next, + ]); + break; + case "show": // 显示 data.loc = data.loc || []; - this.next = MotaActionBlocks['battle_1_s'].xmlText([ - data.loc[0],data.loc[1],this.next]); - } - break; - case "trigger": // 触发另一个事件 - data.loc = data.loc || []; - this.next = MotaActionBlocks['trigger_s'].xmlText([ - data.loc[0],data.loc[1],this.next]); - break; - case "insert": // 强制插入另一个点的事件在当前事件列表执行,当前坐标和楼层不会改变 - if (data.args instanceof Array) { - data.args = JSON.stringify(data.args); - } - else data.args = null; - if (this.isset(data.name)) { - this.next = MotaActionBlocks['insert_1_s'].xmlText([ - data.name, data.args||"", this.next]); - } - else { + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["show_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.time, + data.async || false, + this.next, + ]); + break; + case "hide": // 消失 data.loc = data.loc || []; - this.next = MotaActionBlocks['insert_2_s'].xmlText([ - data.loc[0],data.loc[1],data.which,data.floorId||'',data.args||"",this.next]); - } - break; - case "playStereo": - this.next = MotaActionBlocks['playStereo_s'].xmlText([ - data.name, data.left, data.right, data.split||true,this.next]); - break - case "moveStereo": - this.next = MotaActionBlocks['moveStereo_s'].xmlText([ - data.name, data.left, data.right, data.split||true,data.leftTo, data.rightTo, data.time,this.next]); - break - case "playSound": - var knownItems = MotaActionBlocks['NameMap_List'].options.map(function (one) {return one[1];}); - if (knownItems.indexOf(data.name) >= 0) { - this.next = MotaActionBlocks['playSound_1_s'].xmlText([ - data.name,data.stop,data.pitch||"",data.sync,this.next]); - } else { - this.next = MotaActionBlocks['playSound_s'].xmlText([ - data.name,data.stop,data.pitch||"",data.sync,this.next]); - } - break; - case "playBgm": - this.next = MotaActionBlocks['playBgm_s'].xmlText([ - data.name,data.startTime||0,data.keep||false,this.next]); - break - case "pauseBgm": - this.next = MotaActionBlocks['pauseBgm_s'].xmlText([ - this.next]); - break - case "resumeBgm": - this.next = MotaActionBlocks['resumeBgm_s'].xmlText([ - data.resume||false,this.next]); - break - case "loadBgm": - this.next = MotaActionBlocks['loadBgm_s'].xmlText([ - data.name,this.next]); - break - case "freeBgm": - this.next = MotaActionBlocks['freeBgm_s'].xmlText([ - data.name,this.next]); - break - case "stopSound": - this.next = MotaActionBlocks['stopSound_s'].xmlText([ - this.next]); - break - case "setVolume": - this.next = MotaActionBlocks['setVolume_s'].xmlText([ - data.value, data.time, data.async||false, this.next]); - break - case "setBgmSpeed": - this.next = MotaActionBlocks['setBgmSpeed_s'].xmlText([ - data.value, data.pitch||false, this.next]); - break; - case "setValue": - this.next = MotaActionBlocks['setValue_s'].xmlText([ - this.expandIdBlock([data.name]), data["operator"]||'=', - this.expandEvalBlock([data.value]), - data.norefresh || false, - this.next]); - break; - case "setEnemy": - this.next = MotaActionBlocks['setEnemy_s'].xmlText([ - MotaActionFunctions.replaceToName_token(data.id), data.name, data["operator"]||'=', this.expandEvalBlock([data.value]), - data.norefresh||false, this.next]); - break; - case "setEnemyOnPoint": - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['setEnemyOnPoint_s'].xmlText([ - x_str.join(','),y_str.join(','),data.floorId||'',data.name, data["operator"]||'=', this.expandEvalBlock([data.value]), - data.norefresh||false, this.next]); - break; - case "resetEnemyOnPoint": - data.loc=data.loc||[]; - if (!(data.loc[0] instanceof Array)) - data.loc = [data.loc]; - var x_str=[],y_str=[]; - data.loc.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['resetEnemyOnPoint_s'].xmlText([ - x_str.join(','),y_str.join(','), data.floorId||'',data.norefresh||false,this.next]); - break; - case "moveEnemyOnPoint": - data.from=data.from||['',''] - if (data.dxy) { - this.next = MotaActionBlocks['moveEnemyOnPoint_1_s'].xmlText([ - data.from[0], data.from[1], data.dxy[0], data.dxy[1], data.floorId||'',data.norefresh||false,this.next]); - } else { - data.to=data.to||['',''] - this.next = MotaActionBlocks['moveEnemyOnPoint_s'].xmlText([ - data.from[0], data.from[1], data.to[0], data.to[1], data.floorId||'',data.norefresh||false,this.next]); - } - break; - case "setEquip": - this.next = MotaActionBlocks['setEquip_s'].xmlText([ - MotaActionFunctions.replaceToName_token(data.id), data.valueType||'value', data.name, data["operator"]||'=', this.expandEvalBlock([data.value]), this.next]); - break; - case "setFloor": - this.next = MotaActionBlocks['setFloor_s'].xmlText([ - data.name, data.floorId||null, JSON.stringify(data.value), this.next]); - break; - case "setGlobalAttribute": - this.next = MotaActionBlocks['setGlobalAttribute_s'].xmlText([ - data.name, data.value, this.next]); - break; - case "setGlobalValue": - this.next = MotaActionBlocks['setGlobalValue_s'].xmlText([ - data.name, data.value, this.next]); - break; - case "setGlobalFlag": - this.next = MotaActionBlocks['setGlobalFlag_s'].xmlText([ - data.name, data.value, this.next]); - break; - case "setNameMap": - this.next = MotaActionBlocks['setNameMap_s'].xmlText([ - data.name, data.value, this.next]); - break; - case "input": - this.next = MotaActionBlocks['input_s'].xmlText([ - data.text,this.next]); - break; - case "input2": - this.next = MotaActionBlocks['input2_s'].xmlText([ - data.text,this.next]); - break; - case "if": // 条件判断 - if (data["false"]) { - this.next = MotaActionFunctions.xmlText('if_s', [ - this.expandEvalBlock([data.condition]), - this.insertActionList(data["true"]), - this.insertActionList(data["false"]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - } - else { - this.next = MotaActionFunctions.xmlText('if_1_s', [ - this.expandEvalBlock([data.condition]), - this.insertActionList(data["true"]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - } - break; - case "confirm": // 显示确认框 - this.next = MotaActionFunctions.xmlText('confirm_s', [ - this.EvalString_Multi(data.text), data.timeout||0, data["default"], - this.insertActionList(data["yes"]), - this.insertActionList(data["no"]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "switch": // 多重条件分歧 - var case_caseList = null; - for(var ii=data.caseList.length-1,caseNow;caseNow=data.caseList[ii];ii--) { - case_caseList=MotaActionFunctions.xmlText('switchCase', [ - this.isset(caseNow.case)?this.expandEvalBlock([caseNow.case]):"值",caseNow.nobreak,this.insertActionList(caseNow.action),case_caseList], - /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); - } - this.next = MotaActionFunctions.xmlText('switch_s', [ - this.expandEvalBlock([data.condition]), - case_caseList,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "choices": // 提供选项 - var text_choices = null; - for(var ii=data.choices.length-1,choice;choice=data.choices[ii];ii--) { - choice.color = this.Colour(choice.color); - text_choices=MotaActionFunctions.xmlText('choicesContext', [ - choice.text,choice.icon,choice.color,'rgba('+choice.color+')',choice.need||'',choice.condition||'',this.insertActionList(choice.action),text_choices], - /* isShadow */false, /*comment*/ null, /*collapsed*/ choice._collapsed, /*disabled*/ choice._disabled); - } - if (!this.isset(data.text)) data.text = ''; - var info = this.getTitleAndPosition(data.text); - this.next = MotaActionFunctions.xmlText('choices_s', [ - info[3],info[0],info[1],data.timeout||0,data.width,text_choices,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "for": // 循环遍历 - this.next = MotaActionFunctions.xmlText('for_s',[ - this.expandEvalBlock([data.name]), - data.from || 0, data.to || 0, data.step || 0, - this.insertActionList(data.data), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "forEach": // 循环遍历列表 - this.next = MotaActionFunctions.xmlText('forEach_s',[ - this.expandEvalBlock([data.name]), - JSON.stringify(data.list), - this.insertActionList(data.data), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "while": // 前置条件循环处理 - this.next = MotaActionFunctions.xmlText('while_s',[ - this.expandEvalBlock([data.condition]), - this.insertActionList(data.data), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "dowhile": // 后置条件循环处理 - this.next = MotaActionFunctions.xmlText('dowhile_s',[ - this.insertActionList(data.data), - this.expandEvalBlock([data.condition]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "break": // 跳出循环 - this.next = MotaActionBlocks['break_s'].xmlText([ - data.n || 1, this.next]); - break; - case "continue": // 继续执行当前循环 - this.next = MotaActionBlocks['continue_s'].xmlText([ - data.n || 1, this.next]); - break; - case "win": - this.next = MotaActionBlocks['win_s'].xmlText([ - data.reason,data.norank?true:false,data.noexit?true:false,this.next]); - break; - case "lose": - this.next = MotaActionBlocks['lose_s'].xmlText([ - data.reason,this.next]); - break; - case "restart": - this.next = MotaActionBlocks['restart_s'].xmlText([ - this.next]); - break; - case "function": - var func = data["function"]; - func=func.split('{').slice(1).join('{').split('}').slice(0,-1).join('}').trim().split('\n').join('\\n'); - this.next = MotaActionBlocks['function_s'].xmlText([ - data.async||false,func,this.next]); - break; - case "update": - this.next = MotaActionBlocks['update_s'].xmlText([ - this.doNotCheckAutoEvents||false, this.next]); - break; - case "showStatusBar": - this.next = MotaActionBlocks['showStatusBar_s'].xmlText([ - this.next]); - break; - case "hideStatusBar": - this.next = MotaActionBlocks['hideStatusBar_s'].xmlText([ - data.toolbox||false,this.next]); - break; - case "setHeroOpacity": - this.next = MotaActionBlocks['setHeroOpacity_s'].xmlText([ - data.opacity, data.moveMode, data.time, data.async||false, this.next]); - break; - case "sleep": // 等待多少毫秒 - this.next = MotaActionBlocks['sleep_s'].xmlText([ - data.time||0,data.noSkip||false,this.next]); - break; - case "wait": // 等待用户操作 - var case_waitList = null; - if (data.data) { - for(var ii=data.data.length-1,caseNow;caseNow=data.data[ii];ii--) { - if (caseNow["case"] == "keyboard") { - case_waitList = MotaActionFunctions.xmlText('waitContext_1',[ - caseNow.keycode || "0", caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); - } else if (caseNow["case"] == "mouse") { - case_waitList = MotaActionFunctions.xmlText('waitContext_2',[ - caseNow.px[0], caseNow.px[1], caseNow.py[0], caseNow.py[1], caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); - } else if (caseNow["case"] == "condition") { - case_waitList = MotaActionFunctions.xmlText('waitContext_3',[ - this.expandEvalBlock([caseNow.condition]), caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); - } else if (caseNow["case"] == "timeout") { - case_waitList = MotaActionFunctions.xmlText('waitContext_4',[ - caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["hide_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.remove || false, + data.time, + data.async || false, + this.next, + ]); + break; + case "setBlock": // 设置图块 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["setBlock_s"].xmlText([ + data.number || 0, + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.time, + data.async || false, + this.next, + ]); + break; + case "setBlockOpacity": // 设置图块不透明度 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["setBlockOpacity_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.opacity, + data.time, + data.async || false, + this.next, + ]); + break; + case "setBlockFilter": // 设置图块不透明度 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["setBlockFilter_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.blur, + data.hue, + data.grayscale, + data.invert || false, + data.shadow, + this.next, + ]); + break; + case "turnBlock": // 事件转向 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["turnBlock_s"].xmlText([ + data.direction, + x_str.join(","), + y_str.join(","), + data.floorId || "", + this.next, + ]); + break; + case "showFloorImg": // 显示贴图 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["showFloorImg_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + this.next, + ]); + break; + case "hideFloorImg": // 隐藏贴图 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["hideFloorImg_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + this.next, + ]); + break; + case "showBgFgMap": // 显示图层块 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["showBgFgMap_s"].xmlText([ + data.name || "bg", + x_str.join(","), + y_str.join(","), + data.floorId || "", + this.next, + ]); + break; + case "hideBgFgMap": // 隐藏图层块 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["hideBgFgMap_s"].xmlText([ + data.name || "bg", + x_str.join(","), + y_str.join(","), + data.floorId || "", + this.next, + ]); + break; + case "setBgFgBlock": // 设置图块 + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["setBgFgBlock_s"].xmlText([ + data.name || "bg", + data.number || 0, + x_str.join(","), + y_str.join(","), + data.floorId || "", + this.next, + ]); + break; + case "setHeroIcon": // 改变勇士 + this.next = MotaActionBlocks["setHeroIcon_s"].xmlText([ + data.name || "", + data.noDraw || false, + this.next, + ]); + break; + case "move": // 移动事件 + data.loc = data.loc || ["", ""]; + var buildMoveDirection = function (obj) { + obj = MotaActionFunctions.processMoveDirections(obj || []); + var res = null; + for (var ii = obj.length - 1, one; (one = obj[ii]); ii--) { + var v = one.split(":"); + res = MotaActionBlocks["moveDirection"].xmlText([ + v[0], + parseInt(v[1]), + res, + ]); + } + return res; + }; + this.next = MotaActionBlocks["move_s"].xmlText([ + data.loc[0], + data.loc[1], + data.time, + data.keep || false, + data.async || false, + buildMoveDirection(data.steps), + this.next, + ]); + break; + case "moveAction": // 前进一格或撞击 + this.next = MotaActionBlocks["moveAction_s"].xmlText([this.next]); + break; + case "moveHero": // 无视地形移动勇士 + var buildMoveDirection = function (obj) { + obj = MotaActionFunctions.processMoveDirections(obj || []); + var res = null; + for (var ii = obj.length - 1, one; (one = obj[ii]); ii--) { + var v = one.split(":"); + res = MotaActionBlocks["moveDirection"].xmlText([ + v[0], + parseInt(v[1]), + res, + ]); + } + return res; + }; + this.next = MotaActionBlocks["moveHero_s"].xmlText([ + data.time, + data.async || false, + buildMoveDirection(data.steps), + this.next, + ]); + break; + case "jump": // 跳跃事件 + data.from = data.from || ["", ""]; + if (data.dxy) { + this.next = MotaActionBlocks["jump_1_s"].xmlText([ + data.from[0], + data.from[1], + data.dxy[0], + data.dxy[1], + data.time, + data.keep || false, + data.async || false, + this.next, + ]); + } else { + data.to = data.to || ["", ""]; + this.next = MotaActionBlocks["jump_s"].xmlText([ + data.from[0], + data.from[1], + data.to[0], + data.to[1], + data.time, + data.keep || false, + data.async || false, + this.next, + ]); + } + break; + case "jumpHero": // 跳跃勇士 + if (data.dxy) { + this.next = MotaActionBlocks["jumpHero_1_s"].xmlText([ + data.dxy[0], + data.dxy[1], + data.time, + data.async || false, + this.next, + ]); + } else { + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["jumpHero_s"].xmlText([ + data.loc[0], + data.loc[1], + data.time, + data.async || false, + this.next, + ]); + } + break; + case "changeFloor": // 楼层转换 + if (!data.loc) { + data.loc = data.loc || ["", ""]; + data.stair = data.stair || ":now"; + } + if ( + data.floorId == ":before" || + data.floorId == ":next" || + data.floorId == ":now" + ) { + data.floorType = data.floorId; + delete data.floorId; + } + this.next = MotaActionBlocks["changeFloor_s"].xmlText([ + data.floorType || "floorId", + data.floorId, + data.stair || "loc", + data.loc[0], + data.loc[1], + data.direction, + data.time, + this.next, + ]); + break; + case "changePos": // 直接更换勇士位置, 不切换楼层 + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["changePos_s"].xmlText([ + data.loc[0], + data.loc[1], + data.direction, + this.next, + ]); + break; + case "follow": // 跟随勇士 + this.next = MotaActionBlocks["follow_s"].xmlText([ + data.name || "", + this.next, + ]); + break; + case "unfollow": // 取消跟随 + this.next = MotaActionBlocks["unfollow_s"].xmlText([ + data.name || "", + this.next, + ]); + break; + case "animate": // 显示动画 + if (data.loc == "hero") { + this.next = MotaActionBlocks["animate_1_s"].xmlText([ + data.name, + data.async || false, + this.next, + ]); + } else { + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["animate_s"].xmlText([ + data.name, + data.loc[0], + data.loc[1], + data.alignWindow || false, + data.async || false, + this.next, + ]); + } + break; + case "stopAnimate": // 停止所有动画 + this.next = MotaActionBlocks["stopAnimate_s"].xmlText([ + data.doCallback || false, + this.next, + ]); + break; + case "setViewport": // 设置视角 + if (data.dxy) { + this.next = MotaActionBlocks["setViewport_1_s"].xmlText([ + data.dxy[0], + data.dxy[1], + data.moveMode || "", + data.time || 0, + data.async || false, + this.next, + ]); + } else { + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["setViewport_s"].xmlText([ + data.loc[0], + data.loc[1], + data.moveMode || "", + data.time || 0, + data.async || false, + this.next, + ]); + } + break; + case "lockViewport": + this.next = MotaActionBlocks["lockViewport_s"].xmlText([ + data.lock, + this.next, + ]); + break; + case "vibrate": // 画面震动 + this.next = MotaActionBlocks["vibrate_s"].xmlText([ + data.direction || "horizontal", + data.time || 0, + data.speed, + data.power, + data.async || false, + this.next, + ]); + break; + case "showImage": // 显示图片 + data.loc = data.loc || ["", ""]; + if (data.sloc) { + this.next = MotaActionBlocks["showImage_1_s"].xmlText([ + data.code, + data.image || data.name, + data.reverse, + data.sloc[0], + data.sloc[1], + data.sloc[2], + data.sloc[3], + data.opacity, + data.loc[0], + data.loc[1], + data.loc[2], + data.loc[3], + data.time || 0, + data.async || false, + this.next, + ]); + } else { + this.next = MotaActionBlocks["showImage_s"].xmlText([ + data.code, + data.image || data.name, + data.reverse, + data.loc[0], + data.loc[1], + data.opacity, + data.time || 0, + data.async || false, + this.next, + ]); + } + break; + case "hideImage": // 清除图片 + this.next = MotaActionBlocks["hideImage_s"].xmlText([ + data.code, + data.time || 0, + data.async || false, + this.next, + ]); + break; + case "showTextImage": // 显示图片化文本 + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["showTextImage_s"].xmlText([ + this.EvalString_Multi(data.text), + data.code, + data.loc[0], + data.loc[1], + data.lineHeight || 1.4, + data.reverse, + data.opacity, + data.time || 0, + data.async || false, + this.next, + ]); + break; + case "moveImage": // 移动图片 + data.to = data.to || ["", ""]; + this.next = MotaActionBlocks["moveImage_s"].xmlText([ + data.code, + data.to[0], + data.to[1], + data.opacity, + data.moveMode || "", + data.time || 0, + data.async || false, + this.next, + ]); + break; + case "rotateImage": // 旋转图片 + data.center = data.center || ["", ""]; + this.next = MotaActionBlocks["rotateImage_s"].xmlText([ + data.code, + data.center[0], + data.center[1], + data.moveMode || "", + data.angle || 0, + data.time || 0, + data.async || false, + this.next, + ]); + break; + case "scaleImage": // 放缩图片 + data.center = data.center || ["", ""]; + this.next = MotaActionBlocks["scaleImage_s"].xmlText([ + data.code, + data.center[0], + data.center[1], + data.moveMode || "", + data.scale, + data.time || 0, + data.async || false, + this.next, + ]); + break; + case "showGif": // 显示动图 + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["showGif_s"].xmlText([ + data.name, + data.loc[0], + data.loc[1], + this.next, + ]); + break; + case "setCurtain": // 颜色渐变 + if (this.isset(data.color)) { + data.color = this.Colour(data.color); + this.next = MotaActionBlocks["setCurtain_0_s"].xmlText([ + data.color, + "rgba(" + data.color + ")", + data.time, + data.moveMode, + data.keep || false, + data.async || false, + this.next, + ]); + } else { + this.next = MotaActionBlocks["setCurtain_1_s"].xmlText([ + data.time, + data.moveMode, + data.async || false, + this.next, + ]); + } + break; + case "screenFlash": // 画面闪烁 + data.color = this.Colour(data.color); + this.next = MotaActionBlocks["screenFlash_s"].xmlText([ + data.color, + "rgba(" + data.color + ")", + data.time || 500, + data.times, + data.moveMode, + data.async || false, + this.next, + ]); + break; + case "setWeather": // 更改天气 + this.next = MotaActionBlocks["setWeather_s"].xmlText([ + data.name, + data.level || 1, + data.keep || false, + this.next, + ]); + break; + case "openDoor": // 开一个门, 包括暗墙 + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["openDoor_s"].xmlText([ + data.loc[0], + data.loc[1], + data.floorId || "", + data.needKey || false, + data.async || false, + this.next, + ]); + break; + case "closeDoor": // 关一个门,需要该点无事件 + data.loc = data.loc || ["", ""]; + this.next = MotaActionBlocks["closeDoor_s"].xmlText([ + data.loc[0], + data.loc[1], + data.id, + data.async || false, + this.next, + ]); + break; + case "useItem": // 使用道具 + this.next = MotaActionBlocks["useItem_s"].xmlText([ + MotaActionFunctions.replaceToName_token(data.id), + this.next, + ]); + break; + case "loadEquip": // 装上装备 + this.next = MotaActionBlocks["loadEquip_s"].xmlText([ + MotaActionFunctions.replaceToName_token(data.id), + this.next, + ]); + break; + case "unloadEquip": // 卸下装备 + this.next = MotaActionBlocks["unloadEquip_s"].xmlText([ + data.pos, + this.next, + ]); + break; + case "openShop": // 打开一个全局商店 + this.next = MotaActionBlocks["openShop_s"].xmlText([ + data.id, + data.open || false, + this.next, + ]); + break; + case "disableShop": // 禁用一个全局商店 + this.next = MotaActionBlocks["disableShop_s"].xmlText([ + data.id, + this.next, + ]); + break; + case "battle": // 强制战斗 + if (data.id) { + this.next = MotaActionBlocks["battle_s"].xmlText([ + MotaActionFunctions.replaceToName_token(data.id), + this.next, + ]); + } else { + data.loc = data.loc || []; + this.next = MotaActionBlocks["battle_1_s"].xmlText([ + data.loc[0], + data.loc[1], + this.next, + ]); + } + break; + case "trigger": // 触发另一个事件 + data.loc = data.loc || []; + this.next = MotaActionBlocks["trigger_s"].xmlText([ + data.loc[0], + data.loc[1], + this.next, + ]); + break; + case "insert": // 强制插入另一个点的事件在当前事件列表执行,当前坐标和楼层不会改变 + if (data.args instanceof Array) { + data.args = JSON.stringify(data.args); + } else data.args = null; + if (this.isset(data.name)) { + this.next = MotaActionBlocks["insert_1_s"].xmlText([ + data.name, + data.args || "", + this.next, + ]); + } else { + data.loc = data.loc || []; + this.next = MotaActionBlocks["insert_2_s"].xmlText([ + data.loc[0], + data.loc[1], + data.which, + data.floorId || "", + data.args || "", + this.next, + ]); + } + break; + case "playStereo": + this.next = MotaActionBlocks["playStereo_s"].xmlText([ + data.name, + data.left, + data.right, + data.split || true, + this.next, + ]); + break; + case "moveStereo": + this.next = MotaActionBlocks["moveStereo_s"].xmlText([ + data.name, + data.left, + data.right, + data.split || true, + data.leftTo, + data.rightTo, + data.time, + this.next, + ]); + break; + case "playSound": + var knownItems = MotaActionBlocks["NameMap_List"].options.map(function ( + one + ) { + return one[1]; + }); + if (knownItems.indexOf(data.name) >= 0) { + this.next = MotaActionBlocks["playSound_1_s"].xmlText([ + data.name, + data.stop, + data.pitch || "", + data.sync, + this.next, + ]); + } else { + this.next = MotaActionBlocks["playSound_s"].xmlText([ + data.name, + data.stop, + data.pitch || "", + data.sync, + this.next, + ]); + } + break; + case "playBgm": + this.next = MotaActionBlocks["playBgm_s"].xmlText([ + data.name, + data.startTime || 0, + data.keep || false, + this.next, + ]); + break; + case "pauseBgm": + this.next = MotaActionBlocks["pauseBgm_s"].xmlText([this.next]); + break; + case "resumeBgm": + this.next = MotaActionBlocks["resumeBgm_s"].xmlText([ + data.resume || false, + this.next, + ]); + break; + case "loadBgm": + this.next = MotaActionBlocks["loadBgm_s"].xmlText([ + data.name, + this.next, + ]); + break; + case "freeBgm": + this.next = MotaActionBlocks["freeBgm_s"].xmlText([ + data.name, + this.next, + ]); + break; + case "stopSound": + this.next = MotaActionBlocks["stopSound_s"].xmlText([this.next]); + break; + case "setVolume": + this.next = MotaActionBlocks["setVolume_s"].xmlText([ + data.value, + data.time, + data.async || false, + this.next, + ]); + break; + case "setBgmSpeed": + this.next = MotaActionBlocks["setBgmSpeed_s"].xmlText([ + data.value, + data.pitch || false, + this.next, + ]); + break; + case "setValue": + this.next = MotaActionBlocks["setValue_s"].xmlText([ + this.expandIdBlock([data.name]), + data["operator"] || "=", + this.expandEvalBlock([data.value]), + data.norefresh || false, + this.next, + ]); + break; + case "setEnemy": + this.next = MotaActionBlocks["setEnemy_s"].xmlText([ + MotaActionFunctions.replaceToName_token(data.id), + data.name, + data["operator"] || "=", + this.expandEvalBlock([data.value]), + data.norefresh || false, + this.next, + ]); + break; + case "setEnemyOnPoint": + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["setEnemyOnPoint_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.name, + data["operator"] || "=", + this.expandEvalBlock([data.value]), + data.norefresh || false, + this.next, + ]); + break; + case "resetEnemyOnPoint": + data.loc = data.loc || []; + if (!(data.loc[0] instanceof Array)) data.loc = [data.loc]; + var x_str = [], + y_str = []; + data.loc.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["resetEnemyOnPoint_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.floorId || "", + data.norefresh || false, + this.next, + ]); + break; + case "moveEnemyOnPoint": + data.from = data.from || ["", ""]; + if (data.dxy) { + this.next = MotaActionBlocks["moveEnemyOnPoint_1_s"].xmlText([ + data.from[0], + data.from[1], + data.dxy[0], + data.dxy[1], + data.floorId || "", + data.norefresh || false, + this.next, + ]); + } else { + data.to = data.to || ["", ""]; + this.next = MotaActionBlocks["moveEnemyOnPoint_s"].xmlText([ + data.from[0], + data.from[1], + data.to[0], + data.to[1], + data.floorId || "", + data.norefresh || false, + this.next, + ]); + } + break; + case "setEquip": + this.next = MotaActionBlocks["setEquip_s"].xmlText([ + MotaActionFunctions.replaceToName_token(data.id), + data.valueType || "value", + data.name, + data["operator"] || "=", + this.expandEvalBlock([data.value]), + this.next, + ]); + break; + case "setFloor": + this.next = MotaActionBlocks["setFloor_s"].xmlText([ + data.name, + data.floorId || null, + JSON.stringify(data.value), + this.next, + ]); + break; + case "setGlobalAttribute": + this.next = MotaActionBlocks["setGlobalAttribute_s"].xmlText([ + data.name, + data.value, + this.next, + ]); + break; + case "setGlobalValue": + this.next = MotaActionBlocks["setGlobalValue_s"].xmlText([ + data.name, + data.value, + this.next, + ]); + break; + case "setGlobalFlag": + this.next = MotaActionBlocks["setGlobalFlag_s"].xmlText([ + data.name, + data.value, + this.next, + ]); + break; + case "setNameMap": + this.next = MotaActionBlocks["setNameMap_s"].xmlText([ + data.name, + data.value, + this.next, + ]); + break; + case "input": + this.next = MotaActionBlocks["input_s"].xmlText([data.text, this.next]); + break; + case "input2": + this.next = MotaActionBlocks["input2_s"].xmlText([ + data.text, + this.next, + ]); + break; + case "if": // 条件判断 + if (data["false"]) { + this.next = MotaActionFunctions.xmlText( + "if_s", + [ + this.expandEvalBlock([data.condition]), + this.insertActionList(data["true"]), + this.insertActionList(data["false"]), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + } else { + this.next = MotaActionFunctions.xmlText( + "if_1_s", + [ + this.expandEvalBlock([data.condition]), + this.insertActionList(data["true"]), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + } + break; + case "confirm": // 显示确认框 + this.next = MotaActionFunctions.xmlText( + "confirm_s", + [ + this.EvalString_Multi(data.text), + data.timeout || 0, + data["default"], + this.insertActionList(data["yes"]), + this.insertActionList(data["no"]), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "switch": // 多重条件分歧 + var case_caseList = null; + for ( + var ii = data.caseList.length - 1, caseNow; + (caseNow = data.caseList[ii]); + ii-- + ) { + case_caseList = MotaActionFunctions.xmlText( + "switchCase", + [ + this.isset(caseNow.case) + ? this.expandEvalBlock([caseNow.case]) + : "值", + caseNow.nobreak, + this.insertActionList(caseNow.action), + case_caseList, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ caseNow._collapsed, + /*disabled*/ caseNow._disabled + ); + } + this.next = MotaActionFunctions.xmlText( + "switch_s", + [this.expandEvalBlock([data.condition]), case_caseList, this.next], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "choices": // 提供选项 + var text_choices = null; + for ( + var ii = data.choices.length - 1, choice; + (choice = data.choices[ii]); + ii-- + ) { + choice.color = this.Colour(choice.color); + text_choices = MotaActionFunctions.xmlText( + "choicesContext", + [ + choice.text, + choice.icon, + choice.color, + "rgba(" + choice.color + ")", + choice.need || "", + choice.condition || "", + this.insertActionList(choice.action), + text_choices, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ choice._collapsed, + /*disabled*/ choice._disabled + ); + } + if (!this.isset(data.text)) data.text = ""; + var info = this.getTitleAndPosition(data.text); + this.next = MotaActionFunctions.xmlText( + "choices_s", + [ + info[3], + info[0], + info[1], + data.timeout || 0, + data.width, + text_choices, + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "for": // 循环遍历 + this.next = MotaActionFunctions.xmlText( + "for_s", + [ + this.expandEvalBlock([data.name]), + data.from || 0, + data.to || 0, + data.step || 0, + this.insertActionList(data.data), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "forEach": // 循环遍历列表 + this.next = MotaActionFunctions.xmlText( + "forEach_s", + [ + this.expandEvalBlock([data.name]), + JSON.stringify(data.list), + this.insertActionList(data.data), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "while": // 前置条件循环处理 + this.next = MotaActionFunctions.xmlText( + "while_s", + [ + this.expandEvalBlock([data.condition]), + this.insertActionList(data.data), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "dowhile": // 后置条件循环处理 + this.next = MotaActionFunctions.xmlText( + "dowhile_s", + [ + this.insertActionList(data.data), + this.expandEvalBlock([data.condition]), + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "break": // 跳出循环 + this.next = MotaActionBlocks["break_s"].xmlText([ + data.n || 1, + this.next, + ]); + break; + case "continue": // 继续执行当前循环 + this.next = MotaActionBlocks["continue_s"].xmlText([ + data.n || 1, + this.next, + ]); + break; + case "win": + this.next = MotaActionBlocks["win_s"].xmlText([ + data.reason, + data.norank ? true : false, + data.noexit ? true : false, + this.next, + ]); + break; + case "lose": + this.next = MotaActionBlocks["lose_s"].xmlText([ + data.reason, + this.next, + ]); + break; + case "restart": + this.next = MotaActionBlocks["restart_s"].xmlText([this.next]); + break; + case "function": + var func = data["function"]; + func = func + .split("{") + .slice(1) + .join("{") + .split("}") + .slice(0, -1) + .join("}") + .trim() + .split("\n") + .join("\\n"); + this.next = MotaActionBlocks["function_s"].xmlText([ + data.async || false, + func, + this.next, + ]); + break; + case "update": + this.next = MotaActionBlocks["update_s"].xmlText([ + this.doNotCheckAutoEvents || false, + this.next, + ]); + break; + case "showStatusBar": + this.next = MotaActionBlocks["showStatusBar_s"].xmlText([this.next]); + break; + case "hideStatusBar": + this.next = MotaActionBlocks["hideStatusBar_s"].xmlText([ + data.toolbox || false, + this.next, + ]); + break; + case "setHeroOpacity": + this.next = MotaActionBlocks["setHeroOpacity_s"].xmlText([ + data.opacity, + data.moveMode, + data.time, + data.async || false, + this.next, + ]); + break; + case "sleep": // 等待多少毫秒 + this.next = MotaActionBlocks["sleep_s"].xmlText([ + data.time || 0, + data.noSkip || false, + this.next, + ]); + break; + case "changebg": // 等待多少毫秒 + this.next = MotaActionBlocks["changebg_s"].xmlText([ + data.img1 ?? "", + data.img2 ?? "", + data.time ?? 30, + data.style, + this.next, + ]); + break; + case "wait": // 等待用户操作 + var case_waitList = null; + if (data.data) { + for ( + var ii = data.data.length - 1, caseNow; + (caseNow = data.data[ii]); + ii-- + ) { + if (caseNow["case"] == "keyboard") { + case_waitList = MotaActionFunctions.xmlText( + "waitContext_1", + [ + caseNow.keycode || "0", + caseNow["break"] || false, + this.insertActionList(caseNow.action), + case_waitList, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ caseNow._collapsed, + /*disabled*/ caseNow._disabled + ); + } else if (caseNow["case"] == "mouse") { + case_waitList = MotaActionFunctions.xmlText( + "waitContext_2", + [ + caseNow.px[0], + caseNow.px[1], + caseNow.py[0], + caseNow.py[1], + caseNow["break"] || false, + this.insertActionList(caseNow.action), + case_waitList, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ caseNow._collapsed, + /*disabled*/ caseNow._disabled + ); + } else if (caseNow["case"] == "condition") { + case_waitList = MotaActionFunctions.xmlText( + "waitContext_3", + [ + this.expandEvalBlock([caseNow.condition]), + caseNow["break"] || false, + this.insertActionList(caseNow.action), + case_waitList, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ caseNow._collapsed, + /*disabled*/ caseNow._disabled + ); + } else if (caseNow["case"] == "timeout") { + case_waitList = MotaActionFunctions.xmlText( + "waitContext_4", + [ + caseNow["break"] || false, + this.insertActionList(caseNow.action), + case_waitList, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ caseNow._collapsed, + /*disabled*/ caseNow._disabled + ); + } } } - } - this.next = MotaActionFunctions.xmlText('wait_s',[ - data.forceChild||false,data.timeout||0,case_waitList, this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "waitAsync": // 等待所有异步事件执行完毕 - this.next = MotaActionBlocks['waitAsync_s'].xmlText([ - data.excludeAnimates||false, data.includeSounds||false, this.next]); - break; - case "stopAsync": // 立刻停止所有异步事件 - this.next = MotaActionBlocks['stopAsync_s'].xmlText([ - this.next]); - break; - case "drawWarning": - - this.next = MotaActionBlocks['drawWarning_s'].xmlText([ - data.x,data.y,data.size,data?.text,data?.text2,data?.warning,this.next]); - break; - case "changeMouse": - - this.next = MotaActionBlocks['changeMouse_s'].xmlText([ - data.icon,data.div,data.translate[0],data.translate[1],data.scale[0],data.scale[0],data.degree,data.px,data.py,this.next]); - break; - case "removeMouse": - - this.next = MotaActionBlocks['removeMouse_s'].xmlText([data.div,this.next]); + this.next = MotaActionFunctions.xmlText( + "wait_s", + [ + data.forceChild || false, + data.timeout || 0, + case_waitList, + this.next, + ], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); break; - case "callBook": // 呼出怪物手册 - this.next = MotaActionBlocks['callBook_s'].xmlText([ - this.next]); - break; - case "callSave": // 呼出存档界面 - this.next = MotaActionBlocks['callSave_s'].xmlText([ - this.next]); - break; - case "autoSave": // 自动存档 - this.next = MotaActionBlocks['autoSave_s'].xmlText([ - data.removeLast||false, this.next]); - break; - case "forbidSave": // 禁止存档 - this.next = MotaActionBlocks['forbidSave_s'].xmlText([ - data.forbid||false, this.next]); - break; - case "callLoad": // 呼出读档界面 - this.next = MotaActionBlocks['callLoad_s'].xmlText([ - this.next]); - break; - case "exit": // 立刻结束事件 - this.next = MotaActionBlocks['exit_s'].xmlText([ - this.next]); - break; - case "previewUI": // UI绘制预览 - this.next = MotaActionFunctions.xmlText('previewUI_s',[ - this.insertActionList(data.action), this.next - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); - break; - case "clearMap": // 清除画布 - this.next = MotaActionBlocks['clearMap_s'].xmlText([ - data.x, data.y, data.width, data.height, this.next - ]); - break; - case "setAttribute": // 设置画布属性 - data.fillStyle=this.Colour(data.fillStyle); - data.strokeStyle=this.Colour(data.strokeStyle); - this.next = MotaActionBlocks['setAttribute_s'].xmlText([ - data.font,data.fillStyle,'rgba('+data.fillStyle+')',data.strokeStyle,'rgba('+data.strokeStyle+')', - data.lineWidth,data.alpha,data.align,data.baseline,data.z,this.next]); - break; - case "setFilter": - this.next = MotaActionBlocks['setFilter_s'].xmlText([ - data.blur, data.hue, data.grayscale, data.invert||false, data.shadow, this.next]); - break; - case "fillText": // 绘制一行文本 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['fillText_s'].xmlText([ - data.x, data.y, data.style, 'rgba('+data.style+')', data.font, data.maxWidth, this.EvalString(data.text), this.next - ]); - break; - case "fillBoldText": // 绘制一行描边文本 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['fillBoldText_s'].xmlText([ - data.x, data.y, data.style, 'rgba('+data.style+')', data.strokeStyle, 'rgba('+(data.strokeStyle||"0,0,0,1")+')', - data.font, this.EvalString(data.text), this.next - ]); - break; - case "drawTextContent": // 绘制多行文本 - data.color = this.Colour(data.color); - this.next = MotaActionBlocks['drawTextContent_s'].xmlText([ - this.EvalString_Multi(data.text), data.left, data.top, data.maxWidth, data.color, 'rgba('+data.color+')', - data.align, data.fontSize, data.lineHeight, data.bold, this.next - ]); - break; - case "fillRect": // 绘制矩形 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['fillRect_s'].xmlText([ - data.x, data.y, data.width, data.height, data.radius, data.angle, data.style, 'rgba('+data.style+')', this.next - ]); - break; - case "strokeRect": // 绘制矩形边框 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['strokeRect_s'].xmlText([ - data.x, data.y, data.width, data.height, data.radius, data.angle, data.style, 'rgba('+data.style+')', data.lineWidth, this.next - ]); - break; - case "drawLine": // 绘制线段 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['drawLine_s'].xmlText([ - data.x1, data.y1, data.x2, data.y2, data.style, 'rgba('+data.style+')', data.lineWidth, this.next - ]); - break; - case "drawArrow": // 绘制线段 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['drawArrow_s'].xmlText([ - data.x1, data.y1, data.x2, data.y2, data.style, 'rgba('+data.style+')', data.lineWidth, this.next - ]); - break; - case "fillPolygon": // 绘制多边形 - data.style = this.Colour(data.style); - var x_str=[],y_str=[]; - data.nodes.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['fillPolygon_s'].xmlText([ - x_str.join(','), y_str.join(','), data.style, 'rgba('+data.style+')', this.next - ]); - break; - case "strokePolygon": // 绘制多边形 - data.style = this.Colour(data.style); - var x_str=[],y_str=[]; - data.nodes.forEach(function (t) { - x_str.push(t[0]); - y_str.push(t[1]); - }) - this.next = MotaActionBlocks['strokePolygon_s'].xmlText([ - x_str.join(','), y_str.join(','), data.style, 'rgba('+data.style+')', data.lineWidth, this.next - ]); - break; - case "fillEllipse": // 绘制椭圆 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['fillEllipse_s'].xmlText([ - data.x, data.y, data.a, data.b, data.angle, data.style, 'rgba('+data.style+')', this.next - ]); - break; - case "strokeEllipse": // 绘制椭圆边框 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['strokeEllipse_s'].xmlText([ - data.x, data.y, data.a, data.b, data.angle, data.style, 'rgba('+data.style+')', data.lineWidth, this.next - ]); - break; - case "fillArc": // 绘制弧 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['fillArc_s'].xmlText([ - data.x, data.y, data.r, data.start, data.end, data.style, 'rgba('+data.style+')', this.next - ]); - break; - case "strokeArc": // 绘制弧 - data.style = this.Colour(data.style); - this.next = MotaActionBlocks['strokeArc_s'].xmlText([ - data.x, data.y, data.r, data.start, data.end, data.style, 'rgba('+data.style+')', data.lineWidth, this.next - ]); - break; - case "drawImage": // 绘制图片 - if (data.x1 != null && data.y1 != null && data.w1 != null && data.h1 != null) { - this.next = MotaActionBlocks['drawImage_1_s'].xmlText([ - data.image, data.reverse, data.x, data.y, data.w, data.h, data.x1, data.y1, data.w1, data.h1, data.angle, this.next + case "waitAsync": // 等待所有异步事件执行完毕 + this.next = MotaActionBlocks["waitAsync_s"].xmlText([ + data.excludeAnimates || false, + data.includeSounds || false, + this.next, ]); - } - else { - this.next = MotaActionBlocks['drawImage_s'].xmlText([ - data.image, data.reverse, data.x, data.y, data.w, data.h, data.angle, this.next + break; + case "stopAsync": // 立刻停止所有异步事件 + this.next = MotaActionBlocks["stopAsync_s"].xmlText([this.next]); + break; + case "drawWarning": + this.next = MotaActionBlocks["drawWarning_s"].xmlText([ + data.x, + data.y, + data.size, + data?.text, + data?.text2, + data?.warning, + this.next, ]); - } - break; - case "drawIcon": // 绘制图标 - this.next = MotaActionBlocks['drawIcon_s'].xmlText([ - data.id, data.frame||0, data.x, data.y, data.width, data.height, this.next - ]); - break; - case "drawBackground": // 绘制背景 - if (!/^\w+\.png$/.test(data.background)) - data.background=this.Colour(data.background); - this.next = MotaActionBlocks['drawBackground_s'].xmlText([ - data.background, 'rgba('+data.background+')', data.x, data.y, data.width, data.height, this.next - ]); - break; - case "drawSelector": // 绘制光标 - if (data.image) { - this.next = MotaActionBlocks['drawSelector_s'].xmlText([ - data.image, data.code, data.x, data.y, data.width, data.height, this.next + break; + case "changeMouse": + this.next = MotaActionBlocks["changeMouse_s"].xmlText([ + data.icon, + data.div, + data.translate[0], + data.translate[1], + data.scale[0], + data.scale[0], + data.degree, + data.px, + data.py, + this.next, ]); - } - else { - this.next = MotaActionBlocks['drawSelector_1_s'].xmlText([data.code, this.next]); - } - case "animateImage": // 兼容 animateImage - break; - default: - this.next = MotaActionBlocks['unknown_s'].xmlText([ - JSON.stringify(data),this.next]); - } - this.parseAction(); - return; -} + break; + case "removeMouse": + this.next = MotaActionBlocks["removeMouse_s"].xmlText([ + data.div, + this.next, + ]); + break; + case "callBook": // 呼出怪物手册 + this.next = MotaActionBlocks["callBook_s"].xmlText([this.next]); + break; + case "callSave": // 呼出存档界面 + this.next = MotaActionBlocks["callSave_s"].xmlText([this.next]); + break; + case "autoSave": // 自动存档 + this.next = MotaActionBlocks["autoSave_s"].xmlText([ + data.removeLast || false, + this.next, + ]); + break; + case "forbidSave": // 禁止存档 + this.next = MotaActionBlocks["forbidSave_s"].xmlText([ + data.forbid || false, + this.next, + ]); + break; + case "callLoad": // 呼出读档界面 + this.next = MotaActionBlocks["callLoad_s"].xmlText([this.next]); + break; + case "exit": // 立刻结束事件 + this.next = MotaActionBlocks["exit_s"].xmlText([this.next]); + break; + case "previewUI": // UI绘制预览 + this.next = MotaActionFunctions.xmlText( + "previewUI_s", + [this.insertActionList(data.action), this.next], + /* isShadow */ false, + /*comment*/ null, + /*collapsed*/ data._collapsed, + /*disabled*/ data._disabled + ); + break; + case "clearMap": // 清除画布 + this.next = MotaActionBlocks["clearMap_s"].xmlText([ + data.x, + data.y, + data.width, + data.height, + this.next, + ]); + break; + case "setAttribute": // 设置画布属性 + data.fillStyle = this.Colour(data.fillStyle); + data.strokeStyle = this.Colour(data.strokeStyle); + this.next = MotaActionBlocks["setAttribute_s"].xmlText([ + data.font, + data.fillStyle, + "rgba(" + data.fillStyle + ")", + data.strokeStyle, + "rgba(" + data.strokeStyle + ")", + data.lineWidth, + data.alpha, + data.align, + data.baseline, + data.z, + this.next, + ]); + break; + case "setFilter": + this.next = MotaActionBlocks["setFilter_s"].xmlText([ + data.blur, + data.hue, + data.grayscale, + data.invert || false, + data.shadow, + this.next, + ]); + break; + case "fillText": // 绘制一行文本 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["fillText_s"].xmlText([ + data.x, + data.y, + data.style, + "rgba(" + data.style + ")", + data.font, + data.maxWidth, + this.EvalString(data.text), + this.next, + ]); + break; + case "fillBoldText": // 绘制一行描边文本 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["fillBoldText_s"].xmlText([ + data.x, + data.y, + data.style, + "rgba(" + data.style + ")", + data.strokeStyle, + "rgba(" + (data.strokeStyle || "0,0,0,1") + ")", + data.font, + this.EvalString(data.text), + this.next, + ]); + break; + case "drawTextContent": // 绘制多行文本 + data.color = this.Colour(data.color); + this.next = MotaActionBlocks["drawTextContent_s"].xmlText([ + this.EvalString_Multi(data.text), + data.left, + data.top, + data.maxWidth, + data.color, + "rgba(" + data.color + ")", + data.align, + data.fontSize, + data.lineHeight, + data.bold, + this.next, + ]); + break; + case "fillRect": // 绘制矩形 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["fillRect_s"].xmlText([ + data.x, + data.y, + data.width, + data.height, + data.radius, + data.angle, + data.style, + "rgba(" + data.style + ")", + this.next, + ]); + break; + case "strokeRect": // 绘制矩形边框 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["strokeRect_s"].xmlText([ + data.x, + data.y, + data.width, + data.height, + data.radius, + data.angle, + data.style, + "rgba(" + data.style + ")", + data.lineWidth, + this.next, + ]); + break; + case "drawLine": // 绘制线段 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["drawLine_s"].xmlText([ + data.x1, + data.y1, + data.x2, + data.y2, + data.style, + "rgba(" + data.style + ")", + data.lineWidth, + this.next, + ]); + break; + case "drawArrow": // 绘制线段 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["drawArrow_s"].xmlText([ + data.x1, + data.y1, + data.x2, + data.y2, + data.style, + "rgba(" + data.style + ")", + data.lineWidth, + this.next, + ]); + break; + case "fillPolygon": // 绘制多边形 + data.style = this.Colour(data.style); + var x_str = [], + y_str = []; + data.nodes.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["fillPolygon_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.style, + "rgba(" + data.style + ")", + this.next, + ]); + break; + case "strokePolygon": // 绘制多边形 + data.style = this.Colour(data.style); + var x_str = [], + y_str = []; + data.nodes.forEach(function (t) { + x_str.push(t[0]); + y_str.push(t[1]); + }); + this.next = MotaActionBlocks["strokePolygon_s"].xmlText([ + x_str.join(","), + y_str.join(","), + data.style, + "rgba(" + data.style + ")", + data.lineWidth, + this.next, + ]); + break; + case "fillEllipse": // 绘制椭圆 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["fillEllipse_s"].xmlText([ + data.x, + data.y, + data.a, + data.b, + data.angle, + data.style, + "rgba(" + data.style + ")", + this.next, + ]); + break; + case "strokeEllipse": // 绘制椭圆边框 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["strokeEllipse_s"].xmlText([ + data.x, + data.y, + data.a, + data.b, + data.angle, + data.style, + "rgba(" + data.style + ")", + data.lineWidth, + this.next, + ]); + break; + case "fillArc": // 绘制弧 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["fillArc_s"].xmlText([ + data.x, + data.y, + data.r, + data.start, + data.end, + data.style, + "rgba(" + data.style + ")", + this.next, + ]); + break; + case "strokeArc": // 绘制弧 + data.style = this.Colour(data.style); + this.next = MotaActionBlocks["strokeArc_s"].xmlText([ + data.x, + data.y, + data.r, + data.start, + data.end, + data.style, + "rgba(" + data.style + ")", + data.lineWidth, + this.next, + ]); + break; + case "drawImage": // 绘制图片 + if ( + data.x1 != null && + data.y1 != null && + data.w1 != null && + data.h1 != null + ) { + this.next = MotaActionBlocks["drawImage_1_s"].xmlText([ + data.image, + data.reverse, + data.x, + data.y, + data.w, + data.h, + data.x1, + data.y1, + data.w1, + data.h1, + data.angle, + this.next, + ]); + } else { + this.next = MotaActionBlocks["drawImage_s"].xmlText([ + data.image, + data.reverse, + data.x, + data.y, + data.w, + data.h, + data.angle, + this.next, + ]); + } + break; + case "drawIcon": // 绘制图标 + this.next = MotaActionBlocks["drawIcon_s"].xmlText([ + data.id, + data.frame || 0, + data.x, + data.y, + data.width, + data.height, + this.next, + ]); + break; + case "drawBackground": // 绘制背景 + if (!/^\w+\.png$/.test(data.background)) + data.background = this.Colour(data.background); + this.next = MotaActionBlocks["drawBackground_s"].xmlText([ + data.background, + "rgba(" + data.background + ")", + data.x, + data.y, + data.width, + data.height, + this.next, + ]); + break; + case "drawSelector": // 绘制光标 + if (data.image) { + this.next = MotaActionBlocks["drawSelector_s"].xmlText([ + data.image, + data.code, + data.x, + data.y, + data.width, + data.height, + this.next, + ]); + } else { + this.next = MotaActionBlocks["drawSelector_1_s"].xmlText([ + data.code, + this.next, + ]); + } + case "animateImage": // 兼容 animateImage + break; + default: + this.next = MotaActionBlocks["unknown_s"].xmlText([ + JSON.stringify(data), + this.next, + ]); + } + this.parseAction(); + return; + }; -////// 往当前事件列表之后添加一个事件组 ////// -ActionParser.prototype.insertActionList = function (actionList) { - if (actionList.length===0) return null; - this.event.data.list.push({"type": "_next", "next": this.next}); - this.event.data.list=this.event.data.list.concat(actionList); - this.next = null; - this.parseAction(); - return this.result; -} + ////// 往当前事件列表之后添加一个事件组 ////// + ActionParser.prototype.insertActionList = function (actionList) { + if (actionList.length === 0) return null; + this.event.data.list.push({ type: "_next", next: this.next }); + this.event.data.list = this.event.data.list.concat(actionList); + this.next = null; + this.parseAction(); + return this.result; + }; -////// 判断某对象是否不为undefined也不会null ////// -ActionParser.prototype.isset = function (val) { + ////// 判断某对象是否不为undefined也不会null ////// + ActionParser.prototype.isset = function (val) { if (val === undefined || val === null) { - return false; - } - return true -} - -ActionParser.prototype.StepString = function(steplist) { - var stepchar = { - 'up': '上', - 'down': '下', - 'left': '左', - 'right': '右', - 'forward': '前', - 'backward': '后' - } - var StepString = ''; - var last = null, number = 0; - steplist.forEach(function (v) { - if (v != last) { - if (last != null) { - StepString += stepchar[last]; - if (number > 1) StepString += number; - } - last = v; - number = 1; - } else { - number++; - } - }); - if (last != null) { - StepString += stepchar[last]; - if (number > 1) StepString += number; - } - return StepString; -} - -ActionParser.prototype.EvalString = function(EvalString) { - return EvalString.split('\b').join('\\b').split('\t').join('\\t').split('\n').join('\\n'); -} - -ActionParser.prototype.EvalString_Multi = function(EvalString) { - return EvalString.split('\b').join('\\b').split('\t').join('\\t'); -} - -ActionParser.prototype.getTitleAndPosition = function (string) { - string = this.EvalString_Multi(string); - var title = '', icon = '', position = ''; - string = string.replace(/\\t\[(([^\],]+),)?([^\],]+)\]/g, function (s0, s1, s2, s3) { - if (s3) title = s3; - if (s2) { icon = s3; title = s2; } - if (icon && !/^(.*)\.(jpg|jpeg|png)$/.test(icon) - && !/^[0-9a-zA-Z_][0-9a-zA-Z_:]*$/.test(icon)) { title += "," + icon; icon = ''; } - return ""; - }).replace(/\\b\[(.*?)\]/g, function (s0, s1) { - position = s1; return ""; - }); - return [title, icon, position, string]; -} - -ActionParser.prototype.Colour = function(color) { - return color?JSON.stringify(color).slice(1,-1):null; -} - -ActionParser.prototype.matchId = function(args) { - var rt=function(xml,args){ - // 此处刻意不写成 xml:MotaActionBlocks[str].xmlText 来方便搜索 - return {ret:true,xml:xml,args:args} - } - var match = /nothing/.exec('nothing') - // 固定列表 - var FixedId_List=MotaActionBlocks['FixedId_List'].options; // [["生命", "status:hp"], ...] - match=new RegExp('^('+FixedId_List.map(function(v){return v[1]}).join('|')+')$').exec(args[0]) - if(match){ - return rt(MotaActionBlocks['idFixedList_e'].xmlText, args); - } - // 独立开关 - match=/^switch:([A-Z])$/.exec(args[0]) - if(match){ - args[0]=match[1] - return rt(MotaActionBlocks['idFlag_e'].xmlText, args); - } - // 临时变量 - match=/^temp:([A-Z])$/.exec(args[0]) - if(match){ - args[0]=match[1] - return rt(MotaActionBlocks['idTemp_e'].xmlText, args); - } - // id列表 - var Id_List = MotaActionBlocks['Id_List'].options; // [["变量", "flag"], ...] - match=new RegExp('^('+Id_List.map(function(v){return v[1]}).join('|')+'):([a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]+)$').exec(args[0]) - if(match){ - if (match[1] == 'status' || match[1] == 'item' || match[1] == 'buff') { - match[2] = MotaActionFunctions.replaceToName_token(match[2]); - } - args=[match[1],match[2]] - return rt(MotaActionBlocks['idIdList_e'].xmlText, args); - } - return {ret:false} -} - -ActionParser.prototype.matchEvalAtom = function(args) { - var rt=function(xml,args){ - // 此处刻意不写成 xml:MotaActionBlocks[str].xmlText 来方便搜索 - return {ret:true,xml:xml,args:args} - } - var match = /nothing/.exec('nothing') - // 勾选框 - match = /^(true|false)$/.exec(args[0]) - if(match){ - args[0]='true'==args[0]; - return rt(MotaActionBlocks['bool_e'].xmlText, args); - } - // 怪物属性 - var EnemyId_List=MotaActionBlocks['EnemyId_List'].options; // [["生命", "hp"], ...] - match=new RegExp("^enemy:([a-zA-Z0-9_]+):(" + EnemyId_List.map(function(v){return v[1]}).join('|') + ")$").exec(args[0]) - if(match){ - args=[MotaActionFunctions.replaceToName_token(match[1]),match[2]] - return rt(MotaActionBlocks['enemyattr_e'].xmlText, args); - } - // 图块ID - match=/^blockId:(-?\d+),(-?\d+)$/.exec(args[0]) - if(match){ - args=[match[1],match[2]] - return rt(MotaActionBlocks['blockId_e'].xmlText, args); - } - // 图块数字 - match=/^blockNumber:(-?\d+),(-?\d+)$/.exec(args[0]) - if(match){ - args=[match[1],match[2]] - return rt(MotaActionBlocks['blockNumber_e'].xmlText, args); - } - // 图块类别 - match=/^blockCls:(-?\d+),(-?\d+)$/.exec(args[0]) - if(match){ - args=[match[1],match[2]] - return rt(MotaActionBlocks['blockCls_e'].xmlText, args); - } - // 装备孔 - match=/^equip:(-?\d+)$/.exec(args[0]) - if(match){ - args[0]=match[1] - return rt(MotaActionBlocks['equip_e'].xmlText, args); - } - match=/^core\.isReplaying\(\)$/.exec(args[0]); - if (match) { - return rt(MotaActionBlocks['isReplaying_e'].xmlText, args); - } - match=/^core\.(nextX|nextY)\((-?\d*)\)$/.exec(args[0]); - if (match) { - if (match[2] == "") match[2] = "1"; - args=[match[2], match[1]]; - return rt(MotaActionBlocks['nextXY_e'].xmlText, args); - } - match=/^core\.hasVisitedFloor\(['"](.*?)['"']\)$/.exec(args[0]); - if (match) { - args[0]=match[1]; - return rt(MotaActionBlocks['hasVisitedFloor_e'].xmlText, args); - } - match=/^core\.isShopVisited\(['"](.*?)['"']\)$/.exec(args[0]); - if (match) { - args[0]=match[1]; - return rt(MotaActionBlocks['isShopVisited_e'].xmlText, args); - } - match=/^core\.hasEquip\(['"](.*?)['"']\)$/.exec(args[0]); - if (match) { - args[0]=match[1]; - return rt(MotaActionBlocks['hasEquip_e'].xmlText, args); - } - match=/^core\.canBattle\(['"](.*?)['"']\)$/.exec(args[0]); - if (match) { - args[0]=match[1]; - return rt(MotaActionBlocks['canBattle_e'].xmlText, args); - } - match=/^core\.rand\((\d+)\)$/.exec(args[0]); - if (match) { - args[0]=match[1]; - return rt(MotaActionBlocks['rand_e'].xmlText, args); - } - return {ret:false} -} - -ActionParser.prototype.matchEvalCompare=function(args, isShadow){ - if (MotaActionFunctions.disableExpandCompare) return {ret:false}; - var raw=args[0].replace(/>/g,'>').replace(/</g,'<').replace(/"/g,'"').replace(/ /g,' ').replace(/&/g,'&') - if (raw[0]+raw.slice(-1)=='()') raw=raw.slice(1,-1); - var str=raw - var xml=MotaActionBlocks['expression_arithmetic_0'].xmlText - if (!/<=|<|>=|>|==|!=|===|!==|&&|\|\|/.exec(str)) return {ret:false}; - str=str.replace(/[^<>=!()&|]/g,' ') - // 处理括号匹配 - var old; - do { - old=str; - str=str.replace(/\([^()]*\)/g,function(v){return Array.from({length:v.length+1}).join(' ')}) - } while (old!=str); - // 按优先级依次寻找以下符号 - var oplist=['<','<=','>','>=','==','!=','===','!==','&&','||'].reverse() - for (var index = 0,op; op=oplist[index]; index++) { - var match=new RegExp(' '+(op=='||'?'\\|\\|':op)+' ').exec(str) - if (!match) continue; - args=[this.expandEvalBlock([raw.slice(0,match.index+1)],isShadow),op.replace(/&/g,'&').replace(//g,'>'),this.expandEvalBlock([raw.slice(match.index+1+op.length)],isShadow)] - return {ret:true,xml:xml,args:args} - } - return {ret:false} -} - -ActionParser.prototype.expandIdBlock = function(args, isShadow, comment) { - args[0]=MotaActionFunctions.replaceFromName(args[0]) - var xml=MotaActionBlocks['idString_e'].xmlText - var ret=this.matchId(args) - if (ret.ret){ - xml=ret.xml; - args=ret.args; - } else { - for (var index = 0; index < args.length; index++) { - args[index]=MotaActionFunctions.replaceToName(args[index]) - } - } - return xml(args, isShadow, comment); -} - -ActionParser.prototype.expandEvalBlock = function(args, isShadow, comment) { - args[0]=MotaActionFunctions.replaceFromName(args[0]) - var xml=MotaActionBlocks['evalString_e'].xmlText - if (args[0].indexOf('\n') >= 0 || args[0].indexOf('\\n') >= 0) return xml(args, isShadow, comment); - var ret=this.matchId(args) - if (ret.ret){ - xml=ret.xml; - args=ret.args; - } else if( (ret=this.matchEvalAtom(args)).ret ){ - xml=ret.xml; - args=ret.args; - } else if(/^(!.*|\(!.*\))$/.exec(args[0])){ - // 非 - xml=MotaActionBlocks['negate_e'].xmlText - var content=args[0][0]=='!'?args[0].slice(1):args[0].slice(2,-1) - args[0]=this.expandEvalBlock([content],isShadow) - } else if( (ret=this.matchEvalCompare(args, isShadow)).ret ){ - // 大小比较 - xml=ret.xml; - args=ret.args; - } else { - for (var index = 0; index < args.length; index++) { - args[index]=MotaActionFunctions.replaceToName(args[index]) - } - } - return xml(args, isShadow, comment); -} - -MotaActionFunctions.actionParser = new ActionParser(); - -MotaActionFunctions.workspace = function(){return workspace} - -MotaActionFunctions.parse = function(obj,type) { - try { - obj = obj.map(function (e) { - if (e.type == "function") return e; - else return JSON.parse(MotaActionFunctions.replaceToName(JSON.stringify(e))); - }); - } catch (e) { } - MotaActionFunctions.workspace().clear(); - xml_text = MotaActionFunctions.actionParser.parse(obj, type || 'event'); - xml = Blockly.Xml.textToDom('' + xml_text + ''); - Blockly.Xml.domToWorkspace(xml, MotaActionFunctions.workspace()); -} - -MotaActionFunctions.EvalString_pre = function(EvalString){ - if (EvalString.indexOf('__door__')!==-1) throw new Error('请修改开门变量__door__,如door1,door2,door3等依次向后。请勿存在两个门使用相同的开门变量。'); - EvalString = MotaActionFunctions.replaceFromName(EvalString); - return EvalString.replace(/([^\\])"/g,'$1\\"').replace(/^"/g,'\\"').replace(/""/g,'"\\"'); -} - -MotaActionFunctions.EvalString_Multi_pre = function(EvalString){ - if (EvalString.indexOf('__door__')!==-1) throw new Error('请修改开门变量__door__,如door1,door2,door3等依次向后。请勿存在两个门使用相同的开门变量。'); - EvalString = MotaActionFunctions.replaceFromName(EvalString); - return EvalString.replace(/([^\\])"/g,'$1\\"').replace(/^"/g,'\\"').replace(/""/g,'"\\"').replace(/\n/g, '\\n'); -} - -MotaActionFunctions.JsonEvalString_pre = function (JsonEvalString) { - if (JsonEvalString == '') return ''; - JsonEvalString = MotaActionFunctions.replaceFromName(JsonEvalString); - try { - return JSON.stringify(JSON.parse(JsonEvalString)); - } catch (e) { - throw new Error('此处需要填写一个合法的JSON内容'); - } -} - -MotaActionFunctions.IntString_pre = function (IntString) { - if (!/^[+-]?\d*$/.test(IntString)) throw new Error('此项必须是整数或不填'); - return IntString; -} - -MotaActionFunctions.IdString_pre = function(IdString){ - if (IdString.indexOf('__door__')!==-1) throw new Error('请修改开门变量__door__,如door1,door2,door3等依次向后。请勿存在两个门使用相同的开门变量。'); - IdString = MotaActionFunctions.replaceFromName(IdString); - IdString = MotaActionFunctions.replaceFromName_token(IdString); - if (IdString && !(MotaActionFunctions.pattern.id.test(IdString)) && !(MotaActionFunctions.pattern.idWithoutFlag.test(IdString))) - throw new Error('id: '+IdString+'中包含了0-9 a-z A-Z _ - :之外的字符'); - return IdString; -} - -MotaActionFunctions.PosString_pre = function(PosString){ - if (!PosString || /^-?\d+$/.test(PosString)) return PosString; - //if (!(MotaActionFunctions.pattern.id.test(PosString)))throw new Error(PosString+'中包含了0-9 a-z A-Z _ 和中文之外的字符,或者是没有以flag: 开头'); - var comma = PosString.indexOf(','); - if (comma >= 0 && PosString.substring(0, comma).indexOf('(') < 0) throw '此处不可写多点坐标'; - return '"'+MotaActionFunctions.replaceFromName(PosString)+'"'; -} - -MotaActionFunctions.processMoveDirections = function (steps) { - var curr = null, num = null; - var result = []; - steps.forEach(function (one) { - var v = one.split(':'); - if (v.length == 1) v.push("1"); - if (v[0] != curr) { - if (curr != null) result.push(curr+":"+num); - curr = v[0]; - num = parseInt(v[1]); - } else { - num += parseInt(v[1]); - } - }); - if (curr != null) result.push(curr+":"+num); - return result; -} - -MotaActionFunctions.processcgDrawing = function (bodyList) { - var list=[] - bodyList.forEach(function (one) { - list.push([one.name,one.px,one.filter])}) - return list; -} - -MotaActionFunctions.processMultiLoc = function (EvalString_0, EvalString_1) { - var floorstr = ''; - if (EvalString_0 && EvalString_1) { - var x = EvalString_0, y = EvalString_1; - var pattern = /^([+-]?\d+)(, ?[+-]?\d+)*$/; - if (pattern.test(x) && pattern.test(y) && x.split(',').length == y.split(',').length) { - x=x.split(','); - y=y.split(','); - for(var ii=0;ii 1) StepString += number; + } + last = v; + number = 1; + } else { + number++; + } + }); + if (last != null) { + StepString += stepchar[last]; + if (number > 1) StepString += number; } - if (num.length==0) num="1"; - return isset(noparse)?num:parseInt(num); - } + return StepString; + }; - while (index") + .replace(/</g, "<") + .replace(/"/g, '"') + .replace(/ /g, " ") + .replace(/&/g, "&"); + if (raw[0] + raw.slice(-1) == "()") raw = raw.slice(1, -1); + var str = raw; + var xml = MotaActionBlocks["expression_arithmetic_0"].xmlText; + if (!/<=|<|>=|>|==|!=|===|!==|&&|\|\|/.exec(str)) return { ret: false }; + str = str.replace(/[^<>=!()&|]/g, " "); + // 处理括号匹配 + var old; + do { + old = str; + str = str.replace(/\([^()]*\)/g, function (v) { + return Array.from({ length: v.length + 1 }).join(" "); + }); + } while (old != str); + // 按优先级依次寻找以下符号 + var oplist = [ + "<", + "<=", + ">", + ">=", + "==", + "!=", + "===", + "!==", + "&&", + "||", + ].reverse(); + for (var index = 0, op; (op = oplist[index]); index++) { + var match = new RegExp(" " + (op == "||" ? "\\|\\|" : op) + " ").exec( + str + ); + if (!match) continue; + args = [ + this.expandEvalBlock([raw.slice(0, match.index + 1)], isShadow), + op.replace(/&/g, "&").replace(//g, ">"), + this.expandEvalBlock( + [raw.slice(match.index + 1 + op.length)], + isShadow + ), + ]; + return { ret: true, xml: xml, args: args }; + } + return { ret: false }; + }; + ActionParser.prototype.expandIdBlock = function (args, isShadow, comment) { + args[0] = MotaActionFunctions.replaceFromName(args[0]); + var xml = MotaActionBlocks["idString_e"].xmlText; + var ret = this.matchId(args); + if (ret.ret) { + xml = ret.xml; + args = ret.args; + } else { + for (var index = 0; index < args.length; index++) { + args[index] = MotaActionFunctions.replaceToName(args[index]); + } + } + return xml(args, isShadow, comment); + }; - MotaActionFunctions.pattern.replaceEnemyValueList.forEach(function (v) { - map[v[0]] = v[1]; list.push(v[0]); - }); - str = str.replace(new RegExp("enemy:([a-zA-Z0-9_]+)[.:](" + list.join("|") + ")\\b", "g"), function (a, b, c) { - return map[c] ? ("enemy:" + b + ":" + map[c]) : c; - }).replace(/(enemy:[a-zA-Z0-9_]+)[.::]/g, '$1:'); + ActionParser.prototype.expandEvalBlock = function (args, isShadow, comment) { + args[0] = MotaActionFunctions.replaceFromName(args[0]); + var xml = MotaActionBlocks["evalString_e"].xmlText; + if (args[0].indexOf("\n") >= 0 || args[0].indexOf("\\n") >= 0) + return xml(args, isShadow, comment); + var ret = this.matchId(args); + if (ret.ret) { + xml = ret.xml; + args = ret.args; + } else if ((ret = this.matchEvalAtom(args)).ret) { + xml = ret.xml; + args = ret.args; + } else if (/^(!.*|\(!.*\))$/.exec(args[0])) { + // 非 + xml = MotaActionBlocks["negate_e"].xmlText; + var content = args[0][0] == "!" ? args[0].slice(1) : args[0].slice(2, -1); + args[0] = this.expandEvalBlock([content], isShadow); + } else if ((ret = this.matchEvalCompare(args, isShadow)).ret) { + // 大小比较 + xml = ret.xml; + args = ret.args; + } else { + for (var index = 0; index < args.length; index++) { + args[index] = MotaActionFunctions.replaceToName(args[index]); + } + } + return xml(args, isShadow, comment); + }; - map = {}; list = []; - MotaActionFunctions.pattern.replaceEnemyList.forEach(function (v) { - map[v[0]] = v[1]; list.push(v[0]); - }); - str = str.replace(new RegExp("enemy:(" + list.join("|") + ")\\b", "g"), function (a, b) { - return map[b] ? ("怪物:" + map[b]) : b; - }).replace(/enemy:/g, "怪物:"); + MotaActionFunctions.actionParser = new ActionParser(); - str = str.replace(/blockId:/g, "图块ID:").replace(/blockNumber:/g, "图块数字:").replace(/blockCls:/g, "图块类别:").replace(/equip:/g, "装备孔:"); - return str; -} + MotaActionFunctions.workspace = function () { + return workspace; + }; -MotaActionFunctions.replaceFromName = function (str) { - if (!str || MotaActionFunctions.disableReplace) return str; - var map = {}, list = []; - MotaActionFunctions.pattern.replaceStatusList.forEach(function (v) { - map[v[1]] = v[0]; list.push(v[1]); - }); - str = str.replace(new RegExp("状态[::](" + list.join("|") + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", "g"), function (a, b) { - return map[b] ? ("status:" + map[b]) : b; - }).replace(/状态[::]/g, "status:"); - str = str.replace(new RegExp("增益[::](" + list.join("|") + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", "g"), function (a, b) { - return map[b] ? ("buff:" + map[b]) : b; - }).replace(/增益[::]/g, "buff:"); - map = {}; list = []; - MotaActionFunctions.pattern.replaceItemList.forEach(function (v) { - map[v[1]] = v[0]; list.push(v[1]); - }); - str = str.replace(new RegExp("物品[::](" + list.join("|") + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", "g"), function (a, b) { - return map[b] ? ("item:" + map[b]) : b; - }).replace(/物品[::]/g, "item:"); - str = str.replace(/变量[::]/g, "flag:").replace(/独立开关[::]/g, "switch:").replace(/全局存储[::]/g, "global:"); + MotaActionFunctions.parse = function (obj, type) { + try { + obj = obj.map(function (e) { + if (e.type == "function") return e; + else + return JSON.parse( + MotaActionFunctions.replaceToName(JSON.stringify(e)) + ); + }); + } catch (e) {} + MotaActionFunctions.workspace().clear(); + xml_text = MotaActionFunctions.actionParser.parse(obj, type || "event"); + xml = Blockly.Xml.textToDom("" + xml_text + ""); + Blockly.Xml.domToWorkspace(xml, MotaActionFunctions.workspace()); + }; - map = {}; list = []; - MotaActionFunctions.pattern.replaceEnemyList.forEach(function (v) { - map[v[1]] = v[0]; list.push(v[1]); - }); - str = str.replace(new RegExp("(enemy:|怪物[::])(" + list.join("|") + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", "g"), function (a, b, c, d) { - return map[c] ? ("enemy:" + map[c]) : c; - }).replace(/怪物[::]/g, "enemy:"); + MotaActionFunctions.EvalString_pre = function (EvalString) { + if (EvalString.indexOf("__door__") !== -1) + throw new Error( + "请修改开门变量__door__,如door1,door2,door3等依次向后。请勿存在两个门使用相同的开门变量。" + ); + EvalString = MotaActionFunctions.replaceFromName(EvalString); + return EvalString.replace(/([^\\])"/g, '$1\\"') + .replace(/^"/g, '\\"') + .replace(/""/g, '"\\"'); + }; - map = {}; list = []; - MotaActionFunctions.pattern.replaceEnemyValueList.forEach(function (v) { - map[v[1]] = v[0]; list.push(v[1]); - }); - str = str.replace(new RegExp("enemy:([a-zA-Z0-9_]+)[::](" + list.join("|") + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", "g"), function (a, b, c, d) { - return map[c] ? ("enemy:" + b + ":" + map[c]) : c; - }).replace(/(enemy:[a-zA-Z0-9_]+)[::]/g, '$1:'); + MotaActionFunctions.EvalString_Multi_pre = function (EvalString) { + if (EvalString.indexOf("__door__") !== -1) + throw new Error( + "请修改开门变量__door__,如door1,door2,door3等依次向后。请勿存在两个门使用相同的开门变量。" + ); + EvalString = MotaActionFunctions.replaceFromName(EvalString); + return EvalString.replace(/([^\\])"/g, '$1\\"') + .replace(/^"/g, '\\"') + .replace(/""/g, '"\\"') + .replace(/\n/g, "\\n"); + }; - str = str.replace(/图块I[dD][::]/g, "blockId:").replace(/图块数字[::]/g, "blockNumber:").replace(/图块类别[::]/g, "blockCls:").replace(/装备孔[::]/g, "equip:"); + MotaActionFunctions.JsonEvalString_pre = function (JsonEvalString) { + if (JsonEvalString == "") return ""; + JsonEvalString = MotaActionFunctions.replaceFromName(JsonEvalString); + try { + return JSON.stringify(JSON.parse(JsonEvalString)); + } catch (e) { + throw new Error("此处需要填写一个合法的JSON内容"); + } + }; - return str; -} + MotaActionFunctions.IntString_pre = function (IntString) { + if (!/^[+-]?\d*$/.test(IntString)) throw new Error("此项必须是整数或不填"); + return IntString; + }; -} + MotaActionFunctions.IdString_pre = function (IdString) { + if (IdString.indexOf("__door__") !== -1) + throw new Error( + "请修改开门变量__door__,如door1,door2,door3等依次向后。请勿存在两个门使用相同的开门变量。" + ); + IdString = MotaActionFunctions.replaceFromName(IdString); + IdString = MotaActionFunctions.replaceFromName_token(IdString); + if ( + IdString && + !MotaActionFunctions.pattern.id.test(IdString) && + !MotaActionFunctions.pattern.idWithoutFlag.test(IdString) + ) + throw new Error( + "id: " + IdString + "中包含了0-9 a-z A-Z _ - :之外的字符" + ); + return IdString; + }; + + MotaActionFunctions.PosString_pre = function (PosString) { + if (!PosString || /^-?\d+$/.test(PosString)) return PosString; + //if (!(MotaActionFunctions.pattern.id.test(PosString)))throw new Error(PosString+'中包含了0-9 a-z A-Z _ 和中文之外的字符,或者是没有以flag: 开头'); + var comma = PosString.indexOf(","); + if (comma >= 0 && PosString.substring(0, comma).indexOf("(") < 0) + throw "此处不可写多点坐标"; + return '"' + MotaActionFunctions.replaceFromName(PosString) + '"'; + }; + + MotaActionFunctions.processMoveDirections = function (steps) { + var curr = null, + num = null; + var result = []; + steps.forEach(function (one) { + var v = one.split(":"); + if (v.length == 1) v.push("1"); + if (v[0] != curr) { + if (curr != null) result.push(curr + ":" + num); + curr = v[0]; + num = parseInt(v[1]); + } else { + num += parseInt(v[1]); + } + }); + if (curr != null) result.push(curr + ":" + num); + return result; + }; + + MotaActionFunctions.processcgDrawing = function (bodyList) { + var list = []; + bodyList.forEach(function (one) { + list.push([one.name, one.px, one.filter]); + }); + return list; + }; + + MotaActionFunctions.processMultiLoc = function (EvalString_0, EvalString_1) { + var floorstr = ""; + if (EvalString_0 && EvalString_1) { + var x = EvalString_0, + y = EvalString_1; + var pattern = /^([+-]?\d+)(, ?[+-]?\d+)*$/; + if ( + pattern.test(x) && + pattern.test(y) && + x.split(",").length == y.split(",").length + ) { + x = x.split(","); + y = y.split(","); + for (var ii = 0; ii < x.length; ii++) + x[ii] = "[" + x[ii].trim() + "," + y[ii].trim() + "]"; + floorstr = ', "loc": [' + x.join(",") + "]"; + } + if (floorstr == "") { + floorstr = ', "loc": ["' + x + '","' + y + '"]'; + } + } + return floorstr; + }; + + MotaActionFunctions.StepString_pre = function (StepString) { + //StepString='上右3下2左上左2' + var route = StepString.replace(/上/g, "U") + .replace(/下/g, "D") + .replace(/左/g, "L") + .replace(/右/g, "R") + .replace(/前/g, "F") + .replace(/后/g, "B"); + + //copyed from core.js + var ans = [], + index = 0; + + var isset = function (a) { + if (a == undefined || a == null) { + return false; + } + return true; + }; + var getNumber = function (noparse) { + var num = ""; + while (index < route.length && !isNaN(route.charAt(index))) { + num += route.charAt(index++); + } + if (num.length == 0) num = "1"; + return isset(noparse) ? num : parseInt(num); + }; + + while (index < route.length) { + var c = route.charAt(index++); + var number = getNumber(); + + switch (c) { + case "U": + for (var i = 0; i < number; i++) ans.push("up"); + break; + case "D": + for (var i = 0; i < number; i++) ans.push("down"); + break; + case "L": + for (var i = 0; i < number; i++) ans.push("left"); + break; + case "R": + for (var i = 0; i < number; i++) ans.push("right"); + break; + case "F": + for (var i = 0; i < number; i++) ans.push("forward"); + break; + case "B": + for (var i = 0; i < number; i++) ans.push("backward"); + break; + } + } + return ans; + }; + + MotaActionFunctions.ColorString_pre = function (ColorString) { + if (ColorString && !MotaActionFunctions.pattern.colorRe.test(ColorString)) + throw new Error("颜色格式错误,形如:0~255,0~255,0~255,0~1"); + return ColorString; + }; + + MotaActionFunctions.FontString_pre = function (FontString) { + if (FontString && !MotaActionFunctions.pattern.fontRe.test(FontString)) + throw new Error("字体必须是 [italic] [bold] 14px Verdana 这种形式或不填"); + return FontString; + }; + + MotaActionFunctions.pattern = MotaActionFunctions.pattern || {}; + MotaActionFunctions.pattern.id = + /^(flag|global|temp):([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)$/; + MotaActionFunctions.pattern.idWithoutFlag = /^[0-9a-zA-Z_][0-9a-zA-Z_\-:]*$/; + MotaActionFunctions.pattern.colorRe = /^[0-9 ]+,[0-9 ]+,[0-9 ]+(,[0-9. ]+)?$/; + MotaActionFunctions.pattern.fontRe = + /^(italic )?(bold )?(\d+)px ([a-zA-Z0-9_\u4E00-\u9FCC]+)$/; + + MotaActionFunctions.pattern.replaceStatusList = [ + // 保证顺序! + ["hpmax", "生命上限"], + ["hp", "生命"], + ["name", "名称"], + ["lv", "等级"], + ["atk", "攻击"], + ["def", "防御"], + ["mdef", "护盾"], + ["manamax", "魔力上限"], + ["mana", "魔力"], + ["money", "金币"], + ["exp", "经验"], + ["steps", "步数"], + ]; + + (function () { + // 读道具列表 + MotaActionFunctions.pattern.replaceItemList = []; + for (var id in core.material.items) { + var name = core.material.items[id].name; + if ( + id && + name && + name != "新物品" && + /^[a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+$/.test( + name + ) + ) { + MotaActionFunctions.pattern.replaceItemList.push([id, name]); + } + } + + MotaActionFunctions.pattern.replaceEnemyList = []; + for (var id in core.material.enemys) { + var name = core.material.enemys[id].name; + if ( + id && + name && + name != "新敌人" && + /^[a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+$/.test( + name + ) + ) { + MotaActionFunctions.pattern.replaceEnemyList.push([id, name]); + } + } + })(); + + MotaActionFunctions.pattern.replaceEnemyValueList = [ + // 保证顺序! + ["hp", "生命"], + ["name", "名称"], + ["atk", "攻击"], + ["def", "防御"], + ["money", "金币"], + ["exp", "经验"], + ["point", "加点"], + ["special", "属性"], + ]; + + MotaActionFunctions.disableReplace = false; + MotaActionFunctions.disableExpandCompare = false; + + MotaActionFunctions.replaceToName_token = function (str) { + if (!str || MotaActionFunctions.disableReplace) return str; + var list = []; + list = list.concat(MotaActionFunctions.pattern.replaceStatusList); + list = list.concat(MotaActionFunctions.pattern.replaceItemList); + list = list.concat(MotaActionFunctions.pattern.replaceEnemyList); + list = list.concat(MotaActionFunctions.pattern.replaceEnemyValueList); + for (var index = 0, pair; (pair = list[index]); index++) { + if (pair[0] == str) { + return pair[1]; + } + } + return str; + }; + + MotaActionFunctions.replaceFromName_token = function (str) { + if (!str || MotaActionFunctions.disableReplace) return str; + var list = []; + list = list.concat(MotaActionFunctions.pattern.replaceStatusList); + list = list.concat(MotaActionFunctions.pattern.replaceItemList); + list = list.concat(MotaActionFunctions.pattern.replaceEnemyList); + list = list.concat(MotaActionFunctions.pattern.replaceEnemyValueList); + for (var index = 0, pair; (pair = list[index]); index++) { + if (pair[1] == str) { + return pair[0]; + } + } + return str; + }; + + MotaActionFunctions.replaceToName = function (str) { + if (!str || MotaActionFunctions.disableReplace) return str; + var map = {}, + list = []; + MotaActionFunctions.pattern.replaceStatusList.forEach(function (v) { + map[v[0]] = v[1]; + list.push(v[0]); + }); + str = str + .replace( + new RegExp("status:(" + list.join("|") + ")\\b", "g"), + function (a, b) { + return map[b] ? "状态:" + map[b] : b; + } + ) + .replace(/status:/g, "状态:"); + str = str + .replace( + new RegExp("buff:(" + list.join("|") + ")\\b", "g"), + function (a, b) { + return map[b] ? "增益:" + map[b] : b; + } + ) + .replace(/buff:/g, "增益:"); + map = {}; + list = []; + MotaActionFunctions.pattern.replaceItemList.forEach(function (v) { + map[v[0]] = v[1]; + list.push(v[0]); + }); + str = str + .replace( + new RegExp("item:(" + list.join("|") + ")\\b", "g"), + function (a, b) { + return map[b] ? "物品:" + map[b] : b; + } + ) + .replace(/item:/g, "物品:"); + str = str + .replace(/flag:/g, "变量:") + .replace(/switch:/g, "独立开关:") + .replace(/global:/g, "全局存储:"); + + MotaActionFunctions.pattern.replaceEnemyValueList.forEach(function (v) { + map[v[0]] = v[1]; + list.push(v[0]); + }); + str = str + .replace( + new RegExp("enemy:([a-zA-Z0-9_]+)[.:](" + list.join("|") + ")\\b", "g"), + function (a, b, c) { + return map[c] ? "enemy:" + b + ":" + map[c] : c; + } + ) + .replace(/(enemy:[a-zA-Z0-9_]+)[.::]/g, "$1:"); + + map = {}; + list = []; + MotaActionFunctions.pattern.replaceEnemyList.forEach(function (v) { + map[v[0]] = v[1]; + list.push(v[0]); + }); + str = str + .replace( + new RegExp("enemy:(" + list.join("|") + ")\\b", "g"), + function (a, b) { + return map[b] ? "怪物:" + map[b] : b; + } + ) + .replace(/enemy:/g, "怪物:"); + + str = str + .replace(/blockId:/g, "图块ID:") + .replace(/blockNumber:/g, "图块数字:") + .replace(/blockCls:/g, "图块类别:") + .replace(/equip:/g, "装备孔:"); + return str; + }; + + MotaActionFunctions.replaceFromName = function (str) { + if (!str || MotaActionFunctions.disableReplace) return str; + var map = {}, + list = []; + MotaActionFunctions.pattern.replaceStatusList.forEach(function (v) { + map[v[1]] = v[0]; + list.push(v[1]); + }); + str = str + .replace( + new RegExp( + "状态[::](" + + list.join("|") + + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", + "g" + ), + function (a, b) { + return map[b] ? "status:" + map[b] : b; + } + ) + .replace(/状态[::]/g, "status:"); + str = str + .replace( + new RegExp( + "增益[::](" + + list.join("|") + + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", + "g" + ), + function (a, b) { + return map[b] ? "buff:" + map[b] : b; + } + ) + .replace(/增益[::]/g, "buff:"); + map = {}; + list = []; + MotaActionFunctions.pattern.replaceItemList.forEach(function (v) { + map[v[1]] = v[0]; + list.push(v[1]); + }); + str = str + .replace( + new RegExp( + "物品[::](" + + list.join("|") + + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", + "g" + ), + function (a, b) { + return map[b] ? "item:" + map[b] : b; + } + ) + .replace(/物品[::]/g, "item:"); + str = str + .replace(/变量[::]/g, "flag:") + .replace(/独立开关[::]/g, "switch:") + .replace(/全局存储[::]/g, "global:"); + + map = {}; + list = []; + MotaActionFunctions.pattern.replaceEnemyList.forEach(function (v) { + map[v[1]] = v[0]; + list.push(v[1]); + }); + str = str + .replace( + new RegExp( + "(enemy:|怪物[::])(" + + list.join("|") + + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", + "g" + ), + function (a, b, c, d) { + return map[c] ? "enemy:" + map[c] : c; + } + ) + .replace(/怪物[::]/g, "enemy:"); + + map = {}; + list = []; + MotaActionFunctions.pattern.replaceEnemyValueList.forEach(function (v) { + map[v[1]] = v[0]; + list.push(v[1]); + }); + str = str + .replace( + new RegExp( + "enemy:([a-zA-Z0-9_]+)[::](" + + list.join("|") + + ")(?:$|(?=[^a-zA-Z0-9_\\u4E00-\\u9FCC\\u3040-\\u30FF\\u2160-\\u216B\\u0391-\\u03C9]))", + "g" + ), + function (a, b, c, d) { + return map[c] ? "enemy:" + b + ":" + map[c] : c; + } + ) + .replace(/(enemy:[a-zA-Z0-9_]+)[::]/g, "$1:"); + + str = str + .replace(/图块I[dD][::]/g, "blockId:") + .replace(/图块数字[::]/g, "blockNumber:") + .replace(/图块类别[::]/g, "blockCls:") + .replace(/装备孔[::]/g, "equip:"); + + return str; + }; +}; diff --git a/_server/config.json b/_server/config.json index 5d318ea..84aac55 100644 --- a/_server/config.json +++ b/_server/config.json @@ -1 +1 @@ -{"viewportLoc":[0,0],"editorLastFloorId":"street01"} \ No newline at end of file +{"viewportLoc":[0,0],"editorLastFloorId":"street02"} \ No newline at end of file diff --git a/project/events.js b/project/events.js index 4f77b85..ec024f2 100644 --- a/project/events.js +++ b/project/events.js @@ -154,31 +154,270 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = "time": 50 }, { - "type": "setCurtain", - "color": [ + "type": "changebg", + "img1": "", + "img2": "", + "time": 30, + "style": "引入" + }, + { + "type": "over", + "text": "人生不如意事,十常居七八。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ 0, 0, 0, 1 ], - "time": 500, - "keep": true + "font": "bold 48px Verdana" }, - "\b[center]人生不如意事,十常居七八。", - "\b[center]世间的万物皆被装缀着不公的色彩。", - "\b[center]没错,就像——", - "\b[center]十几年前的那一天,", - "\b[center]在都市的角落,同许多的生命共同消逝一般。", - "\b[center]没错,就像——", - "\b[center]十几年前的那天起以来,", - "\b[center]无数的生命被那无法逃脱的污泥囚禁一样。", - "\b[center]人生不如意事,十常居七八。", - "\b[center]世间的万物皆被装缀着不公的色彩。", - "\b[center]没错,就像——", - "\b[center]如今,这一天。", { - "type": "setCurtain", - "time": 500 + "type": "over", + "text": "世间的万物皆被装缀着不公的色彩。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "没错,就像——", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "十几年前的那一天,", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "在都市的角落,同许多的生命共同消逝一般。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "没错,就像——", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "十几年前的那天起以来,", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "无数的生命被那无法逃脱的污泥囚禁一样。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "人生不如意事,十常居七八。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "世间的万物皆被装缀着不公的色彩。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "没错,就像——", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "over", + "text": "如今,这一天。", + "image": "", + "time": 3000, + "hidetime": 30, + "sound": "", + "textColor": [ + 255, + 255, + 255, + 1 + ], + "boldColor": [ + 0, + 0, + 0, + 1 + ], + "font": "bold 48px Verdana" + }, + { + "type": "changebg", + "img1": "", + "img2": "other_0001.png", + "time": 30, + "style": "场景切换" }, { "type": "cgtext", @@ -240,6 +479,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "other_0001.png", + "img2": "bg_3563.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "bg_3563.png", @@ -400,6 +646,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "bg_3563.png", + "img2": "other_0002.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "other_0002.png", @@ -560,6 +813,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "other_0002.png", + "img2": "other_0001.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "other_0001.png", @@ -580,6 +840,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "other_0001.png", + "img2": "other_0003.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "other_0003.png", @@ -620,6 +887,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "other_0003.png", + "img2": "", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "", @@ -640,6 +914,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "", + "img2": "other_0003.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "other_0003.png", @@ -680,6 +961,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "other_0003.png", + "img2": "", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "", @@ -825,6 +1113,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = "name": "Blind_Alley.mp3", "keep": true }, + { + "type": "changebg", + "img1": "", + "img2": "bg_6004.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "bg_6004.png", @@ -945,6 +1240,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "bg_6004.png", + "img2": "other_0004.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "other_0004.png", @@ -1005,6 +1307,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "other_0004.png", + "img2": "bg_3601.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "bg_3601.png", @@ -1065,6 +1374,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "bg_3601.png", + "img2": "bg_3531.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "bg_3531.png", @@ -1347,7 +1663,7 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = }, { "type": "cgtext", - "bg": "", + "bg": "bg_3531.png", "WindowSkin": false, "head": { "name": "", @@ -1735,7 +2051,7 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = }, "name": "凯伊姆", "time": 50, - "sound": "aiy3100000100.mp3", + "sound": "aiy310000100.mp3", "text": "「话说回来,那个要落跑的女人呢?」", "bodyList": [ { @@ -2395,7 +2711,7 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = }, "name": "凯伊姆", "time": 50, - "sound": "aiy3100000110.mp3", + "sound": "aiy310000110.mp3", "text": "「我要走了」", "bodyList": [ { @@ -2455,7 +2771,7 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = }, "name": "凯伊姆", "time": 50, - "sound": "aiy3100000120.mp3", + "sound": "aiy310000120.mp3", "text": "「啊啊」", "bodyList": [ { @@ -2509,6 +2825,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "bg_3531.png", + "img2": "bg_3601.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "bg_3601.png", @@ -2709,6 +3032,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "bg_3601.png", + "img2": "bg_3531.png", + "time": 30, + "style": "场景切换" + }, { "type": "cgtext", "bg": "bg_3531.png", @@ -2729,6 +3059,13 @@ var events_c12a15a8_c380_4b28_8144_256cba95f760 = } ] }, + { + "type": "changebg", + "img1": "bg_3531.png", + "img2": "", + "time": 30, + "style": "引出" + }, { "type": "comment", "text": "好多立绘,先更这点(吐槽一下)" diff --git a/project/floors/street01.js b/project/floors/street01.js index 8aa39f8..59a851e 100644 --- a/project/floors/street01.js +++ b/project/floors/street01.js @@ -25,6 +25,12 @@ main.floors.street01= ], "direction": "up" } + ], + "5,10": [ + { + "type": "insert", + "name": "chapter0" + } ] }, "changeFloor": { diff --git a/project/plugins.js b/project/plugins.js index e7dd469..25390bd 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -55,6 +55,14 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.doAction() } }) + core.registerEvent("changebg", function (data) { + if (!main.replayChecking && !core.isReplaying()) { + core.changebg(data.img1, data.img2, data.time, data.style) + } else { + core.doAction() + } + }) + core.registerEvent("cgtext", function (data) { if (!main.replayChecking && !core.isReplaying()) { core.ui.cgText.image = data.bg; @@ -7407,6 +7415,7 @@ core.plugin.animate = { ], '特效表现': [ MotaActionBlocks['sleep_s'].xmlText(), + MotaActionBlocks['changebg_s'].xmlText(), MotaActionFunctions.actionParser.parseList({ "type": "wait", "timeout": 0, @@ -9865,16 +9874,21 @@ core.plugin.animate = { core.insertAction(data) core.doAction(); - + } else if (!core.status.event.data) { + cg.style.display = "none" + core.ui._animateUI('hide', null, () => { + core.doAction() + }); } else { // 正在淡入淡出的话不执行 if (core.status.event.animateUI) return; auto = false; - const data = core.clone(core.status.event.data.current); + // 打字机效果显示全部文字 if (core.status.event.interval != null) { + const data = core.clone(core.status.event.data?.current); data.showAll = true; data.time = 0 data.text = data.text.replace(/(\\(z))(\[.*?])?/g, ""); //去除打字机暂停效果 @@ -9989,7 +10003,10 @@ core.plugin.animate = { if (auto && !this.WindowSkin && !core.ui.cgText.sound || (core.ui.cgText.sound && !core.musicStatus.soundStatus)) { setTimeout(() => { if (auto) { - core.doAction() + cg.style.display = "none" + core.ui._animateUI('hide', null, () => { + core.doAction() + }) } }, 2000) } @@ -10001,8 +10018,10 @@ core.plugin.animate = { core.status.event.interval = null; if (auto && !this.WindowSkin && !core.ui.cgText.sound || (core.ui.cgText.sound && !core.musicStatus.soundStatus)) setTimeout(() => { if (auto) { - - core.doAction() + cg.style.display = "none" + core.ui._animateUI('hide', null, () => { + core.doAction() + }) } }, 2000) } @@ -10064,7 +10083,10 @@ core.plugin.animate = { if (this.sound && auto && !this.WindowSkin && core.musicStatus.soundStatus) { setTimeout(() => { if (auto) { - core.doAction() + cg.style.display = "none" + core.ui._animateUI('hide', null, () => { + core.doAction() + }) } }, 2000) } @@ -10094,131 +10116,242 @@ core.plugin.animate = { core.ui.cgText = new cgText() }, "旁白": function () { -// 在此增加新插件 -const over = document.createElement('canvas'); //over画布设置 -over.style.position = 'absolute'; -over.style.zIndex = 310; -over.style.display = "none" -over.id = 'over'; -main.dom.gameGroup.insertAdjacentElement('afterend', over) -over.style.top = "50%" -over.style.left = "50%" -over.style.transform = "translate(-50%,-50%)" -const ctx = over.getContext("2d"); -main.dom.over = over; + // 在此增加新插件 + const over = document.createElement('canvas'); //over画布设置 + over.style.position = 'absolute'; + over.style.zIndex = 310; + over.style.display = "none" + over.id = 'over'; + main.dom.gameGroup.insertAdjacentElement('afterend', over) + over.style.top = "50%" + over.style.left = "50%" + over.style.transform = "translate(-50%,-50%)" + const ctx = over.getContext("2d"); + main.dom.over = over; -this.over = function (image, time = 3000, hidetime = 100, sound = "", textColor = "#FFFFFF", boldColor = "#000000", font = "bold 48px Verdana", text = "") { - if (!core.isPlaying()) { return core.doAction() } - const img = core.material.images.images?.[image] - over.style.display = "block"; - let globalAlpha = 0 - core.registerAnimationFrame("overshow", true, () => { + this.over = function (image, time = 3000, hidetime = 100, sound = "", textColor = "#FFFFFF", boldColor = "#000000", font = "bold 48px Verdana", text = "") { + if (!core.isPlaying()) { return core.doAction() } + const img = core.material.images.images?.[image] + over.style.display = "block"; + let globalAlpha = 0 + core.registerAnimationFrame("overshow", true, () => { - core.clearMap(ctx) - if (core.domStyle.isVertical) { - ctx.canvas.width = 1248; - ctx.canvas.height = 2028; - ctx.save(); //保存设置 - ctx.translate(1248, 0) //重新定位右上角为基准 - ctx.rotate(Math.PI / 2) //旋转90度 - } else { - ctx.canvas.width = 2028; - ctx.canvas.height = 1248; - } - ctx.globalAlpha = 1 - - if (img) { //绘制背景 - ctx.drawImage(img, 0, 0, 2028, 1248) - - } else { - core.fillRect(ctx, 0, 0, 2028, 1248) - } - globalAlpha++ - ctx.globalAlpha = globalAlpha / hidetime - core.setTextAlign(ctx, 'center'); - core.fillBoldText(ctx, text, 1014, 624, textColor, boldColor, font) - - ctx.restore(); - if (globalAlpha >= hidetime) { - core.unregisterAnimationFrame("overshow") - if (sound && core.material.sounds[sound] && core.musicStatus.soundStatus) { - core.playSound(sound, null, () => { - core.registerAnimationFrame("overhide", true, () => { - - core.clearMap(ctx) - if (core.domStyle.isVertical) { - ctx.canvas.width = 1248; - ctx.canvas.height = 2028; - ctx.save(); //保存设置 - ctx.translate(1248, 0) //重新定位右上角为基准 - ctx.rotate(Math.PI / 2) //旋转90度 - } else { - ctx.canvas.width = 2028; - ctx.canvas.height = 1248; - } - ctx.globalAlpha = 1 - if (img) { //绘制背景 - ctx.drawImage(img, 0, 0, 2028, 1248) - - } else { - core.fillRect(ctx, 0, 0, 2028, 1248) - } - globalAlpha-- - ctx.globalAlpha = globalAlpha / hidetime - core.setTextAlign(ctx, 'center'); - core.fillBoldText(ctx, text, 1014, 624, textColor, boldColor, font) - - ctx.restore(); - if (globalAlpha <= 0) { - over.style.display = 'none' - core.unregisterAnimationFrame("overhide") - core.doAction() - } - }) - }) + core.clearMap(ctx) + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0) //重新定位右上角为基准 + ctx.rotate(Math.PI / 2) //旋转90度 } else { - setTimeout(() => { - core.registerAnimationFrame("overhide", true, () => { - - core.clearMap(ctx) - if (core.domStyle.isVertical) { - ctx.canvas.width = 1248; - ctx.canvas.height = 2028; - ctx.save(); //保存设置 - ctx.translate(1248, 0) //重新定位右上角为基准 - ctx.rotate(Math.PI / 2) //旋转90度 - } else { - ctx.canvas.width = 2028; - ctx.canvas.height = 1248; - } - ctx.globalAlpha = 1 - if (img) { //绘制背景 - ctx.drawImage(img, 0, 0, 2028, 1248) - - } else { - core.fillRect(ctx, 0, 0, 2028, 1248) - } - globalAlpha-- - ctx.globalAlpha = globalAlpha / hidetime - core.setTextAlign(ctx, 'center'); - core.fillBoldText(ctx, text, 1014, 624, textColor, boldColor, font) - - ctx.restore(); - - if (globalAlpha <= 0) { - - over.style.display = 'none' - core.unregisterAnimationFrame("overhide") - core.doAction(); - } - }) - }, time) + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; } + ctx.globalAlpha = 1 + + if (img) { //绘制背景 + ctx.drawImage(img, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + globalAlpha++ + ctx.globalAlpha = globalAlpha / hidetime + core.setTextAlign(ctx, 'center'); + core.fillBoldText(ctx, text, 1014, 624, textColor, boldColor, font) + + ctx.restore(); + if (globalAlpha >= hidetime) { + core.unregisterAnimationFrame("overshow") + if (sound && core.material.sounds[sound] && core.musicStatus.soundStatus) { + core.playSound(sound, null, () => { + core.registerAnimationFrame("overhide", true, () => { + + core.clearMap(ctx) + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0) //重新定位右上角为基准 + ctx.rotate(Math.PI / 2) //旋转90度 + } else { + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; + } + ctx.globalAlpha = 1 + if (img) { //绘制背景 + ctx.drawImage(img, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + globalAlpha-- + ctx.globalAlpha = globalAlpha / hidetime + core.setTextAlign(ctx, 'center'); + core.fillBoldText(ctx, text, 1014, 624, textColor, boldColor, font) + + ctx.restore(); + if (globalAlpha <= 0) { + over.style.display = 'none' + core.unregisterAnimationFrame("overhide") + core.doAction() + } + }) + }) + } else { + setTimeout(() => { + core.registerAnimationFrame("overhide", true, () => { + + core.clearMap(ctx) + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0) //重新定位右上角为基准 + ctx.rotate(Math.PI / 2) //旋转90度 + } else { + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; + } + ctx.globalAlpha = 1 + if (img) { //绘制背景 + ctx.drawImage(img, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + globalAlpha-- + ctx.globalAlpha = globalAlpha / hidetime + core.setTextAlign(ctx, 'center'); + core.fillBoldText(ctx, text, 1014, 624, textColor, boldColor, font) + + ctx.restore(); + + if (globalAlpha <= 0) { + + over.style.display = 'none' + core.unregisterAnimationFrame("overhide") + core.doAction(); + } + }) + }, time) + } + } + }) + } + this.changebg = function (img1, img2, time, style) { + let globalAlpha1 = 0 + let globalAlpha2 = time + img1 = core.material.images.images?.[img1] + img2 = core.material.images.images?.[img2] + over.style.display = "block"; + switch (style) { + case "引入": + core.registerAnimationFrame("bgin", true, () => { + + core.clearMap(ctx) + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0) //重新定位右上角为基准 + ctx.rotate(Math.PI / 2) //旋转90度 + } else { + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; + } + ctx.globalAlpha = globalAlpha1 / time + if (img2) { //绘制背景 + ctx.drawImage(img2, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + globalAlpha1++ + ctx.restore(); + if (globalAlpha1 >= time) { + core.unregisterAnimationFrame("bgin"); + over.style.display = "none"; + core.doAction() + } + }) + + break; + case "引出": + core.registerAnimationFrame("bgout", true, () => { + + core.clearMap(ctx) + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0) //重新定位右上角为基准 + ctx.rotate(Math.PI / 2) //旋转90度 + } else { + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; + } + ctx.globalAlpha = globalAlpha2 / time + if (img1) { //绘制背景 + ctx.drawImage(img1, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + globalAlpha2-- + ctx.restore(); + if (globalAlpha2 <= 0) { + core.unregisterAnimationFrame("bgout"); + over.style.display = "none"; + core.doAction() + } + }) + + break; + case "场景切换": + core.registerAnimationFrame("changebg", true, () => { + + core.clearMap(ctx) + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0) //重新定位右上角为基准 + ctx.rotate(Math.PI / 2) //旋转90度 + } else { + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; + } + ctx.globalAlpha = 1 + core.fillRect(ctx, 0, 0, 2028, 1248) + ctx.globalAlpha = globalAlpha2 / time + if (img1) { //绘制背景 + ctx.drawImage(img1, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + ctx.globalAlpha = globalAlpha1 / time + if (img2) { //绘制背景 + ctx.drawImage(img2, 0, 0, 2028, 1248) + + } else { + core.fillRect(ctx, 0, 0, 2028, 1248) + } + globalAlpha2-- + globalAlpha1++ + ctx.restore(); + if (globalAlpha2 <= 0 || globalAlpha1 >= time) { + core.unregisterAnimationFrame("changebg"); + over.style.display = "none"; + core.doAction() + } + }) + + break; + } - }) - - -} + } }, "属性映射": function () { // 在此增加新插件