fixed a few bugs on layers before first document is created

This commit is contained in:
Sam Keddy 2020-09-09 04:15:22 +00:00
parent 8a769557db
commit 43f5fa8d5c
3 changed files with 44 additions and 28 deletions

View File

@ -10,6 +10,8 @@ let modes = {
let infoBox = document.getElementById('editor-mode-info'); let infoBox = document.getElementById('editor-mode-info');
function switchMode(currentMode, mustConfirm = true) { function switchMode(currentMode, mustConfirm = true) {
//switch to advanced mode
if (currentMode == 'Basic') { if (currentMode == 'Basic') {
// Switch to advanced ez pez lemon squez // Switch to advanced ez pez lemon squez
document.getElementById('switch-mode-button').innerHTML = 'Switch to basic mode'; document.getElementById('switch-mode-button').innerHTML = 'Switch to basic mode';
@ -21,19 +23,30 @@ function switchMode(currentMode, mustConfirm = true) {
pixelEditorMode = 'Advanced'; pixelEditorMode = 'Advanced';
} }
//switch to basic mode
else { else {
// Switch to basic
//if there is a current layer (a document is active)
if (currentLayer) {
//confirm with user before flattening image
if (mustConfirm ) { if (mustConfirm ) {
if (!confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) { if (!confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) {
return; return;
} }
} }
document.getElementById('switch-mode-button').innerHTML = 'Switch to advanced mode';
// Selecting the current layer // Selecting the current layer
currentLayer.selectLayer(); currentLayer.selectLayer();
// Flatten the layers // Flatten the layers
flatten(true); flatten(true);
}
//change menu text
document.getElementById('switch-mode-button').innerHTML = 'Switch to advanced mode';
// Hide the layer menus // Hide the layer menus
layerList.style.display = 'none'; layerList.style.display = 'none';
document.getElementById('layer-button').style.display = 'none'; document.getElementById('layer-button').style.display = 'none';

View File

@ -560,6 +560,8 @@ function addLayer(id, saveHistory = true) {
console.log("Tela creata: " + newCanvas); console.log("Tela creata: " + newCanvas);
if (!layerListEntry) return console.warn('skipping adding layer because no document');
// Clone the default layer // Clone the default layer
let toAppend = layerListEntry.cloneNode(true); let toAppend = layerListEntry.cloneNode(true);
// Setting the default name for the layer // Setting the default name for the layer
@ -588,3 +590,5 @@ function addLayer(id, saveHistory = true) {
return newLayer; return newLayer;
} }
layerList = document.getElementById("layers-menu");

View File

@ -5,7 +5,6 @@ function newPixel (width, height, editorMode, fileContent = null) {
currentPalette = []; currentPalette = [];
if (firstPixel) { if (firstPixel) {
layerList = document.getElementById("layers-menu");
layerListEntry = layerList.firstElementChild; layerListEntry = layerList.firstElementChild;
// Setting up the current layer // Setting up the current layer