let firstPixel = true; function newPixel (width, height, editorMode, fileContent = null) { pixelEditorMode = editorMode; currentPalette = []; if (firstPixel) { layerListEntry = layerList.firstElementChild; currentLayer = new Layer(width, height, canvas, layerListEntry); currentLayer.canvas.style.zIndex = 2; } else { let nLayers = layers.length; for (let i=2; i < layers.length - 2; i++) { let currentEntry = layers[i].menuEntry; let associatedLayer; if (currentEntry != null) { // Getting the associated layer associatedLayer = getLayerByID(currentEntry.id); // Deleting its canvas associatedLayer.canvas.remove(); // Adding the id to the unused ones 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(); } //add colors from selected palette var selectedPalette = getText('palette-button'); if (selectedPalette != 'Choose a palette...' && fileContent == null) { //if this palette isnt the one specified in the url, then reset the url if (!palettes[selectedPalette].specified) history.pushState(null, null, '/pixel-editor/app'); //fill the palette with specified palette createColorPalette(palettes[selectedPalette].colors,true); } else if (fileContent == null) { //this wasn't a specified palette, so reset the url history.pushState(null, null, '/pixel-editor/app'); //generate default colors var fg = hslToRgb(Math.floor(Math.random()*255), 230,70); var bg = hslToRgb(Math.floor(Math.random()*255), 230,170); //convert colors to hex var defaultForegroundColor = rgbToHex(fg.r,fg.g,fg.b); var defaultBackgroundColor = rgbToHex(bg.r,bg.g,bg.b); //add colors to palette addColor(defaultForegroundColor).classList.add('selected'); addColor(defaultBackgroundColor); //set current drawing color as foreground color currentLayer.context.fillStyle = '#'+defaultForegroundColor; currentGlobalColor = '#' + defaultForegroundColor; selectedPalette = 'none'; } //fill background of canvas with bg color fillCheckerboard(); //reset undo and redo states undoStates = []; redoStates = []; closeDialogue(); currentTool.updateCursor(); document.getElementById('export-button').classList.remove('disabled'); documentCreated = true; firstPixel = false; if (fileContent != null) { for (let i=0; i