const Startup = (() => { let splashPostfix = ''; Events.on('click', 'create-button', create, false); Events.on('click', 'create-button-splash', create, true); function create(isSplash) { // If I'm creating from the splash menu, I append '-splash' so I get the corresponding values if (isSplash) splashPostfix = '-splash'; else splashPostfix = ''; var width = Util.getValue('size-width' + splashPostfix); var height = Util.getValue('size-height' + splashPostfix); var selectedPalette = Util.getText('palette-button' + splashPostfix); newPixel(width, height); resetInput(); //track google event if (typeof ga !== 'undefined') ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/ } /** Creates a new, empty file * * @param {*} width Start width of the canvas * @param {*} height Start height of the canvas * @param {*} fileContent If fileContent != null, then the newPixel is being called from the open menu */ function newPixel (width, height, fileContent = null) { // The palette is empty, at the beginning ColorModule.resetPalette(); initLayers(width, height); initPalette(); // Closing the "New Pixel dialogue" Dialogue.closeDialogue(); // Updating the cursor of the current tool ToolManager.currentTool().updateCursor(); // The user is now able to export the Pixel document.getElementById('export-button').classList.remove('disabled'); // Now, if I opened an LPE file if (fileContent != null) { loadFromLPE(fileContent); // Deleting the default layer LayerList.deleteLayer(false); // Selecting the new one currFile.layers[1].selectLayer(); } EditorState.switchMode(EditorState.getCurrentMode()); // This is not the first Pixel anymore EditorState.created(); } function initLayers(width, height) { // Setting the general canvasSize currFile.canvasSize = [width, height]; // If this is the first pixel I'm creating since the app has started if (EditorState.firstPixel()) { // Creating the first layer currFile.currentLayer = new Layer(width, height, 'pixel-canvas', ""); currFile.currentLayer.canvas.style.zIndex = 2; } else { // Deleting all the extra layers and canvases, leaving only one let nLayers = currFile.layers.length; for (let i=2; i < currFile.layers.length - nAppLayers; i++) { let currentEntry = currFile.layers[i].menuEntry; let associatedLayer; if (currentEntry != null) { // Getting the associated layer associatedLayer = LayerList.getLayerByID(currentEntry.id); // Deleting its canvas associatedLayer.canvas.remove(); // Adding the id to the unused ones Layer.unusedIDs.push(currentEntry.id); // Removing the entry from the menu currentEntry.remove(); } } // Removing the old layers from the list for (let i=2; i 0) { colors[0].parentElement.remove(); } // If the user selected a palette and isn't opening a file, I load the selected palette if (selectedPalette != 'Choose a palette...') { if (selectedPalette === 'Loaded palette') { ColorModule.createColorPalette(palettes['Loaded palette'].colors); } else { //if this palette isnt the one specified in the url, then reset the url if (!palettes[selectedPalette].specified) history.pushState(null, null, '/pixel-editor'); //fill the palette with specified colours ColorModule.createColorPalette(palettes[selectedPalette].colors); } } // Otherwise, I just generate 2 semirandom colours else { //this wasn't a specified palette, so reset the url history.pushState(null, null, '/pixel-editor'); //generate default colors var fg = new Color("hsv", Math.floor(Math.random()*360), 50, 50).rgb; var bg = new Color("hsv", Math.floor(Math.random()*360), 80, 100).rgb; //convert colors to hex var defaultForegroundColor = Color.rgbToHex(fg); var defaultBackgroundColor = Color.rgbToHex(bg); //add colors to palette ColorModule.addColor(defaultForegroundColor).classList.add('selected'); ColorModule.addColor(defaultBackgroundColor); //set current drawing color as foreground color ColorModule.updateCurrentColor('#'+defaultForegroundColor); selectedPalette = 'none'; } } function loadFromLPE(fileContent) { // I add every layer the file had in it for (let i=0; i