diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 48b6854c..b117d948 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -457,6 +457,75 @@ return code; */; +// doorInfo 事件编辑器入口之一 +doorInfo_m + : '门信息' '开关门时间' Int '开门音效' EvalString? '关门音效' EvalString? BGNL? Newline '需要钥匙' doorKeyList+ BEND + + +/* doorInfo_m +tooltip : 开门信息 +default : [160, 'door.mp3', 'door.mp3'] +helpUrl : https://h5mota.com/games/template/_docs/#/event +EvalString_0 = EvalString_0 && (', "openSound": "' + EvalString_0 + '"'); +EvalString_1 = EvalString_1 && (', "closeSound": "' + EvalString_1 + '"'); +var code = '{"time": '+Int_0+EvalString_0+EvalString_1+', "keys": {\n'+doorKeyList_0+'\n}}'; +return code; +*/; + +doorKeyList + : doorKeyKnown + | doorKeyUnknown + | doorKeyEmpty; + + +doorKeyKnown + : Key_List ':' Int BEND + + +/* doorKeyKnown +tooltip : 需要钥匙 +default : ['yellowKey', 1] +helpUrl : https://h5mota.com/games/template/_docs/#/event +return '"'+Key_List_0+'": '+Int_0+', '; +*/; + +doorKeyUnknown + : IdString ':' Int BEND + + +/* doorKeyUnknown +tooltip : 需要钥匙 +default : ['orangeKey', 1] +helpUrl : https://h5mota.com/games/template/_docs/#/event +return '"'+IdString_0+'": '+Int_0+', '; +*/; + + +doorKeyEmpty + : Newline + +/* doorKeyEmpty +var code = ' \n'; +return code; +*/; + + +faceIds_m + : '行走图朝向:' BGNL? Newline '向上ID' IdString? '向下ID' IdString? '向左ID' IdString? '向右ID' IdString? BEND + + +/* faceIds_m +tooltip : 行走图朝向 +default : ["","","",""] +helpUrl : https://h5mota.com/games/template/_docs/#/event +return '{' + [ + IdString_0 && ('"up": "' + IdString_0 +'"'), + IdString_1 && ('"down": "' + IdString_1 +'"'), + IdString_2 && ('"left": "' + IdString_2 +'"'), + IdString_3 && ('"right": "' + IdString_3 +'"'), +].join(', ') + '}\n'; +*/; + //为了避免关键字冲突,全部加了_s //动作 @@ -3042,6 +3111,10 @@ Equip_List : '生命'|'生命上限'|'攻击'|'防御'|'护盾'|'魔力'|'魔力上限' /*Equip_List ['hp','hpmax','atk','def','mdef','mana','manamax']*/; +Key_List + : '黄钥匙'|'蓝钥匙'|'红钥匙'|'绿钥匙'|'铁门钥匙' + /*Key_List ['yellowKey','blueKey','redKey','greenKey','steelKey']*/; + //转blockly后不保留需要加" EvalString : Equote_double (ESC_double | ~["\\])* Equote_double diff --git a/_server/MotaActionParse.js b/_server/MotaActionParse.js index acfb4dcf..0724ec9a 100644 --- a/_server/MotaActionParse.js +++ b/_server/MotaActionParse.js @@ -74,6 +74,22 @@ ActionParser.prototype.parse = function (obj,type) { } return MotaActionBlocks['equip_m'].xmlText([obj.type, obj.animate, buildEquip(obj.value), buildEquip(obj.percentage)]); + case 'doorInfo': + if(!obj) obj={}; + var buildKeys = function (obj) { + obj = obj || {}; + var text_choices = null; + var knownListKeys = MotaActionBlocks.doorKeyKnown.json.args0[0].options.map(function (one) {return one[1];}) + Object.keys(obj).sort().forEach(function (key) { + var one = knownListKeys.indexOf(key) >= 0 ? 'doorKeyKnown' : 'doorKeyUnknown'; + text_choices = MotaActionBlocks[one].xmlText([ + key, obj.key, text_choices + ]); + }) + return text_choices; + } + return MotaActionBlocks['doorInfo_m'].xmlText([obj.time || 160, obj.openSound, obj.closeSound, buildKeys(obj.keys)]); + case 'floorImage': if(!obj) obj=[]; var text_choices = null; @@ -84,6 +100,9 @@ ActionParser.prototype.parse = function (obj,type) { } return MotaActionBlocks['floorImage_m'].xmlText([text_choices]); + case 'faceIds': + if(!obj) obj={}; + return MotaActionBlocks['faceIds_m'].xmlText([obj.up||"", obj.down||"", obj.left||"", obj.right||""]); case 'shop': var buildsub = function(obj,parser,next){ diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 1d319b71..f857c66f 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -81,6 +81,10 @@ editor_blockly = function () { MotaActionFunctions.actionParser.parse([{ "name": "bg.jpg", "x": 0, "y": 0, "canvas": "bg" }], 'floorImage'), + MotaActionFunctions.actionParser.parse({ + "time": 160, "openSound": "door.mp3", "closeSound": "door.mp3", "keys": {"yellowKey": 1, "orangeKey": 1} + }, 'doorInfo'), + MotaActionBlocks['faceIds_m'].xmlText(), ], '显示文字':[ MotaActionBlocks['text_0_s'].xmlText(), @@ -1052,7 +1056,8 @@ function omitedcheckUpdateFunction(event) { || (type == 'choices_s' && name == 'IdString_0') || (type == 'choicesContext' && name == 'IdString_0') || (type == 'closeDoor_s' && name == 'IdString_0') || (type == 'setBlock_s' && name == 'EvalString_0') || (type == 'setBgFgBlock_s' && name == 'EvalString_0') || (type == 'drawIcon_s' && name == 'IdString_0') - || (type == 'shopsub' && name == 'IdString_1') || (type == 'shopChoices' && name == 'IdString_0')) { + || (type == 'shopsub' && name == 'IdString_1') || (type == 'shopChoices' && name == 'IdString_0') + || type == 'faceIds_m') { return filter(allIds, content); } @@ -1062,13 +1067,14 @@ function omitedcheckUpdateFunction(event) { } // 对道具ID进行补全 - if ((type == 'useItem_s' || type == 'loadEquip_s') && name == 'IdString_0') { + if ((type == 'useItem_s' || type == 'loadEquip_s' || type == 'doorKeyUnknown') && name == 'IdString_0') { return filter(allItems, content); } // 对图片名进行补全 if ((type == 'showImage_s' || type == 'showImage_1_s' || type == 'showGif_s' || type == 'setHeroIcon_s' - || type == 'follow_s' || type == 'unfollow_s' || type == 'drawImage_s' || type == 'drawImage_1_s') && name == 'EvalString_0') { + || type == 'follow_s' || type == 'unfollow_s' || type == 'drawImage_s' || type == 'drawImage_1_s' + || type == 'floorOneImage') && name == 'EvalString_0') { return filter(allImages, content); } diff --git a/_server/table/comment.js b/_server/table/comment.js index ca63b022..bdf74943 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -336,13 +336,15 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { }, "doorInfo": { "_leaf": true, - "_type": "textarea", + "_type": "event", + "_event": "doorInfo", "_docs": "门信息", "_data": "该图块的门信息,是一个四元数组。\n第一项为所需要的钥匙信息,第二项为开关门的毫秒数,第三项为开此门时的音效,第四项为关此门时的音效。仅对animates生效。" }, "faceIds": { "_leaf": true, - "_type": "textarea", + "_type": "event", + "_event": "faceIds", "_docs": "行走图朝向", "_data": "行走图朝向,仅对NPC有效。可以在这里定义同一个NPC的多个朝向行走图。\n比如 {\"up\":\"N333\",\"down\":\"N334\",\"left\":\"N335\",\"right\":\"N336\"} 就将该素材的上下左右朝向分别绑定到N333,N334,N335和N336四个图块。\n在勇士撞上NPC时,或NPC在移动时,会自动选择最合适的朝向图块(如果存在定义)来进行绘制。" } diff --git a/editor-mobile.html b/editor-mobile.html index e73794aa..ea13578b 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -220,6 +220,8 @@ + + diff --git a/editor.html b/editor.html index daba251b..3ede676b 100644 --- a/editor.html +++ b/editor.html @@ -216,6 +216,8 @@ + + diff --git a/libs/events.js b/libs/events.js index 66e9922b..412f20b3 100644 --- a/libs/events.js +++ b/libs/events.js @@ -469,13 +469,14 @@ events.prototype._openDoor_check = function (id, x, y, needKey) { return clearAndReturn(); doorInfo = doorInfo.doorInfo; // Check all keys - var keyInfo = doorInfo[0]; + var keyInfo = doorInfo.keys || {}; if (needKey) { - if (keyInfo == null) { - core.drawTip("无法开启此门"); - return clearAndReturn(); - } for (var keyName in keyInfo) { + // --- 如果是一个不存在的道具,则直接认为无法开启 + if (!core.material.items[keyName]) { + core.drawTip("无法开启此门"); + return clearAndReturn(); + } var keyValue = keyInfo[keyName]; if (core.itemCount(keyName) < keyValue) { core.drawTip("你没有" + ((core.material.items[keyName] || {}).name || "钥匙"), null, true); @@ -487,7 +488,7 @@ events.prototype._openDoor_check = function (id, x, y, needKey) { core.removeItem(keyName, keyInfo[keyName]); } } - core.playSound(doorInfo[2] || 'door.mp3'); + core.playSound(doorInfo.openSound); return true; } @@ -495,7 +496,7 @@ events.prototype._openDoor_animate = function (id, x, y, callback) { var blockInfo = core.getBlockInfo(id); var image = blockInfo.image, posY = blockInfo.posY, height = blockInfo.height; - var speed = (core.getBlockById(id).event.doorInfo[1] || 160) / 4; + var speed = (core.getBlockById(id).event.doorInfo.time || 160) / 4; var locked = core.status.lockControl; core.lockControl(); @@ -2629,11 +2630,11 @@ events.prototype.closeDoor = function (x, y, id, callback) { } // 关门动画 - core.playSound(doorInfo[3] || 'door.mp3'); + core.playSound(doorInfo.closeDoor); var blockInfo = core.getBlockInfo(id); var image = blockInfo.image, posY = blockInfo.posY, height = blockInfo.height; - var speed = (doorInfo[1] || 160) / 4, state = 0; + var speed = (doorInfo.time || 160) / 4, state = 0; var animate = window.setInterval(function () { state++; if (state == 4) { diff --git a/project/maps.js b/project/maps.js index 09a10db7..0883429d 100644 --- a/project/maps.js +++ b/project/maps.js @@ -1,8 +1,8 @@ var maps_90f36752_8815_4be8_b32b_d7fad1d0542e = { - "1": {"cls":"animates","id":"yellowWall","canBreak":true,"animate":1,"doorInfo":[null,160,"door.mp3","door.mp3"]}, - "2": {"cls":"animates","id":"whiteWall","canBreak":true,"animate":1,"doorInfo":[null,160,"door.mp3","door.mp3"]}, - "3": {"cls":"animates","id":"blueWall","canBreak":true,"animate":1,"doorInfo":[null,160,"door.mp3","door.mp3"]}, + "1": {"cls":"animates","id":"yellowWall","canBreak":true,"animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}}}, + "2": {"cls":"animates","id":"whiteWall","canBreak":true,"animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}}}, + "3": {"cls":"animates","id":"blueWall","canBreak":true,"animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}}}, "4": {"cls":"animates","id":"star","name":"星空"}, "5": {"cls":"animates","id":"lava","name":"岩浆"}, "6": {"cls":"terrains","id":"ice"}, @@ -68,12 +68,12 @@ var maps_90f36752_8815_4be8_b32b_d7fad1d0542e = "71": {"cls":"items","id":"shield0"}, "72": {"cls":"items","id":"skill1"}, "73": {"cls":"items","id":"wand"}, - "81": {"cls":"animates","id":"yellowDoor","trigger":"openDoor","animate":1,"doorInfo":[{"yellowKey":1},160,"door.mp3","door.mp3"],"name":"黄门"}, - "82": {"cls":"animates","id":"blueDoor","trigger":"openDoor","animate":1,"doorInfo":[{"blueKey":1},160,"door.mp3","door.mp3"],"name":"蓝门"}, - "83": {"cls":"animates","id":"redDoor","trigger":"openDoor","animate":1,"doorInfo":[{"redKey":1},160,"door.mp3","door.mp3"],"name":"红门"}, - "84": {"cls":"animates","id":"greenDoor","trigger":"openDoor","animate":1,"doorInfo":[{"greenKey":1},160,"door.mp3","door.mp3"],"name":"绿门"}, - "85": {"cls":"animates","id":"specialDoor","trigger":"openDoor","animate":1,"doorInfo":[null,160,"door.mp3","door.mp3"],"name":"机关门"}, - "86": {"cls":"animates","id":"steelDoor","trigger":"openDoor","animate":1,"doorInfo":[{"steelKey":1},160,"door.mp3","door.mp3"],"name":"铁门"}, + "81": {"cls":"animates","id":"yellowDoor","trigger":"openDoor","animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{"yellowKey":1}},"name":"黄门"}, + "82": {"cls":"animates","id":"blueDoor","trigger":"openDoor","animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{"blueKey":1}},"name":"蓝门"}, + "83": {"cls":"animates","id":"redDoor","trigger":"openDoor","animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{"redKey":1}},"name":"红门"}, + "84": {"cls":"animates","id":"greenDoor","trigger":"openDoor","animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{"greenKey":1}},"name":"绿门"}, + "85": {"cls":"animates","id":"specialDoor","trigger":"openDoor","animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{"specialKey":1}},"name":"机关门"}, + "86": {"cls":"animates","id":"steelDoor","trigger":"openDoor","animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{"steelKey":1}},"name":"铁门"}, "87": {"cls":"terrains","id":"upFloor","canPass":true}, "88": {"cls":"terrains","id":"downFloor","canPass":true}, "89": {"cls":"animates","id":"portal","canPass":true}, @@ -86,11 +86,11 @@ var maps_90f36752_8815_4be8_b32b_d7fad1d0542e = "102": {"cls":"animates","id":"crystalBottom"}, "103": {"cls":"animates","id":"fire"}, "104": {"cls":"animates","id":"switch"}, - "105": {"cls":"animates","id":"steelDoor2","doorInfo":[{},"door.mp3","door.mp3"],"animate":1,"trigger":"openDoor"}, - "106": {"cls":"animates","id":"steelDoor3","doorInfo":[{},"door.mp3","door.mp3"],"animate":1,"trigger":"openDoor"}, - "107": {"cls":"animates","id":"iceDoor","doorInfo":[{},"door.mp3","door.mp3"],"animate":1,"trigger":"openDoor"}, - "108": {"cls":"animates","id":"iceDoor2","doorInfo":[{},"door.mp3","door.mp3"],"animate":1,"trigger":"openDoor"}, - "109": {"cls":"animates","id":"magentaWall","canBreak":true,"animate":1,"doorInfo":[null,"door.mp3","door.mp3"]}, + "105": {"cls":"animates","id":"steelDoor2","doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}},"animate":1,"trigger":"openDoor"}, + "106": {"cls":"animates","id":"steelDoor3","doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}},"animate":1,"trigger":"openDoor"}, + "107": {"cls":"animates","id":"iceDoor","doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}},"animate":1,"trigger":"openDoor"}, + "108": {"cls":"animates","id":"iceDoor2","doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}},"animate":1,"trigger":"openDoor"}, + "109": {"cls":"animates","id":"magentaWall","canBreak":true,"animate":1,"doorInfo":{"time":160,"openSound":"door.mp3","closeSound":"door.mp3","keys":{}}}, "121": {"cls":"npcs","id":"man"}, "122": {"cls":"npcs","id":"trader"}, "123": {"cls":"npcs","id":"thief"},