From b75f4754436426bb57aca98ac1ee2017886b29f5 Mon Sep 17 00:00:00 2001 From: oc Date: Fri, 7 Jun 2019 22:41:59 +0800 Subject: [PATCH] exchangePos --- _server/editor.js | 19 +++++++++++++++++++ _server/editor_unsorted_1.js | 17 +++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index 683200a2..3641c236 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -531,6 +531,25 @@ editor.prototype.movePos = function (startPos, endPos, callback) { }); } +editor.prototype.exchangePos = function (startPos, endPos, callback) { + if (!startPos || !endPos) return; + if (startPos.x == endPos.x && startPos.y == endPos.y) return; + var startInfo = editor.copyFromPos(startPos); + var endInfo = editor.copyFromPos(endPos); + editor.pasteToPos(startInfo, endPos); + editor.pasteToPos(endInfo, startPos); + editor.updateMap(); + editor.file.saveFloorFile(function (err) { + if (err) { + printe(err); + throw(err) + } + ;printf('交换事件成功'); + editor.drawPosSelection(); + if (callback) callback(); + }); +} + editor.prototype.clearPos = function (clearPos, pos, callback) { var fields = Object.keys(editor.file.comment._data.floors._data.loc._data); pos = pos || editor.pos; diff --git a/_server/editor_unsorted_1.js b/_server/editor_unsorted_1.js index ef27a102..f8ad9f3e 100644 --- a/_server/editor_unsorted_1.js +++ b/_server/editor_unsorted_1.js @@ -209,7 +209,8 @@ editor.constructor.prototype.listen=function () { eui.onmouseup = function (e) { if (!selectBox.isSelected()) { //tip.whichShow(1); - editor.movePos(startPos, endPos); + // editor.movePos(startPos, endPos); + editor.exchangePos(startPos, endPos); startPos = endPos = null; uc.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); return; @@ -747,19 +748,7 @@ editor.constructor.prototype.listen=function () { editor.preMapData = null; reDo = null; editor_mode.onmode(''); - var now = editor.pos, last = editor.lastRightButtonPos[1]; - if (now.x == last.x && now.y == last.y) return; - editor.pasteToPos(editor.lastCopyedInfo[1], now); - editor.pasteToPos(editor.lastCopyedInfo[0], last); - editor.updateMap(); - editor.file.saveFloorFile(function (err) { - if (err) { - printe(err); - throw(err) - } - ;printf('两位置的事件已互换'); - editor.drawPosSelection(); - }); + editor.exchangePos(editor.pos, editor.lastRightButtonPos[1]); } var clearEvent = document.getElementById('clearEvent');