From cbad40d773d673a91ade6fa36995ed75fa852b8c Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 31 May 2019 19:30:44 +0800 Subject: [PATCH] blockly selectPoint --- _server/MotaAction.g4 | 2 +- _server/editor_blockly.js | 53 +++++++++++++++++++++++++++++++++++++++ editor.html | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 00bb44e8..2d0a5276 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -1087,7 +1087,7 @@ changePos_0_s /* changePos_0_s tooltip : changePos: 当前位置切换 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=changepos%EF%BC%9A%E5%BD%93%E5%89%8D%E4%BD%8D%E7%BD%AE%E5%88%87%E6%8D%A2%E5%8B%87%E5%A3%AB%E8%BD%AC%E5%90%91 -default : ["","",null] +default : ["0","0",null] colour : this.dataColor DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"'); var code = '{"type": "changePos", "loc": ['+PosString_0+','+PosString_1+']'+DirectionEx_List_0+'},\n'; diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index a5244fc6..2fa83442 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -624,6 +624,10 @@ function omitedcheckUpdateFunction(event) { } catch (e) {main.log(e);} return; } + if (b && b.type in selectPointBlocks) { // selectPoint + this.selectPoint(); + return; + } var textStringDict = { 'text_0_s': 'EvalString_0', @@ -728,6 +732,55 @@ function omitedcheckUpdateFunction(event) { return results.length == 0 ? editor_blockly.lastUsedType : results; } + // ------ select point ------ + + // id: [x, y, floorId] + var selectPointBlocks = { + "changeFloor_m": ["Number_0", "Number_1", "IdString_0"], + "jumpHero_s": ["PosString_0", "PosString_1"], + "changeFloor_s": ["PosString_0", "PosString_1", "IdString_0"], + "changePos_0_s": ["PosString_0", "PosString_1"], + "battle_1_s": ["PosString_0", "PosString_1"], + "openDoor_s": ["PosString_0", "PosString_1", "IdString_0"], + "closeDoor_s": ["PosString_0", "PosString_1"], + "show_s": ["EvalString_0", "EvalString_1", "IdString_0"], + "hide_s": ["EvalString_0", "EvalString_1", "IdString_0"], + "setBlock_s": ["PosString_0", "PosString_1"], + "move_s": ["PosString_0", "PosString_1"], + "jump_s": ["PosString_2", "PosString_3"], // 跳跃暂时只考虑终点 + "showBgFgMap_s": ["EvalString_0", "EvalString_1", "IdString_0"], + "hideBgFgMap_s": ["EvalString_0", "EvalString_1", "IdString_0"], + "setBgFgBlock_s": ["PosString_0", "PosString_1", "IdString_0"], + "showFloorImg_s": ["EvalString_0", "EvalString_1", "IdString_0"], + "hideFloorImg_s": ["EvalString_0", "EvalString_1", "IdString_0"], + "trigger_s": ["PosString_0", "PosString_1"], + "insert_2_s": ["PosString_0", "PosString_1", "IdString_0"] + } + + editor_blockly.selectPoint = function () { + var block = Blockly.selected, x_area = null, y_area = null, floor_area = null; + var floorId = editor.currentFloorId, pos = editor.pos, x = pos.x, y = pos.y; + if (block != null && block.type in selectPointBlocks) { + var arr = selectPointBlocks[block.type]; + x_area = arr[0]; + y_area = arr[1]; + floor_area = arr[2]; + var xv = parseInt(block.getFieldValue(x_area)), yv = parseInt(block.getFieldValue(y_area)); + if (!isNaN(xv)) x = xv; + if (!isNaN(yv)) y = yv; + if (floor_area != null) floorId = block.getFieldValue(floor_area) || floorId; + } + uievent.selectPoint(floorId, x, y, floor_area == null, function (fv, xv, yv) { + if (x_area == null || y_area == null) return; + if (floor_area != null) { + if (fv != editor.currentFloorId) block.setFieldValue(fv, floor_area); + else block.setFieldValue("", floor_area); + } + block.setFieldValue(xv, x_area); + block.setFieldValue(yv, y_area); + }); + } + return editor_blockly; } //editor_blockly=editor_blockly(); \ No newline at end of file diff --git a/editor.html b/editor.html index 5926201f..0a0f0d96 100644 --- a/editor.html +++ b/editor.html @@ -211,6 +211,7 @@ +