drag bg/fg

This commit is contained in:
oc 2019-07-09 16:22:57 +08:00
parent 9491ab9287
commit 83828e57a7
2 changed files with 40 additions and 1 deletions

View File

@ -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;

View File

@ -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;