Fixed bug that caused the wrong colour to be modified with jscolor

This commit is contained in:
unsettledgames 2021-07-11 12:53:50 +02:00
parent f5807417ec
commit 1daeb81ef4
2 changed files with 5 additions and 8 deletions

View File

@ -22,7 +22,7 @@ const ColorModule = (() => {
// Changes all of one color to another after being changed from color picker
function colorChanged(colorHexElement) {
console.log("Clicked:");
console.log(colorHexElement);
console.log(colorHexElement.target);
// Get old and new colors from the element
const hexElement = colorHexElement.target;
const hexElementValue = hexElement.value;
@ -31,7 +31,7 @@ const ColorModule = (() => {
//if the color is not a valid hex color, exit this function and do nothing
const newColorHex = hexElementValue.toLowerCase();
if (/^[0-9a-f]{6}$/i.test(newColorHex) == false) return
if (/^[0-9a-f]{6}$/i.test(newColorHex) == false) return;
currentPalette.splice(currentPalette.indexOf("#" + newColor), 1);
newColor.a = 255;
@ -180,13 +180,13 @@ const ColorModule = (() => {
newEditButton = editButtonTemplate.cloneNode(true);
listItem.appendChild(newEditButton);
newEditButton.addEventListener('click', () => {
newEditButton.addEventListener('click', (event) => {
//hide edit button
newEditButton.parentElement.lastChild.classList.add('hidden');
event.target.parentElement.lastChild.classList.add('hidden');
//show jscolor picker, if basic mode is enabled
if (pixelEditorMode == 'Basic')
newEditButton.parentElement.firstChild.jscolor.show();
event.target.parentElement.firstChild.jscolor.show();
else
showDialogue("palette-block", false);
});

View File

@ -318,14 +318,11 @@ 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)