Added undo/redo feature

* new file : HistoryManager.js
* can undo (ctrl-z) and redo (ctrl-y) changes performed through the
tools
* history states are recorded per frame
* a new state is recorder each time a tool is released (introduced
TOOL_RELEASED event for this purpose)
* a duplicated frame doesn't inherit the history states of the original
frame
* there is no limit to the number of states that can be stored per frame
* actions such as creating/duplicating/deleting a frame are not
concerned by this update
This commit is contained in:
juliandescottes
2012-09-07 00:18:59 +02:00
parent 1c12e92ce3
commit 17bf7b3807
5 changed files with 137 additions and 61 deletions

View File

@@ -79,7 +79,8 @@ $.namespace("pskl");
this.animationController.init();
this.previewsController.init();
pskl.HistoryManager.init();
pskl.NotificationService.init();
pskl.LocalStorageService.init(frameSheet);
@@ -154,7 +155,7 @@ $.namespace("pskl");
setActiveFrame: function(index) {
activeFrameIndex = index;
this.drawingController.frame = frameSheet.getFrameByIndex(index);
this.drawingController.frame = this.getCurrentFrame();
},
setActiveFrameAndRedraw: function(index) {
@@ -176,6 +177,10 @@ $.namespace("pskl");
return activeFrameIndex;
},
getCurrentFrame : function () {
return frameSheet.getFrameByIndex(activeFrameIndex);
},
initDrawingArea : function() {
drawingAreaContainer = $('#drawing-canvas-container')[0];
document.body.addEventListener('mouseup', this.onMouseup.bind(this));
@@ -261,6 +266,8 @@ $.namespace("pskl");
if(isRightClicked) {
$.publish(Events.CANVAS_RIGHT_CLICK_RELEASED);
}
isClicked = false;
isRightClicked = false;
var spriteCoordinate = this.getSpriteCoordinate(event);
@@ -271,11 +278,11 @@ $.namespace("pskl");
this.drawingController
);
$.publish(Events.TOOL_RELEASED);
// TODO: Remove that when we have the centralized redraw loop
this.previewsController.createPreviews();
}
},
onCanvasContextMenu : function (event) {