From 3d2e0c06bb500f7eccff8619e3120d5aa3ec19e4 Mon Sep 17 00:00:00 2001 From: oc Date: Wed, 12 Dec 2018 23:07:38 +0800 Subject: [PATCH] Fix Ctrl+Z --- _server/editor.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index f83e68b4..c9622e6f 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -235,6 +235,7 @@ editor.prototype.changeFloor = function (floorId, callback) { }); editor.currentFloorData[name]=mapArray; } + editor.preMapData = null; core.changeFloor(floorId, null, {"x": 0, "y": 0, "direction": "up"}, null, function () { core.bigmap.offsetX=0; core.bigmap.offsetY=0; @@ -728,7 +729,7 @@ editor.prototype.listen = function () { holdingPath = 0; e.stopPropagation(); if (stepPostfix && stepPostfix.length) { - preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); + editor.preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); if(editor.brushMod!=='line'){ var x0=stepPostfix[0].x; var y0=stepPostfix[0].y; @@ -822,7 +823,7 @@ editor.prototype.listen = function () { } } - var preMapData = {}; + editor.preMapData = null; var currDrawData = { pos: [], info: {} @@ -836,18 +837,18 @@ editor.prototype.listen = function () { if (e.altKey && [48, 49, 50, 51, 52, 53, 54, 55, 56, 57].indexOf(e.keyCode) !== -1) e.preventDefault(); //Ctrl+z 撤销上一步undo - if (e.keyCode == 90 && e.ctrlKey && preMapData && currDrawData.pos.length && selectBox.isSelected) { - editor.map = JSON.parse(JSON.stringify(preMapData.map)); - editor.fgmap = JSON.parse(JSON.stringify(preMapData.fgmap)); - editor.bgmap = JSON.parse(JSON.stringify(preMapData.bgmap)); + if (e.keyCode == 90 && e.ctrlKey && editor.preMapData && currDrawData.pos.length && selectBox.isSelected) { + editor.map = JSON.parse(JSON.stringify(editor.preMapData.map)); + editor.fgmap = JSON.parse(JSON.stringify(editor.preMapData.fgmap)); + editor.bgmap = JSON.parse(JSON.stringify(editor.preMapData.bgmap)); editor.updateMap(); reDo = JSON.parse(JSON.stringify(currDrawData)); currDrawData = {pos: [], info: {}}; - preMapData = null; + editor.preMapData = null; } //Ctrl+y 重做一步redo if (e.keyCode == 89 && e.ctrlKey && reDo && reDo.pos.length && selectBox.isSelected) { - preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); + editor.preMapData = JSON.parse(JSON.stringify({map:editor.map,fgmap:editor.fgmap,bgmap:editor.bgmap})); for (var j = 0; j < reDo.pos.length; j++) editor.map[reDo.pos[j].y][reDo.pos[j].x] = JSON.parse(JSON.stringify(reDo.info)); @@ -1027,7 +1028,7 @@ editor.prototype.listen = function () { copyLoc.onmousedown = function(e){ editor.hideMidMenu(); e.stopPropagation(); - preMapData = null; + editor.preMapData = null; reDo = null; editor_mode.onmode(''); var now = editor.pos; @@ -1060,7 +1061,7 @@ editor.prototype.listen = function () { moveLoc.onmousedown = function(e){ editor.hideMidMenu(); e.stopPropagation(); - preMapData = null; + editor.preMapData = null; reDo = null; var thisevent = editor.map[editor.pos.y][editor.pos.x]; if(thisevent==0){ @@ -1106,7 +1107,7 @@ editor.prototype.listen = function () { clearLoc.onmousedown = function(e){ editor.hideMidMenu(); e.stopPropagation(); - preMapData = null; + editor.preMapData = null; reDo = null; editor.info = 0; editor_mode.onmode('');