Fixed file loading bug

This commit is contained in:
unsettledgames 2021-07-24 10:25:55 +02:00
parent da7ae65ead
commit 0a774978ef
3 changed files with 9 additions and 10 deletions

View File

@ -347,8 +347,8 @@ const ColorModule = (() => {
*/
function createColorPalette(paletteColors) {
//remove current palette
while (colorsMenu.childCount > 0)
colorsMenu.children[0].parentElement.remove();
while (colorsMenu.childElementCount > 1)
colorsMenu.children[0].remove();
var lightestColor = new Color("hex", '#000000');
var darkestColor = new Color("hex", '#ffffff');
@ -399,7 +399,7 @@ const ColorModule = (() => {
if (!isPixelEmpty(imageData[j])) {
let color = imageData[j]+','+imageData[j + 1]+','+imageData[j + 2];
if (!colors[color]) {
if (!colors[color] && imageData[j + 3] != 0) {
colors[color] = new Color("rgb", imageData[j], imageData[j + 1], imageData[j + 2]).rgb;
//don't allow more than 256 colors to be added
@ -421,6 +421,8 @@ const ColorModule = (() => {
}
}
console.log("palette");
//create palette from colors array
createColorPalette(colorPaletteArray);
}

View File

@ -1,5 +1,3 @@
// TODO: the button to load a palette disappeared for some reason, should add it back
const FileManager = (() => {
// Binding the browse holder change event to file loading
@ -109,9 +107,8 @@ const FileManager = (() => {
// Getting the extension
let extension = (fileName.substring(fileName.lastIndexOf('.')+1, fileName.length) || fileName).toLowerCase();
// I didn't write this check and I have no idea what it does
if (browseHolder.files && browseHolder.files[0]) {
// Btw, checking if the extension is supported
// Checking if the extension is supported
if (extension == 'png' || extension == 'gif' || extension == 'lpe') {
// If it's a Lospec Pixel Editor tm file, I load the project
if (extension == 'lpe') {
@ -130,12 +127,14 @@ const FileManager = (() => {
function openFile() {
//load file
var fileReader = new FileReader();
fileReader.onload = function(e) {
var img = new Image();
img.onload = function() {
//create a new pixel with the images dimentions
EditorState.switchMode('Advanced');
Startup.newPixel(this.width, this.height);
EditorState.switchMode('Advanced');
//draw the image onto the canvas
currentLayer.context.drawImage(img, 0, 0);

View File

@ -9,7 +9,5 @@ if (
(!bowser.mobile && !bowser.tablet)
)
console.log("compatibility check passed");
//show warning
else document.getElementById("compatibility-warning").style.visibility = "visible";