Finished implementing editor modes

This commit is contained in:
unsettledgames 2020-07-20 23:33:17 +02:00
parent e9e1ba96da
commit 6be8791dec
8 changed files with 63 additions and 10 deletions

View File

@ -2,7 +2,7 @@ on('click', 'create-button', function (){
var width = getValue('size-width'); var width = getValue('size-width');
var height = getValue('size-height'); var height = getValue('size-height');
var mode = getValue("editor-mode"); var mode = getValue("editor-mode");
newPixel(width,height,'asdfg'); newPixel(width, height, mode);
document.getElementById('new-pixel-warning').style.display = 'block'; document.getElementById('new-pixel-warning').style.display = 'block';
//get selected palette name //get selected palette name

View File

@ -9,6 +9,45 @@ let modes = {
let infoBox = document.getElementById('editor-mode-info'); let infoBox = document.getElementById('editor-mode-info');
function switchMode(currentMode, mustConfirm = true) {
if (currentMode == 'Basic') {
// Switch to advanced ez pez lemon squez
document.getElementById('switch-mode-button').innerHTML = 'Switch to basic mode';
// Show the layer menus
layerList.style.display = "inline-block";
document.getElementById('layer-button').style.display = 'inline-block';
// Move the palette menu
document.getElementById('colors-menu').style.right = '200px';
pixelEditorMode = 'Advanced';
}
else {
// Switch to basic
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);
// Hide the layer menus
layerList.style.display = 'none';
document.getElementById('layer-button').style.display = 'none';
// Move the palette menu
document.getElementById('colors-menu').style.right = '0px';
pixelEditorMode = 'Basic';
}
}
on('click', 'switch-mode-button', function (e) {
switchMode(pixelEditorMode);
});
// Makes the menu open // Makes the menu open
on('click', 'editor-mode-button', function (e){ on('click', 'editor-mode-button', function (e){
//open or close the preset menu //open or close the preset menu

View File

@ -206,18 +206,20 @@ function getProjectData() {
// sorting layers by increasing z-index // sorting layers by increasing z-index
let layersCopy = layers.slice(); let layersCopy = layers.slice();
layersCopy.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1); layersCopy.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1);
// store canvas size // save canvas size
dictionary['canvasWidth'] = currentLayer.canvasSize[0]; dictionary['canvasWidth'] = currentLayer.canvasSize[0];
dictionary['canvasHeight'] = currentLayer.canvasSize[1]; dictionary['canvasHeight'] = currentLayer.canvasSize[1];
// store palette // save editor mode
dictionary['editorMode'] = pixelEditorMode;
// save palette
for (let i=0; i<currentPalette.length; i++) { for (let i=0; i<currentPalette.length; i++) {
dictionary["color" + i] = currentPalette[i]; dictionary["color" + i] = currentPalette[i];
} }
// Store number of layers // save number of layers
dictionary["nLayers"] = layersCopy.length; dictionary["nLayers"] = layersCopy.length;
// store layers // save layers
for (let i=0; i<layersCopy.length; i++) { for (let i=0; i<layersCopy.length; i++) {
// Only saving the layers the user has access to (no vfx, tmp or checkerboard layers) // Only saving the layers the user has access to (no vfx, tmp or checkerboard layers)
if (layersCopy[i].menuEntry != null) { if (layersCopy[i].menuEntry != null) {

View File

@ -329,11 +329,14 @@ function flatten(onlyVisible) {
let nToFlatten = 0; let nToFlatten = 0;
for (let i=0; i<layers.length; i++) { for (let i=0; i<layers.length; i++) {
console.log(layers[i].name);
if (layers[i].menuEntry != null && layers[i].isVisible) { if (layers[i].menuEntry != null && layers[i].isVisible) {
visibleLayers.push(layers[i]); visibleLayers.push(layers[i]);
} }
} }
console.log("da piallare: " + visibleLayers.length);
// Sorting them by z-index // Sorting them by z-index
visibleLayers.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? -1 : 1); visibleLayers.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? -1 : 1);
// Selecting the last visible layer (the only one that won't get deleted) // Selecting the last visible layer (the only one that won't get deleted)

View File

@ -12,7 +12,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
reader.onload = function (e) { reader.onload = function (e) {
let dictionary = JSON.parse(e.target.result); let dictionary = JSON.parse(e.target.result);
newPixel(dictionary['canvasWidth'], dictionary['canvasHeight'], [], dictionary); newPixel(dictionary['canvasWidth'], dictionary['canvasHeight'], dictionary['editorMode'], dictionary);
} }
} }
else { else {
@ -22,7 +22,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
var img = new Image(); var img = new Image();
img.onload = function() { img.onload = function() {
//create a new pixel with the images dimentions //create a new pixel with the images dimentions
newPixel(this.width, this.height, []); newPixel(this.width, this.height, 'Advanced');
//draw the image onto the canvas //draw the image onto the canvas
currentLayer.context.drawImage(img, 0, 0); currentLayer.context.drawImage(img, 0, 0);

View File

@ -1,6 +1,8 @@
let firstPixel = true; let firstPixel = true;
function newPixel (width, height, palette, fileContent = null) { function newPixel (width, height, editorMode, fileContent = null) {
pixelEditorMode = editorMode;
currentPalette = []; currentPalette = [];
if (firstPixel) { if (firstPixel) {
layerList = document.getElementById("layers-menu"); layerList = document.getElementById("layers-menu");
@ -121,7 +123,6 @@ function newPixel (width, height, palette, fileContent = null) {
firstPixel = false; firstPixel = false;
if (fileContent != null) { if (fileContent != null) {
console.log(fileContent);
for (let i=0; i<fileContent['nLayers']; i++) { for (let i=0; i<fileContent['nLayers']; i++) {
let layerData = fileContent['layer' + i]; let layerData = fileContent['layer' + i];
let layerImage = fileContent['layer' + i + 'ImageData']; let layerImage = fileContent['layer' + i + 'ImageData'];
@ -158,4 +159,11 @@ function newPixel (width, height, palette, fileContent = null) {
// Deleting the default layer // Deleting the default layer
deleteLayer(false); deleteLayer(false);
} }
if (pixelEditorMode == 'Basic') {
switchMode('Advanced', false);
}
else {
switchMode('Basic', false);
}
} }

View File

@ -5,7 +5,7 @@ window.onload = function(){
//if the user specified dimentions //if the user specified dimentions
if (specifiedDimentions) if (specifiedDimentions)
//create a new pixel //create a new pixel
newPixel(getValue('size-width'),getValue('size-height'),''); newPixel(getValue('size-width'),getValue('size-height'), getValue('editor-mode'));
else else
//otherwise show the new pixel dialog //otherwise show the new pixel dialog
showDialogue('new-pixel', false); showDialogue('new-pixel', false);

View File

@ -4,6 +4,7 @@ var dragging = false;
var lastPos = [0,0]; var lastPos = [0,0];
var dialogueOpen = false; var dialogueOpen = false;
var documentCreated = false; var documentCreated = false;
var pixelEditorMode;
// Checkerboard management // Checkerboard management
// Checkerboard color 1 // Checkerboard color 1