Fixed a horrible bug that happened when moving layers

This commit is contained in:
unsettledgames 2020-06-20 23:50:57 +02:00
parent d9d1406d57
commit 349a4417d8
3 changed files with 20 additions and 30 deletions

View File

@ -10,9 +10,6 @@ function fillCheckerboard() {
var context = checkerBoard.context; var context = checkerBoard.context;
context.clearRect(0, 0, canvasSize[0], canvasSize[1]); context.clearRect(0, 0, canvasSize[0], canvasSize[1]);
console.log(canvasSize);
console.log(checkerBoardSquareSize);
// Cycling through the canvas (using it as a matrix) // Cycling through the canvas (using it as a matrix)
for (var i=0; i<canvasSize[0] / checkerBoardSquareSize; i++) { for (var i=0; i<canvasSize[0] / checkerBoardSquareSize; i++) {
nSquaresFilled = 0; nSquaresFilled = 0;

View File

@ -183,7 +183,6 @@ class Layer {
} }
layerDragDrop(element) { layerDragDrop(element) {
console.log("Elemento: " + element.dataTransfer.getData('text/html'));
if (element.stopPropagation) { if (element.stopPropagation) {
element.stopPropagation(); // Stops some browsers from redirecting. element.stopPropagation(); // Stops some browsers from redirecting.
} }
@ -193,7 +192,6 @@ class Layer {
let toDropID = element.dataTransfer.getData('text/html'); let toDropID = element.dataTransfer.getData('text/html');
let thisID = this.id; let thisID = this.id;
console.log("ID di quello spostato: " + toDropID + ", di quello su cui metterlo: " + thisID);
swapLayerEntries(toDropID, thisID); swapLayerEntries(toDropID, thisID);
} }
@ -204,7 +202,6 @@ class Layer {
} }
layerDragEnd(element) { layerDragEnd(element) {
console.log(currentLayer);
this.classList.remove('layerdragover'); this.classList.remove('layerdragover');
} }
@ -237,18 +234,14 @@ class Layer {
toggleLock() { toggleLock() {
if (this.isLocked) { if (this.isLocked) {
console.log("unlocked");
this.unlock(); this.unlock();
} }
else { else {
console.log("locked");
this.lock(); this.lock();
} }
} }
toggleVisibility() { toggleVisibility() {
console.log(this);
if (this.isVisible) { if (this.isVisible) {
this.hide(); this.hide();
} }
@ -330,11 +323,8 @@ function swapLayerEntries(id1, id2) {
let entry1 = document.getElementById(id1); let entry1 = document.getElementById(id1);
let entry2 = document.getElementById(id2); let entry2 = document.getElementById(id2);
console.log("id1: " + id1); console.log("entry 1: " + id1);
console.log("id2: " + id2); console.log("entry 2: " + id2);
console.log("entry1: " + entry1);
console.log("entry2: " + entry2);
let layer1 = getLayerByID(id1); let layer1 = getLayerByID(id1);
let layer2 = getLayerByID(id2); let layer2 = getLayerByID(id2);
@ -343,19 +333,30 @@ function swapLayerEntries(id1, id2) {
let after2 = entry2.nextSibling; let after2 = entry2.nextSibling;
let parent = entry1.parentNode; let parent = entry1.parentNode;
console.log("prima: " + layer1.canvas.style.zIndex);
console.log("prima: " + layer2.canvas.style.zIndex);
tmpZIndex = layer1.canvas.style.zIndex;
layer1.canvas.style.zIndex = layer2.canvas.style.zIndex;
layer2.canvas.style.zIndex = tmpZIndex;
console.log("fatto");
parent.insertBefore(entry2, entry1); parent.insertBefore(entry2, entry1);
if (after2) { if (after2) {
parent.insertBefore(entry1, after2); if (after2 == entry1) {
parent.prepend(entry1);
}
else {
parent.insertBefore(entry1, after2);
}
} else { } else {
parent.appendChild(entry1); parent.appendChild(entry1);
} }
tmpZIndex = layer1.canvas.style.zIndex; console.log("dopo: " + layer1.canvas.style.zIndex);
console.log("1: " + layer1.canvas.style.zIndex); console.log("dopo: " + layer2.canvas.style.zIndex);
console.log("2: " + layer2.canvas.style.zIndex);
layer1.canvas.style.zIndex = layer2.canvas.style.zIndex;
layer2.canvas.style.zIndex = tmpZIndex;
} }
// Finds a layer given its name // Finds a layer given its name

View File

@ -36,8 +36,6 @@ window.addEventListener("mousedown", function (mouseEvent) {
currentTool.updateCursor(); currentTool.updateCursor();
console.log(currentLayer.isLocked);
if (!currentLayer.isLocked && canDraw) { if (!currentLayer.isLocked && canDraw) {
draw(mouseEvent); draw(mouseEvent);
} }
@ -47,7 +45,6 @@ window.addEventListener("mousedown", function (mouseEvent) {
tool.pencil.previousBrushSize = tool.pencil.brushSize; tool.pencil.previousBrushSize = tool.pencil.brushSize;
} }
else if (currentTool.name == 'eraser' && mouseEvent.which == 3) { else if (currentTool.name == 'eraser' && mouseEvent.which == 3) {
console.log('resize eraser')
currentTool = tool.resizeeraser; currentTool = tool.resizeeraser;
tool.eraser.previousBrushSize = tool.eraser.brushSize; tool.eraser.previousBrushSize = tool.eraser.brushSize;
} }
@ -87,12 +84,9 @@ window.addEventListener("mouseup", function (mouseEvent) {
var colors = document.getElementsByClassName('color-button'); var colors = document.getElementsByClassName('color-button');
for (var i = 0; i < colors.length; i++) { for (var i = 0; i < colors.length; i++) {
console.log(colors[i].jscolor.toString());
//if picked color matches this color //if picked color matches this color
if (newColor == colors[i].jscolor.toString()) { if (newColor == colors[i].jscolor.toString()) {
console.log('color found');
//remove current color selection //remove current color selection
var selectedColor = document.querySelector("#colors-menu li.selected") var selectedColor = document.querySelector("#colors-menu li.selected")
if (selectedColor) selectedColor.classList.remove("selected"); if (selectedColor) selectedColor.classList.remove("selected");
@ -111,7 +105,6 @@ window.addEventListener("mouseup", function (mouseEvent) {
} }
} }
else if (currentTool.name == 'fill' && mouseEvent.target.className == 'drawingCanvas') { else if (currentTool.name == 'fill' && mouseEvent.target.className == 'drawingCanvas') {
//console.log('filling')
//get cursor postion //get cursor postion
var cursorLocation = getCursorPosition(mouseEvent); var cursorLocation = getCursorPosition(mouseEvent);
@ -341,7 +334,6 @@ function draw (mouseEvent) {
else if (currentTool.name == 'rectselect') { else if (currentTool.name == 'rectselect') {
if (dragging && !isRectSelecting && mouseEvent.target.className == 'drawingCanvas') { if (dragging && !isRectSelecting && mouseEvent.target.className == 'drawingCanvas') {
isRectSelecting = true; isRectSelecting = true;
console.log("cominciata selezione su " + mouseEvent.target.className);
startRectSelection(mouseEvent); startRectSelection(mouseEvent);
} }
else if (dragging && isRectSelecting) { else if (dragging && isRectSelecting) {