mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed file loading bug
This commit is contained in:
parent
da7ae65ead
commit
0a774978ef
@ -347,8 +347,8 @@ const ColorModule = (() => {
|
|||||||
*/
|
*/
|
||||||
function createColorPalette(paletteColors) {
|
function createColorPalette(paletteColors) {
|
||||||
//remove current palette
|
//remove current palette
|
||||||
while (colorsMenu.childCount > 0)
|
while (colorsMenu.childElementCount > 1)
|
||||||
colorsMenu.children[0].parentElement.remove();
|
colorsMenu.children[0].remove();
|
||||||
|
|
||||||
var lightestColor = new Color("hex", '#000000');
|
var lightestColor = new Color("hex", '#000000');
|
||||||
var darkestColor = new Color("hex", '#ffffff');
|
var darkestColor = new Color("hex", '#ffffff');
|
||||||
@ -399,7 +399,7 @@ const ColorModule = (() => {
|
|||||||
if (!isPixelEmpty(imageData[j])) {
|
if (!isPixelEmpty(imageData[j])) {
|
||||||
let color = imageData[j]+','+imageData[j + 1]+','+imageData[j + 2];
|
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;
|
colors[color] = new Color("rgb", imageData[j], imageData[j + 1], imageData[j + 2]).rgb;
|
||||||
|
|
||||||
//don't allow more than 256 colors to be added
|
//don't allow more than 256 colors to be added
|
||||||
@ -421,6 +421,8 @@ const ColorModule = (() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("palette");
|
||||||
|
|
||||||
//create palette from colors array
|
//create palette from colors array
|
||||||
createColorPalette(colorPaletteArray);
|
createColorPalette(colorPaletteArray);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// TODO: the button to load a palette disappeared for some reason, should add it back
|
|
||||||
|
|
||||||
const FileManager = (() => {
|
const FileManager = (() => {
|
||||||
|
|
||||||
// Binding the browse holder change event to file loading
|
// Binding the browse holder change event to file loading
|
||||||
@ -109,9 +107,8 @@ const FileManager = (() => {
|
|||||||
// Getting the extension
|
// Getting the extension
|
||||||
let extension = (fileName.substring(fileName.lastIndexOf('.')+1, fileName.length) || fileName).toLowerCase();
|
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]) {
|
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 (extension == 'png' || extension == 'gif' || extension == 'lpe') {
|
||||||
// If it's a Lospec Pixel Editor tm file, I load the project
|
// If it's a Lospec Pixel Editor tm file, I load the project
|
||||||
if (extension == 'lpe') {
|
if (extension == 'lpe') {
|
||||||
@ -130,12 +127,14 @@ const FileManager = (() => {
|
|||||||
function openFile() {
|
function openFile() {
|
||||||
//load file
|
//load file
|
||||||
var fileReader = new FileReader();
|
var fileReader = new FileReader();
|
||||||
|
|
||||||
fileReader.onload = function(e) {
|
fileReader.onload = function(e) {
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
|
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
//create a new pixel with the images dimentions
|
//create a new pixel with the images dimentions
|
||||||
EditorState.switchMode('Advanced');
|
|
||||||
Startup.newPixel(this.width, this.height);
|
Startup.newPixel(this.width, this.height);
|
||||||
|
EditorState.switchMode('Advanced');
|
||||||
|
|
||||||
//draw the image onto the canvas
|
//draw the image onto the canvas
|
||||||
currentLayer.context.drawImage(img, 0, 0);
|
currentLayer.context.drawImage(img, 0, 0);
|
||||||
|
@ -9,7 +9,5 @@ if (
|
|||||||
(!bowser.mobile && !bowser.tablet)
|
(!bowser.mobile && !bowser.tablet)
|
||||||
)
|
)
|
||||||
console.log("compatibility check passed");
|
console.log("compatibility check passed");
|
||||||
|
|
||||||
|
|
||||||
//show warning
|
//show warning
|
||||||
else document.getElementById("compatibility-warning").style.visibility = "visible";
|
else document.getElementById("compatibility-warning").style.visibility = "visible";
|
||||||
|
Loading…
Reference in New Issue
Block a user