mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Finished implementing editor modes
This commit is contained in:
parent
e9e1ba96da
commit
6be8791dec
@ -2,7 +2,7 @@ on('click', 'create-button', function (){
|
||||
var width = getValue('size-width');
|
||||
var height = getValue('size-height');
|
||||
var mode = getValue("editor-mode");
|
||||
newPixel(width,height,'asdfg');
|
||||
newPixel(width, height, mode);
|
||||
document.getElementById('new-pixel-warning').style.display = 'block';
|
||||
|
||||
//get selected palette name
|
||||
|
@ -9,6 +9,45 @@ let modes = {
|
||||
|
||||
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
|
||||
on('click', 'editor-mode-button', function (e){
|
||||
//open or close the preset menu
|
||||
|
@ -206,18 +206,20 @@ function getProjectData() {
|
||||
// sorting layers by increasing z-index
|
||||
let layersCopy = layers.slice();
|
||||
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['canvasHeight'] = currentLayer.canvasSize[1];
|
||||
// store palette
|
||||
// save editor mode
|
||||
dictionary['editorMode'] = pixelEditorMode;
|
||||
// save palette
|
||||
for (let i=0; i<currentPalette.length; i++) {
|
||||
dictionary["color" + i] = currentPalette[i];
|
||||
}
|
||||
|
||||
// Store number of layers
|
||||
// save number of layers
|
||||
dictionary["nLayers"] = layersCopy.length;
|
||||
|
||||
// store layers
|
||||
// save layers
|
||||
for (let i=0; i<layersCopy.length; i++) {
|
||||
// Only saving the layers the user has access to (no vfx, tmp or checkerboard layers)
|
||||
if (layersCopy[i].menuEntry != null) {
|
||||
|
@ -329,11 +329,14 @@ function flatten(onlyVisible) {
|
||||
let nToFlatten = 0;
|
||||
|
||||
for (let i=0; i<layers.length; i++) {
|
||||
console.log(layers[i].name);
|
||||
if (layers[i].menuEntry != null && layers[i].isVisible) {
|
||||
visibleLayers.push(layers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("da piallare: " + visibleLayers.length);
|
||||
|
||||
// Sorting them by z-index
|
||||
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)
|
||||
|
@ -12,7 +12,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
|
||||
reader.onload = function (e) {
|
||||
let dictionary = JSON.parse(e.target.result);
|
||||
|
||||
newPixel(dictionary['canvasWidth'], dictionary['canvasHeight'], [], dictionary);
|
||||
newPixel(dictionary['canvasWidth'], dictionary['canvasHeight'], dictionary['editorMode'], dictionary);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -22,7 +22,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
//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
|
||||
currentLayer.context.drawImage(img, 0, 0);
|
||||
|
@ -1,6 +1,8 @@
|
||||
let firstPixel = true;
|
||||
|
||||
function newPixel (width, height, palette, fileContent = null) {
|
||||
function newPixel (width, height, editorMode, fileContent = null) {
|
||||
pixelEditorMode = editorMode;
|
||||
|
||||
currentPalette = [];
|
||||
if (firstPixel) {
|
||||
layerList = document.getElementById("layers-menu");
|
||||
@ -121,7 +123,6 @@ function newPixel (width, height, palette, fileContent = null) {
|
||||
firstPixel = false;
|
||||
|
||||
if (fileContent != null) {
|
||||
console.log(fileContent);
|
||||
for (let i=0; i<fileContent['nLayers']; i++) {
|
||||
let layerData = fileContent['layer' + i];
|
||||
let layerImage = fileContent['layer' + i + 'ImageData'];
|
||||
@ -158,4 +159,11 @@ function newPixel (width, height, palette, fileContent = null) {
|
||||
// Deleting the default layer
|
||||
deleteLayer(false);
|
||||
}
|
||||
|
||||
if (pixelEditorMode == 'Basic') {
|
||||
switchMode('Advanced', false);
|
||||
}
|
||||
else {
|
||||
switchMode('Basic', false);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ window.onload = function(){
|
||||
//if the user specified dimentions
|
||||
if (specifiedDimentions)
|
||||
//create a new pixel
|
||||
newPixel(getValue('size-width'),getValue('size-height'),'');
|
||||
newPixel(getValue('size-width'),getValue('size-height'), getValue('editor-mode'));
|
||||
else
|
||||
//otherwise show the new pixel dialog
|
||||
showDialogue('new-pixel', false);
|
||||
|
@ -4,6 +4,7 @@ var dragging = false;
|
||||
var lastPos = [0,0];
|
||||
var dialogueOpen = false;
|
||||
var documentCreated = false;
|
||||
var pixelEditorMode;
|
||||
|
||||
// Checkerboard management
|
||||
// Checkerboard color 1
|
||||
|
Loading…
Reference in New Issue
Block a user