From 83828e57a7f6d9b0e4b7bdc9067d3dcc405641ca Mon Sep 17 00:00:00 2001 From: oc Date: Tue, 9 Jul 2019 16:22:57 +0800 Subject: [PATCH] drag bg/fg --- _server/editor.js | 36 ++++++++++++++++++++++++++++++++++++ _server/editor_unsorted_1.js | 5 ++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/_server/editor.js b/_server/editor.js index 033187da..cb7490a3 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -556,6 +556,42 @@ editor.prototype.exchangePos = function (startPos, endPos, callback) { }); } +editor.prototype.moveBgFg = function (startPos, endPos, name, callback) { + if (!startPos || !endPos || ["bgmap","fgmap"].indexOf(name)<0) return; + if (startPos.x == endPos.x && startPos.y == endPos.y) return; + editor[name][endPos.y][endPos.x] = editor[name][startPos.y][startPos.x]; + editor[name][startPos.y][startPos.x] = 0; + editor.updateMap(); + editor.file.saveFloorFile(function (err) { + if (err) { + printe(err); + throw(err) + } + ;printf('移动图块成功'); + editor.drawPosSelection(); + if (callback) callback(); + }); +} + +editor.prototype.exchangeBgFg = function (startPos, endPos, name, callback) { + if (!startPos || !endPos || ["bgmap","fgmap"].indexOf(name)<0) return; + if (startPos.x == endPos.x && startPos.y == endPos.y) return; + var value = editor[name][endPos.y][endPos.x]; + editor[name][endPos.y][endPos.x] = editor[name][startPos.y][startPos.x]; + editor[name][startPos.y][startPos.x] = value; + 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 73955ab2..d3b4c5c0 100644 --- a/_server/editor_unsorted_1.js +++ b/_server/editor_unsorted_1.js @@ -209,7 +209,10 @@ editor.constructor.prototype.listen=function () { if (!selectBox.isSelected()) { //tip.whichShow(1); // editor.movePos(startPos, endPos); - editor.exchangePos(startPos, endPos); + if (editor.layerMod == 'map') + editor.exchangePos(startPos, endPos); + else + editor.exchangeBgFg(startPos, endPos, editor.layerMod); startPos = endPos = null; uc.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__); return false;