const FileManager = (() => { // Binding the browse holder change event to file loading const browseHolder = document.getElementById('open-image-browse-holder'); const browsePaletteHolder = document.getElementById('load-palette-browse-holder'); Events.on('change', browseHolder, loadFile); Events.on('change', browsePaletteHolder, loadPalette); Events.on('click', 'export-confirm', exportProject); function openSaveProjectWindow() { //create name let selectedPalette = Util.getText('palette-button'); if (selectedPalette != 'Choose a palette...'){ var paletteAbbreviation = palettes[selectedPalette].abbreviation; var fileName = 'pixel-'+paletteAbbreviation+'-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]; } else { var fileName = 'pixel-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]; selectedPalette = 'none'; } Util.setValue('lpe-file-name', fileName); Events.on("click", "save-project-confirm", saveProject); Dialogue.showDialogue('save-project', false); } function openPixelExportWindow() { let selectedPalette = Util.getText('palette-button'); if (selectedPalette != 'Choose a palette...'){ var paletteAbbreviation = palettes[selectedPalette].name; var fileName = 'pixel-'+paletteAbbreviation+'-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]+'.png'; } else { var fileName = 'pixel-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]+'.png'; selectedPalette = 'none'; } Util.setValue('export-file-name', fileName); Dialogue.showDialogue('export', false); } function saveProject() { // Get name let fileName = Util.getValue("lpe-file-name") + ".lpe"; let selectedPalette = Util.getText('palette-button'); //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, currFile.canvasSize[0]+'/'+currFile.canvasSize[1]); /*global ga*/ } function exportProject() { if (EditorState.documentCreated()) { //create name let fileName = Util.getValue("export-file-name"); //set download link let linkHolder = document.getElementById('save-image-link-holder'); // Creating a tmp canvas to flatten everything let exportCanvas = document.createElement("canvas"); let emptyCanvas = document.createElement("canvas"); let layersCopy = currFile.layers.slice(); exportCanvas.width = currFile.canvasSize[0]; exportCanvas.height = currFile.canvasSize[1]; emptyCanvas.width = currFile.canvasSize[0]; emptyCanvas.height = currFile.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'] = currFile.canvasSize[0]; dictionary['canvasHeight'] = currFile.canvasSize[1]; // save editor mode dictionary['editorMode'] = EditorState.getCurrentMode(); // save palette for (let i=0; i