From 31048d7d05acc2efcb0eb04fd1c889c64bc6cf19 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 22 Nov 2019 22:47:55 +0800 Subject: [PATCH] enemy:xxx && blockId:x,y --- _server/MotaAction.g4 | 81 ++++++++++++++++++++++++++++++++++++++- _server/editor_blockly.js | 34 +++++++++++++++- libs/utils.js | 6 +++ 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index bcb49afa..38e889d5 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -2593,6 +2593,46 @@ return [code, Blockly.JavaScript.ORDER_ATOMIC]; */; +//这一条不会被antlr识别,总是会被归到idString_e +idString_3_e + : '怪物' IdString '的' EnemyId_List + + +/* idString_3_e +colour : this.idstring_eColor +default : ['greenSlime',"攻击"] +//todo 将其output改成'idString_e' +var code = 'enemy:'+IdString_0+'.'+EnemyId_List_0; +return [code, Blockly.JavaScript.ORDER_ATOMIC]; +*/; + + +//这一条不会被antlr识别,总是会被归到idString_e +idString_4_e + : '图块ID:' Int ',' Int + + +/* idString_4_e +colour : this.idstring_eColor +default : [0,0] +var code = 'blockId:'+Int_0+','+Int_1; +return [code, Blockly.JavaScript.ORDER_ATOMIC]; +*/; + + +//这一条不会被antlr识别,总是会被归到idString_e +idString_5_e + : '图块类别:' Int ',' Int + + +/* idString_5_e +colour : this.idstring_eColor +default : [0,0] +var code = 'blockCls:'+Int_0+','+Int_1; +return [code, Blockly.JavaScript.ORDER_ATOMIC]; +*/; + + evFlag_e : '独立开关' Letter_List @@ -2744,6 +2784,10 @@ Id_List : '变量' | '状态' | '物品' | '独立开关' | '全局存储' /*Id_List ['flag','status','item', 'switch', 'global']*/; +EnemyId_List + : '生命'|'攻击'|'防御'|'金币'|'经验'|'加点'|'属性'|'名称' + /*EnemyId_List ['hp','atk','def','money','experience','point','special','name']*/; + //转blockly后不保留需要加" EvalString : Equote_double (ESC_double | ~["\\])* Equote_double @@ -2804,6 +2848,9 @@ this.evisitor.mapColor=175; delete(this.block('negate_e').inputsInline); this.block('idString_1_e').output='idString_e'; this.block('idString_2_e').output='idString_e'; +this.block('idString_3_e').output='idString_e'; +this.block('idString_4_e').output='idString_e'; +this.block('idString_5_e').output='idString_e'; this.block('evFlag_e').output='idString_e'; */ @@ -3779,7 +3826,7 @@ MotaActionFunctions.pattern.replaceStatusList = [ ["mana", "魔力"], ["money", "金币"], ["experience", "经验"], - ["steps", "步数"] + ["steps", "步数"], ]; MotaActionFunctions.pattern.replaceItemList = [ @@ -3833,6 +3880,17 @@ MotaActionFunctions.pattern.replaceItemList = [ ["jumpShoes", "跳跃靴"], ]; +MotaActionFunctions.pattern.replaceEnemyList = [ + // 保证顺序! + ["name", "名称"], + ["atk", "攻击"], + ["def", "防御"], + ["money", "金币"], + ["experience", "经验"], + ["point", "加点"], + ["special", "属性"], +]; + MotaActionFunctions.disableReplace = false; MotaActionFunctions.replaceToName = function (str) { @@ -3852,6 +3910,16 @@ MotaActionFunctions.replaceToName = function (str) { return map[b] ? ("物品:" + map[b]) : b; }).replace(/item:/g, "物品:"); str = str.replace(/flag:/g, "变量:").replace(/switch:/g, "独立开关:").replace(/global:/g, "全局存储:"); + + map = {}; list = []; + MotaActionFunctions.pattern.replaceEnemyList.forEach(function (v) { + map[v[0]] = v[1]; list.push(v[0]); + }); + str = str.replace(new RegExp("enemy:([a-zA-Z0-9_]+).(" + list.join("|") + ")", "g"), function (a, b, c) { + return map[c] ? ("怪物:" + b + ":" + map[c]) : c; + }).replace(/enemy:/g, "怪物:"); + + str = str.replace(/blockId:/g, "图块ID:").replace(/blockCls:/g, "图块类别:"); return str; } @@ -3872,6 +3940,17 @@ MotaActionFunctions.replaceFromName = function (str) { 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:|怪物[::])([a-zA-Z0-9_]+)[::](" + list.join("|") + ")", "g"), function (a, b, c, d) { + return map[d] ? ("enemy:" + c + ":" + map[d]) : d; + }).replace(/怪物[::]/g, "enemy:"); + + str = str.replace(/图块I[dD][::]/g, "blockId:").replace(/图块类别[::]/g, "blockCls:"); + return str; } diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index ef318e6a..6770e1e4 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -229,6 +229,9 @@ editor_blockly = function () { MotaActionBlocks['idString_e'].xmlText(), MotaActionBlocks['idString_1_e'].xmlText(), MotaActionBlocks['idString_2_e'].xmlText(), + MotaActionBlocks['idString_3_e'].xmlText(), + MotaActionBlocks['idString_4_e'].xmlText(), + MotaActionBlocks['idString_5_e'].xmlText(), MotaActionBlocks['evalString_e'].xmlText(), ], '常见事件模板':[ @@ -910,6 +913,28 @@ function omitedcheckUpdateFunction(event) { return Object.keys(editor.used_flags || {}).filter(function (one) { return one != token && one.startsWith(token); }).sort(); + } else if (before.endsWith("怪物") || (ch == ':' && before.endsWith("enemy"))) { + return Object.keys(core.material.enemys).filter(function (one) { + return one != token && one.startsWith(token); + }) + } else { + var index2 = Math.max(content.lastIndexOf(":", index-1), content.lastIndexOf(":", index-1)); + var ch2 = content.charAt(index2); + if (index2 >= 0) { + before = content.substring(0, index2); + if (before.endsWith("怪物") || (ch == ':' && ch2 == ':' && before.endsWith("enemy"))) { + var list = ["name", "hp", "atk", "def", "money", "experience", "point", "special"]; + if (before.endsWith("怪物") && MotaActionFunctions) { + list = MotaActionFunctions.pattern.replaceEnemyList.map(function (v) { + return v[1]; + }).concat(list); + } + return list.filter(function (one) { + return one != token && one.startsWith(token); + }) + } + } + } } } @@ -1039,7 +1064,7 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { // --- awesomplete var awesomplete = new Awesomplete(htmlInput, { - minChars: 2, + minChars: pb.type == "idString_3_e" ? 1 : 2, maxItems: 12, autoFirst: true, replace: function (text) { @@ -1094,6 +1119,13 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { } var list = editor_blockly.getAutoCompletions(value); + if (pb.type == "idString_3_e") { + list = list.concat(Object.keys(core.material.enemys).filter(function (one) { + return one != value && one.startsWith(value); + })); + list.sort(); + } + awesomplete.list = list; awesomplete.ul.style.marginLeft = getCaretCoordinates(htmlInput, htmlInput.selectionStart).left - htmlInput.scrollLeft - 20 + "px"; diff --git a/libs/utils.js b/libs/utils.js index f3de8a29..d8f811c7 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -81,6 +81,12 @@ utils.prototype.calValue = function (value, prefix, need, times) { value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)"); if (value.indexOf('global:') >= 0) value = value.replace(/global:([a-zA-Z0-9_\u4E00-\u9FCC]+)/g, "core.getGlobal('$1', 0)"); + if (value.indexOf('enemy:')>=0) + value = value.replace(/enemy:([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)/g, "core.material.enemys['$1'].$2"); + if (value.indexOf('blockId:')>=0) + value = value.replace(/blockId:(\d+),(\d+)/g, "core.getBlockId($1, $2)"); + if (value.indexOf('blockCls:')>=0) + value = value.replace(/blockCls:(\d+),(\d+)/g, "core.getBlockCls($1, $2)"); } return eval(value); }