From 017ef3b6f56f3a62dcc1589d85e6cc2203372777 Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Sat, 14 Aug 2021 22:47:49 +0200 Subject: [PATCH] Resolved conflicts with the previous pull request --- js/FileManager.js | 50 ++++-- js/TopMenuModule.js | 4 +- js/_fileMenu.js | 155 ------------------ js/_pixelExport.js | 70 -------- js/_saveProject.js | 39 ----- js/pixel-editor.js | 2 - views/index.hbs | 4 +- .../pixel-export.hbs} | 2 +- .../save-project.hbs} | 0 9 files changed, 41 insertions(+), 285 deletions(-) delete mode 100644 js/_fileMenu.js delete mode 100644 js/_pixelExport.js delete mode 100644 js/_saveProject.js rename views/{pixel-export-popup.hbs => popups/pixel-export.hbs} (85%) rename views/{save-project-popup.hbs => popups/save-project.hbs} (100%) diff --git a/js/FileManager.js b/js/FileManager.js index 194654c..0bbaea1 100644 --- a/js/FileManager.js +++ b/js/FileManager.js @@ -7,19 +7,47 @@ const FileManager = (() => { Events.on('change', browseHolder, loadFile); Events.on('change', browsePaletteHolder, loadPalette); - function saveProject() { + function openSaveProjectWindow() { //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'; + var paletteAbbreviation = palettes[selectedPalette].abbreviation; + var fileName = 'pixel-'+paletteAbbreviation+'-'+canvasSize[0]+'x'+canvasSize[1]; } else { - fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]+'.lpe'; + var fileName = 'pixel-'+canvasSize[0]+'x'+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+'-'+canvasSize[0]+'x'+canvasSize[1]+'.png'; + } else { + var fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]+'.png'; + selectedPalette = 'none'; + } + + Util.setValue('export-file-name', fileName); + + Events.on("click", "export-confirm", exportProject); + + 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 @@ -36,15 +64,7 @@ const FileManager = (() => { function exportProject() { if (Startup.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'; - } - + let fileName = Util.getValue("export-file-name"); //set download link var linkHolder = document.getElementById('save-image-link-holder'); // Creating a tmp canvas to flatten everything @@ -248,6 +268,8 @@ const FileManager = (() => { return { saveProject, exportProject, + openPixelExportWindow, + openSaveProjectWindow, open } })(); \ No newline at end of file diff --git a/js/TopMenuModule.js b/js/TopMenuModule.js index 5f324c2..54338bf 100644 --- a/js/TopMenuModule.js +++ b/js/TopMenuModule.js @@ -32,13 +32,13 @@ const TopMenuModule = (() => { Events.on('click', currSubmenuButton, Dialogue.showDialogue, 'new-pixel'); break; case 'Save project': - Events.on('click', currSubmenuButton, FileManager.saveProject); + Events.on('click', currSubmenuButton, FileManager.openSaveProjectWindow); break; case 'Open': Events.on('click', currSubmenuButton, FileManager.open); break; case 'Export': - Events.on('click', currSubmenuButton, FileManager.exportProject); + Events.on('click', currSubmenuButton, FileManager.openPixelExportWindow); break; case 'Exit': //if a document exists, make sure they want to delete it diff --git a/js/_fileMenu.js b/js/_fileMenu.js deleted file mode 100644 index 5ce18ed..0000000 --- a/js/_fileMenu.js +++ /dev/null @@ -1,155 +0,0 @@ -var mainMenuItems = document.getElementById('main-menu').children; - -//for each button in main menu (starting at 1 to avoid logo) -for (var i = 1; i < mainMenuItems.length; i++) { - - //get the button that's in the list item - var menuItem = mainMenuItems[i]; - var menuButton = menuItem.children[0]; - - //when you click a main menu items button - on('click', menuButton, function (e, button) { - select(button.parentElement); - }); - - var subMenu = menuItem.children[1]; - var subMenuItems = subMenu.children; - - //when you click an item within a menu button - for (var j = 0; j < subMenuItems.length; j++) { - - var subMenuItem = subMenuItems[j]; - var subMenuButton = subMenuItem.children[0]; - - subMenuButton.addEventListener('click', function (e) { - - switch(this.textContent) { - - //File Menu - case 'New': - showDialogue('new-pixel'); - break; - case 'Save project': - openSaveProjectWindow(); - break; - case 'Open': - //if a document exists - if (documentCreated) { - //check if the user wants to overwrite - if (confirm('Opening a pixel will discard your current one. Are you sure you want to do that?')) - //open file selection dialog - document.getElementById('open-image-browse-holder').click(); - } - else - //open file selection dialog - document.getElementById('open-image-browse-holder').click(); - - break; - - case 'Export': - openPixelExportWindow(); - break; - - case 'Exit': - - console.log('exit'); - //if a document exists, make sure they want to delete it - if (documentCreated) { - - //ask user if they want to leave - if (confirm('Exiting will discard your current pixel. Are you sure you want to do that?')) - //skip onbeforeunload prompt - window.onbeforeunload = null; - else - e.preventDefault(); - } - - break; - //Edit Menu - case 'Undo': - undo(); - break; - case 'Redo': - redo(); - break; - - //Palette Menu - case 'Add color': - addColor('#eeeeee'); - break; - // SELECTION MENU - case 'Paste': - pasteSelection(); - break; - case 'Copy': - copySelection(); - tool.pencil.switchTo(); - break; - case 'Cut': - cutSelectionTool(); - tool.pencil.switchTo(); - break; - case 'Cancel': - tool.pencil.switchTo(); - break; - //Help Menu - case 'Settings': - //fill form with current settings values - setValue('setting-numberOfHistoryStates', settings.numberOfHistoryStates); - - showDialogue('settings'); - break; - //Help Menu - case 'Help': - showDialogue('help'); - break; - case 'About': - showDialogue('about'); - break; - case 'Changelog': - showDialogue('changelog'); - break; - } - - closeMenu(); - }); - } -} - -function closeMenu () { - //remove .selected class from all menu buttons - for (var i = 0; i < mainMenuItems.length; i++) { - deselect(mainMenuItems[i]); - } -} - -function getProjectData() { - // use a dictionary - let dictionary = {}; - // sorting layers by increasing z-index - let layersCopy = layers.slice(); - layersCopy.sort((a, b) => (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 (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1); - - // Merging every layer on the export canvas - for (let i=0; i changelog}} {{> credits}} {{> settings}} - {{> pixel-export-popup}} - {{> save-project-popup}} + {{> pixel-export}} + {{> save-project}} diff --git a/views/pixel-export-popup.hbs b/views/popups/pixel-export.hbs similarity index 85% rename from views/pixel-export-popup.hbs rename to views/popups/pixel-export.hbs index 17fa4d3..6642fe7 100644 --- a/views/pixel-export-popup.hbs +++ b/views/popups/pixel-export.hbs @@ -5,7 +5,7 @@

File Name

- +