From 927be7c310dcb85bc835b1d60c5160ff0a63fe3e Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Tue, 23 Jun 2020 23:10:56 +0200 Subject: [PATCH] Implemented save management HAHA I was joking, I still had to make it save stuff. Ok, now I can only implement the history. It will take ages. --- js/_fileMenu.js | 35 ++++++++++++++++++++++--- js/_layer.js | 54 +++------------------------------------ js/_newPixel.js | 1 - js/_pixelEditorUtility.js | 29 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 55 deletions(-) diff --git a/js/_fileMenu.js b/js/_fileMenu.js index 7f884b4..3183ff4 100644 --- a/js/_fileMenu.js +++ b/js/_fileMenu.js @@ -35,8 +35,6 @@ for (var i = 1; i < mainMenuItems.length; i++) { showDialogue('new-pixel'); break; case 'Open': - - //if a document exists if (documentCreated) { //check if the user wants to overwrite @@ -65,11 +63,42 @@ for (var i = 1; i < mainMenuItems.length; i++) { //set download link var linkHolder = document.getElementById('save-image-link-holder'); - linkHolder.href = canvas.toDataURL(); + // Creating a tmp canvas to flatten everything + var exportCanvas = document.createElement("canvas"); + var emptyCanvas = document.createElement("canvas"); + var layersCopy = layers.slice();; + + exportCanvas.width = canvasSize[0]; + exportCanvas.height = canvasSize[1]; + + emptyCanvas.width = canvasSize[0]; + emptyCanvas.height = canvasSize[1]; + + // Sorting the layers by z index + layersCopy.sort((a, b) => (a.canvas.zIndex > b.canvas.zIndex) ? 1 : -1); + + // Merging every layer on the export canvas + for (let i=0; i (a.canvas.zIndex > b.canvas.zIndex) ? 1 : -1); + visibleLayers.sort((a, b) => (a.canvas.zIndex > b.canvas.zIndex) ? -1 : 1); // Selecting the last visible layer (the only one that won't get deleted) visibleLayers[visibleLayers.length - 1].selectLayer(); // Merging all the layer but the last one for (let i=0; i