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

Load pxo files from the Web version - Fixes #820

This commit is contained in:
Emmanouil Papadeas 2024-01-30 21:17:31 +02:00
parent 1dce3ebe22
commit 63691cacaf

View file

@ -29,7 +29,9 @@ func _define_js() -> void:
canceled = true; canceled = true;
var input = document.createElement('INPUT'); var input = document.createElement('INPUT');
input.setAttribute("type", "file"); 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.click();
input.addEventListener('change', event => { input.addEventListener('change', event => {
if (event.target.files.length > 0){ if (event.target.files.length > 0){
@ -87,19 +89,19 @@ func load_image(load_directly := true):
return return
# Use data from png data # Use data from png data
var image_data var image_data: PackedByteArray
while true: while true:
image_data = JavaScriptBridge.eval("fileData;", true) image_data = JavaScriptBridge.eval("fileData;", true)
if image_data != null: if image_data != null:
break break
await get_tree().create_timer(1.0).timeout # Need more time to load data await get_tree().create_timer(1.0).timeout # Need more time to load data
var image_type = JavaScriptBridge.eval("fileType;", true) var image_type: String = JavaScriptBridge.eval("fileType;", true)
var image_name = JavaScriptBridge.eval("fileName;", true) var image_name: String = JavaScriptBridge.eval("fileName;", true)
var image := Image.new() var image := Image.new()
var image_error var image_error: Error
var image_info: Dictionary = {} var image_info := {}
match image_type: match image_type:
"image/png": "image/png":
if load_directly: if load_directly:
@ -121,6 +123,14 @@ func load_image(load_directly := true):
"image/x-tga": "image/x-tga":
image_error = image.load_tga_from_buffer(image_data) image_error = image.load_tga_from_buffer(image_data)
var invalid_type: var invalid_type:
if image_name.get_extension().to_lower() == "pxo":
var temp_file_path := "user://%s" % image_name
var temp_file := FileAccess.open(temp_file_path, FileAccess.WRITE)
temp_file.store_buffer(image_data)
temp_file.close()
OpenSave.open_pxo_file(temp_file_path)
DirAccess.remove_absolute(temp_file_path)
return
print("Invalid type: " + invalid_type) print("Invalid type: " + invalid_type)
return return
if image_error: if image_error: