From 74a8ee09880930c8d003c5310fe978fb46320a7d Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Wed, 24 Jun 2020 12:51:09 +0200 Subject: [PATCH] Implemented history state for adding layers --- js/_history.js | 20 +++++++++++++++++--- js/_layer.js | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/js/_history.js b/js/_history.js index e0597fb..3adb15a 100644 --- a/js/_history.js +++ b/js/_history.js @@ -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]); diff --git a/js/_layer.js b/js/_layer.js index bb77d6d..1c9a840 100644 --- a/js/_layer.js +++ b/js/_layer.js @@ -518,4 +518,5 @@ function addLayer() { // Insert it before the Add layer button layerList.insertBefore(toAppend, layerList.childNodes[0]); + new HistoryStateAddLayer(newLayer); } \ No newline at end of file