Implemented history state for adding layers

This commit is contained in:
unsettledgames 2020-06-24 12:51:09 +02:00
parent 8201099ad5
commit 74a8ee0988
2 changed files with 18 additions and 3 deletions

View File

@ -27,8 +27,24 @@ function HistoryStateMoveLayer() {
}
function HistoryStateAddLayer() {
//TODO: finisci
function HistoryStateAddLayer(layerData) {
this.added = layerData;
this.undo = function() {
redoStates.push(this);
// un po' brutale onestamente
this.added.selectLayer();
deleteLayer();
};
this.redo = function() {
undoStates.push(this);
addLayer();
};
saveHistoryState(this);
}
//prototype for undoing canvas changes
@ -37,7 +53,6 @@ function HistoryStateEditCanvas () {
this.layerID = currentLayer.id;
this.undo = function () {
console.log("id: " + this.layerID);
var stateLayer = getLayerByID(this.layerID);
var currentCanvas = stateLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
@ -50,7 +65,6 @@ function HistoryStateEditCanvas () {
};
this.redo = function () {
console.log("id: " + this.layerID);
var stateLayer = getLayerByID(this.layerID);
var currentCanvas = stateLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);

View File

@ -518,4 +518,5 @@ function addLayer() {
// Insert it before the Add layer button
layerList.insertBefore(toAppend, layerList.childNodes[0]);
new HistoryStateAddLayer(newLayer);
}