From 3dcc51705a999145e53a8e6d4de217dc03b0f147 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 30 Jan 2024 21:26:07 +0200 Subject: [PATCH] Load pxo files from the Web version - Fixes #820 --- src/Autoload/HTML5FileExchange.gd | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Autoload/HTML5FileExchange.gd b/src/Autoload/HTML5FileExchange.gd index 963e9c13f7bd..d1c712918f2e 100644 --- a/src/Autoload/HTML5FileExchange.gd +++ b/src/Autoload/HTML5FileExchange.gd @@ -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: