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');
function switchMode(currentMode, mustConfirm = true) {
//switch to advanced mode
if (currentMode == 'Basic') {
// Switch to advanced ez pez lemon squez
document.getElementById('switch-mode-button').innerHTML = 'Switch to basic mode';
@ -21,19 +23,30 @@ function switchMode(currentMode, mustConfirm = true) {
pixelEditorMode = 'Advanced';
}
//switch to basic mode
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 (!confirm('Switching to basic mode will flatten all the visible layers. Are you sure you want to continue?')) {
return;
}
}
document.getElementById('switch-mode-button').innerHTML = 'Switch to advanced mode';
// Selecting the current layer
currentLayer.selectLayer();
// Flatten the layers
flatten(true);
}
//change menu text
document.getElementById('switch-mode-button').innerHTML = 'Switch to advanced mode';
// Hide the layer menus
layerList.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);
if (!layerListEntry) return console.warn('skipping adding layer because no document');
// Clone the default layer
let toAppend = layerListEntry.cloneNode(true);
// Setting the default name for the layer
@ -588,3 +590,5 @@ function addLayer(id, saveHistory = true) {
return newLayer;
}
layerList = document.getElementById("layers-menu");

View File

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