mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Implemented history state for merging layers
This commit is contained in:
parent
364b5d2652
commit
17a2fe8318
@ -11,8 +11,33 @@ function HistoryStateFlattenAll() {
|
|||||||
// undo the merge for the number of layers that have been flattened
|
// undo the merge for the number of layers that have been flattened
|
||||||
}
|
}
|
||||||
|
|
||||||
function HistoryStateMergeLayer() {
|
function HistoryStateMergeLayer(aboveIndex, aboveLayer, belowData, belowLayer) {
|
||||||
|
this.aboveIndex = aboveIndex;
|
||||||
|
this.belowData = belowData;
|
||||||
|
this.aboveLayer = aboveLayer;
|
||||||
|
this.belowLayer = belowLayer;
|
||||||
// todo
|
// todo
|
||||||
|
this.undo = function() {
|
||||||
|
layerList.insertBefore(this.aboveLayer.menuEntry, this.belowLayer.menuEntry);
|
||||||
|
canvasView.append(this.aboveLayer.canvas);
|
||||||
|
|
||||||
|
belowLayer.context.clearRect(0, 0, this.belowLayer.canvasSize[0], this.belowLayer.canvasSize[1]);
|
||||||
|
belowLayer.context.putImageData(this.belowData, 0, 0);
|
||||||
|
belowLayer.updateLayerPreview();
|
||||||
|
|
||||||
|
layers.splice(this.aboveIndex, 0, this.aboveLayer);
|
||||||
|
|
||||||
|
redoStates.push(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.redo = function() {
|
||||||
|
aboveLayer.selectLayer();
|
||||||
|
merge(false);
|
||||||
|
|
||||||
|
undoStates.push(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
saveHistoryState(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
function HistoryStateRenameLayer(oldName, newName, layer) {
|
function HistoryStateRenameLayer(oldName, newName, layer) {
|
||||||
|
23
js/_layer.js
23
js/_layer.js
@ -1,18 +1,13 @@
|
|||||||
/** TODO LIST FOR LAYERS
|
/** TODO LIST FOR LAYERS
|
||||||
|
|
||||||
GENERAL REQUIREMENTS:
|
GENERAL REQUIREMENTS:
|
||||||
- When saving an artwork, the layers must be flattened to a temporary layer, which is then exported and deleted
|
|
||||||
- Saving the state of an artwork to a .lospec file so that people can work on it later keeping
|
- Saving the state of an artwork to a .lospec file so that people can work on it later keeping
|
||||||
the layers they created? That'd be cool, even for the app users, that could just double click on a lospec
|
the layers they created? That'd be cool, even for the app users, that could just double click on a lospec
|
||||||
file for it to be opened right in the pixel editor
|
file for it to be opened right in the pixel editor
|
||||||
|
|
||||||
HISTORY:
|
HISTORY:
|
||||||
- Store states for every canvas
|
|
||||||
- Save add layer
|
|
||||||
- Save deleted layer
|
|
||||||
- Save merge layers
|
- Save merge layers
|
||||||
- Save flatten layers
|
- Save flatten layers
|
||||||
- Save move layers
|
|
||||||
|
|
||||||
OPTIONAL:
|
OPTIONAL:
|
||||||
|
|
||||||
@ -23,7 +18,6 @@
|
|||||||
THINGS TO TEST:
|
THINGS TO TEST:
|
||||||
|
|
||||||
1 - Undo / redo
|
1 - Undo / redo
|
||||||
4 - File export
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -33,14 +27,8 @@
|
|||||||
- Resize sprite
|
- Resize sprite
|
||||||
- Refactor the code so that every instance of "canvas" and "context" is replaced by currentLayer.canvas
|
- Refactor the code so that every instance of "canvas" and "context" is replaced by currentLayer.canvas
|
||||||
and currentLayer.context
|
and currentLayer.context
|
||||||
- Refactor and replace the merge layer algorithm with a general function in _pixelEditorUtility.js
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Instead of saving the whole entry, just save their IDs and swap the elements at the end of the drop
|
|
||||||
// TODO: add id management. IDs are assigned incrementally, when a layer is deleted its id should be
|
|
||||||
// claimable by the new layers: add a queue to push the ids of the deleted layers to
|
|
||||||
|
|
||||||
|
|
||||||
let layerList;
|
let layerList;
|
||||||
let layerListEntry;
|
let layerListEntry;
|
||||||
|
|
||||||
@ -377,21 +365,24 @@ function flatten(onlyVisible) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function merge(event) {
|
function merge(saveHistory = true) {
|
||||||
// Saving the layer that should be merged
|
// Saving the layer that should be merged
|
||||||
let toMerge = currentLayer;
|
let toMerge = currentLayer;
|
||||||
let toMergeIndex = layers.indexOf(toMerge);
|
let toMergeIndex = layers.indexOf(toMerge);
|
||||||
// Getting layer below
|
// Getting layer below
|
||||||
let layerBelow = getLayerByID(currentLayer.menuEntry.nextElementSibling.id);
|
let layerBelow = getLayerByID(currentLayer.menuEntry.nextElementSibling.id);
|
||||||
|
|
||||||
console.log("YEEEEUUE");
|
|
||||||
console.log(layerBelow);
|
|
||||||
|
|
||||||
// If I have something to merge with
|
// If I have something to merge with
|
||||||
if (layerBelow != null) {
|
if (layerBelow != null) {
|
||||||
// Selecting that layer
|
// Selecting that layer
|
||||||
layerBelow.selectLayer();
|
layerBelow.selectLayer();
|
||||||
|
|
||||||
|
if (saveHistory) {
|
||||||
|
new HistoryStateMergeLayer(toMergeIndex, toMerge,
|
||||||
|
layerBelow.context.getImageData(0, 0, layerBelow.canvasSize[0], layerBelow.canvasSize[1]),
|
||||||
|
layerBelow);
|
||||||
|
}
|
||||||
|
|
||||||
mergeLayers(currentLayer.context, toMerge.context);
|
mergeLayers(currentLayer.context, toMerge.context);
|
||||||
|
|
||||||
// Deleting the above layer
|
// Deleting the above layer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user