2020-12-31 18:47:56 +03:00
|
|
|
/** Loads a file (.png or .lpe)
|
|
|
|
*
|
|
|
|
*/
|
2019-03-27 02:20:54 +03:00
|
|
|
document.getElementById('open-image-browse-holder').addEventListener('change', function () {
|
2020-06-28 17:57:19 +03:00
|
|
|
let fileName = document.getElementById("open-image-browse-holder").value;
|
2020-12-31 18:47:56 +03:00
|
|
|
// Getting the extension
|
2020-06-28 17:57:19 +03:00
|
|
|
let extension = fileName.substring(fileName.lastIndexOf('.')+1, fileName.length) || fileName;
|
|
|
|
|
2020-12-31 18:47:56 +03:00
|
|
|
// I didn't write this check and I have no idea what it does
|
2020-04-04 10:41:56 +03:00
|
|
|
if (this.files && this.files[0]) {
|
2020-12-31 18:47:56 +03:00
|
|
|
// Btw, checking if the extension is supported
|
2020-06-28 17:57:19 +03:00
|
|
|
if (extension == 'png' || extension == 'gif' || extension == 'lpe') {
|
2020-12-31 18:47:56 +03:00
|
|
|
// If it's a Lospec Pixel Editor tm file, I load the project
|
2020-06-28 17:57:19 +03:00
|
|
|
if (extension == 'lpe') {
|
|
|
|
let file = this.files[0];
|
|
|
|
let reader = new FileReader();
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2020-12-31 18:47:56 +03:00
|
|
|
// Getting all the data
|
2020-06-28 17:57:19 +03:00
|
|
|
reader.readAsText(file, "UTF-8");
|
2020-12-31 18:47:56 +03:00
|
|
|
// Converting the data to a json object and creating a new pixel (see _newPixel.js for more)
|
2020-06-28 17:57:19 +03:00
|
|
|
reader.onload = function (e) {
|
|
|
|
let dictionary = JSON.parse(e.target.result);
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2020-07-21 00:33:17 +03:00
|
|
|
newPixel(dictionary['canvasWidth'], dictionary['canvasHeight'], dictionary['editorMode'], dictionary);
|
2020-06-28 17:57:19 +03:00
|
|
|
}
|
2020-06-27 14:29:28 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//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
|
2020-07-21 00:33:17 +03:00
|
|
|
newPixel(this.width, this.height, 'Advanced');
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2020-06-27 14:29:28 +03:00
|
|
|
//draw the image onto the canvas
|
|
|
|
currentLayer.context.drawImage(img, 0, 0);
|
2020-06-28 17:57:19 +03:00
|
|
|
createPaletteFromLayers();
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2020-06-27 14:29:28 +03:00
|
|
|
//track google event
|
|
|
|
ga('send', 'event', 'Pixel Editor Load', colorPalette.length, this.width+'/'+this.height); /*global ga*/
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2020-06-27 14:29:28 +03:00
|
|
|
};
|
|
|
|
img.src = e.target.result;
|
2020-04-04 10:41:56 +03:00
|
|
|
};
|
2020-06-27 14:29:28 +03:00
|
|
|
fileReader.readAsDataURL(this.files[0]);
|
|
|
|
}
|
2020-04-04 10:41:56 +03:00
|
|
|
}
|
2020-06-27 14:29:28 +03:00
|
|
|
else alert('Only .lpe project files, PNG and GIF files are allowed at this time.');
|
2020-04-04 10:41:56 +03:00
|
|
|
}
|
2020-06-28 17:57:19 +03:00
|
|
|
});
|