const FileManager = (() => { // Binding the browse holder change event to file loading const browseHolder = document.getElementById('open-image-browse-holder'); Input.on('change', browseHolder, loadFile); function saveProject() { //create name let fileName; let selectedPalette = Util.getText('palette-button'); if (selectedPalette != 'Choose a palette...'){ let paletteAbbreviation = palettes[selectedPalette].abbreviation; fileName = 'pixel-'+paletteAbbreviation+'-'+canvasSize[0]+'x'+canvasSize[1]+'.lpe'; } else { fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]+'.lpe'; selectedPalette = 'none'; } //set download link const linkHolder = document.getElementById('save-project-link-holder'); // create file content const content = getProjectData(); linkHolder.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(content); linkHolder.download = fileName; linkHolder.click(); if (typeof ga !== 'undefined') ga('send', 'event', 'Pixel Editor Save', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/ } function exportProject() { if (documentCreated) { //create name var selectedPalette = Util.getText('palette-button'); if (selectedPalette != 'Choose a palette...'){ var paletteAbbreviation = palettes[selectedPalette].abbreviation; var fileName = 'pixel-'+paletteAbbreviation+'-'+canvasSize[0]+'x'+canvasSize[1]+'.png'; } else { var fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]+'.png'; selectedPalette = 'none'; } //set download link var linkHolder = document.getElementById('save-image-link-holder'); // 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.style.zIndex > b.canvas.style.zIndex) ? 1 : -1); // Merging every layer on the export canvas for (let i=0; i (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1); // save canvas size dictionary['canvasWidth'] = currentLayer.canvasSize[0]; dictionary['canvasHeight'] = currentLayer.canvasSize[1]; // save editor mode dictionary['editorMode'] = pixelEditorMode; // save palette for (let i=0; i