editor multi undo

This commit is contained in:
ckcz123 2019-12-27 14:18:44 +08:00
parent 0f65f03083
commit 1216ae7d96
3 changed files with 54 additions and 49 deletions

View File

@ -56,12 +56,9 @@ function editor() {
startPos:null,
endPos:null,
// 撤销/恢复
currDrawData : {
pos: [],
info: {}
},
reDo : null,
preMapData : null,
preMapData : [],
preMapMax: 10,
postMapData: [],
//
shortcut:{},
copyedInfo : null,
@ -246,7 +243,8 @@ editor.prototype.changeFloor = function (floorId, callback) {
});
editor.currentFloorData[name]=mapArray;
}
editor.uivalues.preMapData = null;
editor.uivalues.preMapData = [];
editor.uivalues.postMapData = [];
editor.uifunctions._extraEvent_bindSpecialDoor_doAction(true);
core.changeFloor(floorId, null, {"x": 0, "y": 0, "direction": "up"}, null, function () {
editor.game.fetchMapFromCore();

View File

@ -206,7 +206,7 @@ editor_mappanel_wrapper = function (editor) {
}
editor.uivalues.holdingPath = 0;
if (editor.uivalues.stepPostfix && editor.uivalues.stepPostfix.length) {
editor.uivalues.preMapData = JSON.parse(JSON.stringify({ map: editor.map, fgmap: editor.fgmap, bgmap: editor.bgmap }));
editor.savePreMap();
if (editor.brushMod !== 'line') {
var x0 = editor.uivalues.stepPostfix[0].x;
var y0 = editor.uivalues.stepPostfix[0].y;
@ -221,9 +221,6 @@ editor_mappanel_wrapper = function (editor) {
}
}
}
editor.uivalues.currDrawData.pos = JSON.parse(JSON.stringify(editor.uivalues.stepPostfix));
editor.uivalues.currDrawData.info = JSON.parse(JSON.stringify(editor.info));
editor.uivalues.reDo = null;
// console.log(editor.uivalues.stepPostfix);
if (editor.brushMod === 'tileset' && core.tilesets.indexOf(editor.info.images) !== -1) {
var imgWidth = ~~(core.material.images.tilesets[editor.info.images].width / 32);
@ -511,8 +508,7 @@ editor_mappanel_wrapper = function (editor) {
editor.uifunctions.copyLoc_click = function (e) {
editor.uifunctions.hideMidMenu();
e.stopPropagation();
editor.uivalues.preMapData = null;
editor.uivalues.reDo = null;
editor.savePreMap();
editor_mode.onmode('');
var now = editor.pos, last = editor.uivalues.lastRightButtonPos[1];
if (now.x == last.x && now.y == last.y) return;
@ -535,8 +531,7 @@ editor_mappanel_wrapper = function (editor) {
editor.uifunctions.moveLoc_click = function (e) {
editor.uifunctions.hideMidMenu();
e.stopPropagation();
editor.uivalues.preMapData = null;
editor.uivalues.reDo = null;
editor.savePreMap();
editor_mode.onmode('');
editor.exchangePos(editor.pos, editor.uivalues.lastRightButtonPos[1]);
}
@ -547,7 +542,6 @@ editor_mappanel_wrapper = function (editor) {
*/
editor.uifunctions.clearEvent_click = function (e) {
e.stopPropagation();
editor.uivalues.reDo = null;
editor.clearPos(false);
}
@ -557,7 +551,6 @@ editor_mappanel_wrapper = function (editor) {
*/
editor.uifunctions.clearLoc_click = function (e) {
e.stopPropagation();
editor.uivalues.reDo = null;
editor.clearPos(true);
}
@ -768,6 +761,21 @@ editor_mappanel_wrapper = function (editor) {
if (callback) callback();
});
}
editor.constructor.prototype.savePreMap = function () {
var dt = {
map: editor.map,
fgmap: editor.fgmap,
bgmap: editor.bgmap,
};
if (editor.uivalues.preMapData.length == 0
|| !core.same(editor.uivalues.preMapData[editor.uivalues.preMapData.length - 1], dt)) {
editor.uivalues.preMapData.push(core.clone(dt));
if (editor.uivalues.preMapData.length > editor.uivalues.preMapMax) {
editor.uivalues.preMapData.shift();
}
}
}
editor.constructor.prototype.moveBgFg = function (startPos, endPos, name, callback) {
if (!startPos || !endPos || ["bgmap","fgmap"].indexOf(name)<0) return;
@ -809,7 +817,7 @@ editor_mappanel_wrapper = function (editor) {
var fields = Object.keys(editor.file.comment._data.floors._data.loc._data);
pos = pos || editor.pos;
editor.uifunctions.hideMidMenu();
editor.uivalues.preMapData = null;
editor.savePreMap();
editor.info = 0;
editor_mode.onmode('');
if (clearPos)

View File

@ -81,14 +81,14 @@ editor_ui_wrapper = function (editor) {
editor.uifunctions.body_shortcut = function (e) {
// UI预览 & 地图选点
if (uievent && uievent.isOpen) {
if (editor.uievent && editor.uievent.isOpen) {
e.preventDefault();
if (e.keyCode == 27) uievent.close();
else if (e.keyCode == 13) uievent.confirm();
else if (e.keyCode == 87) uievent.move(0, -1)
else if (e.keyCode == 65) uievent.move(-1, 0)
else if (e.keyCode == 83) uievent.move(0, 1);
else if (e.keyCode == 68) uievent.move(1, 0);
if (e.keyCode == 27) editor.uievent.close();
else if (e.keyCode == 13) editor.uievent.confirm();
else if (e.keyCode == 87) editor.uievent.move(0, -1)
else if (e.keyCode == 65) editor.uievent.move(-1, 0)
else if (e.keyCode == 83) editor.uievent.move(0, 1);
else if (e.keyCode == 68) editor.uievent.move(1, 0);
return;
}
@ -111,29 +111,6 @@ editor_ui_wrapper = function (editor) {
if (editor_multi.id != "" || editor_blockly.id != "")
return;
//Ctrl+z 撤销上一步undo
if (e.keyCode == 90 && e.ctrlKey && editor.uivalues.preMapData && editor.uivalues.currDrawData.pos.length && selectBox.isSelected()) {
editor.map = JSON.parse(JSON.stringify(editor.uivalues.preMapData.map));
editor.fgmap = JSON.parse(JSON.stringify(editor.uivalues.preMapData.fgmap));
editor.bgmap = JSON.parse(JSON.stringify(editor.uivalues.preMapData.bgmap));
editor.updateMap();
editor.uivalues.reDo = JSON.parse(JSON.stringify(editor.uivalues.currDrawData));
editor.uivalues.currDrawData = { pos: [], info: {} };
editor.uivalues.preMapData = null;
return;
}
//Ctrl+y 重做一步redo
if (e.keyCode == 89 && e.ctrlKey && editor.uivalues.reDo && editor.uivalues.reDo.pos.length && selectBox.isSelected()) {
editor.uivalues.preMapData = JSON.parse(JSON.stringify({ map: editor.map, fgmap: editor.fgmap, bgmap: editor.bgmap }));
for (var j = 0; j < editor.uivalues.reDo.pos.length; j++)
editor.map[editor.uivalues.reDo.pos[j].y][editor.uivalues.reDo.pos[j].x] = JSON.parse(JSON.stringify(editor.uivalues.reDo.info));
editor.updateMap();
editor.uivalues.currDrawData = JSON.parse(JSON.stringify(editor.uivalues.reDo));
editor.uivalues.reDo = null;
return;
}
// PGUP和PGDOWN切换楼层
if (e.keyCode == 33 || e.keyCode == 34) {
e.preventDefault();
@ -151,7 +128,29 @@ editor_ui_wrapper = function (editor) {
var focusElement = document.activeElement;
if (!focusElement || focusElement.tagName.toLowerCase() == 'body'
|| focusElement.id == 'selectFloor') {
|| focusElement.id == 'selectFloor') {
//Ctrl+z 撤销上一步undo
if (e.keyCode == 90 && e.ctrlKey && editor.uivalues.preMapData.length > 0) {
e.preventDefault();
var data = editor.uivalues.preMapData.pop();
editor.map = JSON.parse(JSON.stringify(data.map));
editor.fgmap = JSON.parse(JSON.stringify(data.fgmap));
editor.bgmap = JSON.parse(JSON.stringify(data.bgmap));
editor.uivalues.postMapData.push(data);
return;
}
//Ctrl+y 重做一步redo
if (e.keyCode == 89 && e.ctrlKey && editor.uivalues.postMapData.length > 0) {
e.preventDefault();
var data = editor.uivalues.postMapData.pop();
editor.map = JSON.parse(JSON.stringify(data.map));
editor.fgmap = JSON.parse(JSON.stringify(data.fgmap));
editor.bgmap = JSON.parse(JSON.stringify(data.bgmap));
editor.uivalues.preMapData.push(data);
return;
}
// Ctrl+C, Ctrl+X, Ctrl+V
if (e.ctrlKey && e.keyCode == 67 && !selectBox.isSelected()) {
e.preventDefault();