mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Started commenting code
This commit is contained in:
@ -1,16 +1,32 @@
|
||||
let firstPixel = true;
|
||||
|
||||
/** Creates a new, empty file
|
||||
*
|
||||
* @param {*} width Start width of the canvas
|
||||
* @param {*} height Start height of the canvas
|
||||
* @param {*} editorMode The editor mode chosen by the user (advanced or basic)
|
||||
* @param {*} fileContent If fileContent != null, then the newPixel is being called from the open menu
|
||||
*/
|
||||
function newPixel (width, height, editorMode, fileContent = null) {
|
||||
// Saving the editor mode
|
||||
pixelEditorMode = editorMode;
|
||||
|
||||
// The palette is empty, at the beginning
|
||||
currentPalette = [];
|
||||
|
||||
// If this is the first pixel I'm creating since the app has started
|
||||
if (firstPixel) {
|
||||
// I configure the layers elements
|
||||
layerListEntry = layerList.firstElementChild;
|
||||
|
||||
// Creating the first layer
|
||||
currentLayer = new Layer(width, height, canvas, layerListEntry);
|
||||
currentLayer.canvas.style.zIndex = 2;
|
||||
}
|
||||
else {
|
||||
// If it's not the first Pixel, I have to reset the app
|
||||
|
||||
// Deleting all the extra layers and canvases, leaving only one
|
||||
let nLayers = layers.length;
|
||||
for (let i=2; i < layers.length - nAppLayers; i++) {
|
||||
let currentEntry = layers[i].menuEntry;
|
||||
@ -38,10 +54,9 @@ function newPixel (width, height, editorMode, fileContent = null) {
|
||||
// Setting up the current layer
|
||||
layers[1] = new Layer(width, height, layers[1].canvas, layers[1].menuEntry);
|
||||
currentLayer = layers[1];
|
||||
|
||||
currentLayer.canvas.style.zIndex = 2;
|
||||
|
||||
// Updating canvas size
|
||||
// Updating canvas size to the new size
|
||||
for (let i=0; i<nLayers; i++) {
|
||||
layers[i].canvasSize = [width, height];
|
||||
}
|
||||
@ -58,7 +73,7 @@ function newPixel (width, height, editorMode, fileContent = null) {
|
||||
|
||||
// Pixel grid
|
||||
pixelGrid = new Layer(width, height, pixelGridCanvas);
|
||||
|
||||
// Setting the general canvasSize
|
||||
canvasSize = currentLayer.canvasSize;
|
||||
|
||||
if (firstPixel) {
|
||||
@ -81,15 +96,18 @@ function newPixel (width, height, editorMode, fileContent = null) {
|
||||
|
||||
//add colors from selected palette
|
||||
var selectedPalette = getText('palette-button');
|
||||
|
||||
// If the user selected a palette and isn't opening a file, I load the selected palette
|
||||
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
|
||||
//fill the palette with specified colours
|
||||
createColorPalette(palettes[selectedPalette].colors,true);
|
||||
}
|
||||
// Otherwise, I just generate 2 semirandom colours
|
||||
else if (fileContent == null) {
|
||||
//this wasn't a specified palette, so reset the url
|
||||
history.pushState(null, null, '/pixel-editor/app');
|
||||
@ -120,15 +138,21 @@ function newPixel (width, height, editorMode, fileContent = null) {
|
||||
undoStates = [];
|
||||
redoStates = [];
|
||||
|
||||
// Closing the "New Pixel dialogue"
|
||||
closeDialogue();
|
||||
// Updating the cursor of the current tool
|
||||
currentTool.updateCursor();
|
||||
|
||||
// The user is now able to export the Pixel
|
||||
document.getElementById('export-button').classList.remove('disabled');
|
||||
documentCreated = true;
|
||||
|
||||
// This is not the first Pixel anymore
|
||||
firstPixel = false;
|
||||
|
||||
// Now, if I opened a file
|
||||
if (fileContent != null) {
|
||||
// I add every layer the file had in it
|
||||
for (let i=0; i<fileContent['nLayers']; i++) {
|
||||
let layerData = fileContent['layer' + i];
|
||||
let layerImage = fileContent['layer' + i + 'ImageData'];
|
||||
@ -166,6 +190,7 @@ function newPixel (width, height, editorMode, fileContent = null) {
|
||||
deleteLayer(false);
|
||||
}
|
||||
|
||||
// Applying the correct editor mode
|
||||
if (pixelEditorMode == 'Basic') {
|
||||
switchMode('Advanced', false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user