1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Load pxo files from the Web version - Fixes #820

This commit is contained in:
Emmanouil Papadeas 2024-01-30 21:26:07 +02:00
parent 41922c1261
commit 3dcc51705a

View file

@ -28,7 +28,9 @@ func _define_js() -> void:
canceled = true;
var input = document.createElement('INPUT');
input.setAttribute("type", "file");
input.setAttribute("accept", "image/png, image/jpeg, image/webp, image/bmp, image/x-tga");
input.setAttribute(
"accept", ".pxo, image/png, image/jpeg, image/webp, image/bmp, image/x-tga"
);
input.click();
input.addEventListener('change', event => {
if (event.target.files.length > 0){
@ -88,7 +90,7 @@ func load_image(load_directly := true):
return
# Use data from png data
var image_data
var image_data: PoolByteArray
while true:
image_data = JavaScript.eval("fileData;", true)
if image_data != null:
@ -96,11 +98,11 @@ func load_image(load_directly := true):
yield(get_tree().create_timer(1.0), "timeout") # Need more time to load data
var image_type = JavaScript.eval("fileType;", true)
var image_name = JavaScript.eval("fileName;", true)
var image_name: String = JavaScript.eval("fileName;", true)
var image := Image.new()
var image_error
var image_info: Dictionary = {}
var image_error: int
var image_info := {}
match image_type:
"image/png":
if load_directly:
@ -122,6 +124,16 @@ func load_image(load_directly := true):
"image/x-tga":
image_error = image.load_tga_from_buffer(image_data)
var invalid_type:
if image_name.get_extension().to_lower() == "pxo":
var temp_file_path := "user://%s" % image_name
var temp_file := File.new()
temp_file.open(temp_file_path, File.WRITE)
temp_file.store_buffer(image_data)
temp_file.close()
OpenSave.open_pxo_file(temp_file_path)
var dir := Directory.new()
dir.remove(temp_file_path)
return
print("Invalid type: " + invalid_type)
return
if image_error: