diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 2a3d6ddd..92c52eb2 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -192,6 +192,7 @@ action | show_s | hide_s | trigger_s + | insert_s | revisit_s | exit_s | setBlock_s @@ -481,6 +482,20 @@ var code = '{"type": "trigger", "loc": ['+PosString_0+','+PosString_1+']},\n'; return code; */; +insert_s + : '插入事件' 'x' PosString ',' 'y' PosString '楼层' IdString? Newline + + +/* insert_s +tooltip : insert: 立即插入另一个地点的事件执行,当前事件不会中断,事件坐标不会改变 +helpUrl : https://ckcz123.github.io/mota-js/#/event?id=insert%ef%bc%9a%e6%8f%92%e5%85%a5%e5%8f%a6%e4%b8%80%e4%b8%aa%e5%9c%b0%e7%82%b9%e7%9a%84%e4%ba%8b%e4%bb%b6 +default : ["0","0",""] +colour : this.eventColor +IdString_0 = IdString_0 && (', "floorId": "'+IdString_0+'"'); +var code = '{"type": "insert", "loc": ['+PosString_0+','+PosString_1+']'+IdString_0+'},\n'; +return code; +*/; + revisit_s : '重启当前事件' Newline @@ -1966,6 +1981,10 @@ ActionParser.prototype.parseAction = function() { this.next = MotaActionBlocks['trigger_s'].xmlText([ data.loc[0],data.loc[1],this.next]); break; + case "insert": // 强制插入另一个点的事件在当前事件列表执行,当前坐标和楼层不会改变 + this.next = MotaActionBlocks['insert_s'].xmlText([ + data.loc[0],data.loc[1],data.floorId||'',this.next]); + break; case "playSound": this.next = MotaActionBlocks['playSound_s'].xmlText([ data.name,this.next]); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index d4c6092d..8a982f88 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -126,6 +126,7 @@ editor_blockly = function () { MotaActionBlocks['hideBgFgMap_s'].xmlText(), MotaActionBlocks['setBgFgBlock_s'].xmlText(), MotaActionBlocks['trigger_s'].xmlText(), + MotaActionBlocks['insert_s'].xmlText(), MotaActionBlocks['move_s'].xmlText(), MotaActionBlocks['jump_s'].xmlText(), MotaActionBlocks['disableShop_s'].xmlText(), diff --git a/docs/event.md b/docs/event.md index 9a94da0d..19dbafe1 100644 --- a/docs/event.md +++ b/docs/event.md @@ -477,6 +477,32 @@ NPC对话事件结束后如果需要NPC消失也需要调用 `{"type": "hide"}` 例如上面这个例子,下面的文字将不会再被显示,而是直接跳转到`"3,6"`对应的事件列表从头执行。 +### insert:插入另一个地点的事件 + +`{"type":"insert"}` 会插入另一个地点的事件执行。 + +其基本写法如下: + +``` js +"x,y": [ // 实际执行的事件列表 + {"type": "insert", "loc": [3,6]}, // 插入[3,6]点的事件并执行 + {"type": "insert", "loc": [10,10], "floorId": "MT1"}, // 插入MT1层[10,10]点的事件并执行 + "上面的插入事件执行完毕后会接着继续执行后面的事件" +] +``` + +loc是必须的,代表另一个地点的坐标。 + +floorId可选,代表另一个地点所在的楼层;如果不写则默认为当前层。 + +和`type:trigger`不同的是,**`type:trigger`是立刻将当前事件结束(剩下所有内容都忽略),然后重新启动另一个地点的action事件。** + +但是`type:insert`不会结束当前事件,而是直接将另一个地点的事件列表“插入”到当前事件列表中执行。 + +**这个过程中,当前事件不会被结束,当前的楼层和事件坐标不会发生改变。** 插入的事件执行完毕后,会继续执行接下来的内容。 + +我们某个事件写在某个角落的墙上然后远程调用,从而达到“公共事件”的效果。 + ### revisit:立即重启当前事件 revisit和trigger完全相同,只不过是立刻触发的还是本地点的事件 diff --git a/docs/personalization.md b/docs/personalization.md index 612f3d46..8b77af83 100644 --- a/docs/personalization.md +++ b/docs/personalization.md @@ -521,6 +521,15 @@ case 89: // 使用该按键的keyCode,比如Y键就是89 ## 公共事件 +从2.5.1开始,H5提供了`{"type":"insert"}`事件,完美支持了公共事件的写法。 + +我们只需要将需要的公共事件放在某个角落的墙上(或者甚至单独弄一层专门摆放公共事件),并使用“插入事件”,即可进行调用。 + +具体详见[插入另一个地点的事件](event#insert:插入另一个地点的事件)。 + +当然,继续使用**插件**的写法也是可以的。具体参见“脚本编辑 - 插件编写”。 + + ## 自定义状态栏(新增显示项) 在V2.2以后,我们可以自定义状态栏背景图(全塔属性 - statusLeftBackground)等等。 diff --git a/libs/core.js b/libs/core.js index 5e699f9f..de889da3 100644 --- a/libs/core.js +++ b/libs/core.js @@ -148,7 +148,7 @@ function core() { }, 'textAttribute': { 'position': "center", - "offset": 20, + "offset": 0, "title": [255,215,0,1], "background": [0,0,0,0.85], "text": [255,255,255,1], diff --git a/libs/events.js b/libs/events.js index f808aee2..3c8e6a46 100644 --- a/libs/events.js +++ b/libs/events.js @@ -774,6 +774,15 @@ events.prototype.doAction = function() { this.doAction(); break; } + case "insert": + { + var toX=core.calValue(data.loc[0]), toY=core.calValue(data.loc[1]); + var floorId = data.floorId || core.status.floorId; + var event = core.floors[floorId].events[toX+","+toY]; + if (core.isset(event)) core.insertAction(event); + this.doAction(); + break; + } case "playSound": if (!core.status.replay.replaying) core.playSound(data.name); @@ -910,7 +919,7 @@ events.prototype.doAction = function() { case "switch": // 条件选择 var key = core.calValue(data.condition) for (var i = 0; i < data.caseList.length; i++) { - if (core.calValue(data.caseList[i].case) == key || core.calValue(data.caseList[i].case) == "default") { + if (data.caseList[i].case=="default" || core.calValue(data.caseList[i].case) == key) { core.events.insertAction(data.caseList[i].action); break; } diff --git a/project/floors/sample1.js b/project/floors/sample1.js index a7ab22f8..659098a7 100644 --- a/project/floors/sample1.js +++ b/project/floors/sample1.js @@ -594,7 +594,7 @@ main.floors.sample1= ] }, { - "case": "'default'", + "case": "default", "action": [ { "type": "comment",