Skip to content

Commit 3dcc517

Browse files
Load pxo files from the Web version - Fixes #820
1 parent 41922c1 commit 3dcc517

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Autoload/HTML5FileExchange.gd

+17-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func _define_js() -> void:
2828
canceled = true;
2929
var input = document.createElement('INPUT');
3030
input.setAttribute("type", "file");
31-
input.setAttribute("accept", "image/png, image/jpeg, image/webp, image/bmp, image/x-tga");
31+
input.setAttribute(
32+
"accept", ".pxo, image/png, image/jpeg, image/webp, image/bmp, image/x-tga"
33+
);
3234
input.click();
3335
input.addEventListener('change', event => {
3436
if (event.target.files.length > 0){
@@ -88,19 +90,19 @@ func load_image(load_directly := true):
8890
return
8991

9092
# Use data from png data
91-
var image_data
93+
var image_data: PoolByteArray
9294
while true:
9395
image_data = JavaScript.eval("fileData;", true)
9496
if image_data != null:
9597
break
9698
yield(get_tree().create_timer(1.0), "timeout") # Need more time to load data
9799

98100
var image_type = JavaScript.eval("fileType;", true)
99-
var image_name = JavaScript.eval("fileName;", true)
101+
var image_name: String = JavaScript.eval("fileName;", true)
100102

101103
var image := Image.new()
102-
var image_error
103-
var image_info: Dictionary = {}
104+
var image_error: int
105+
var image_info := {}
104106
match image_type:
105107
"image/png":
106108
if load_directly:
@@ -122,6 +124,16 @@ func load_image(load_directly := true):
122124
"image/x-tga":
123125
image_error = image.load_tga_from_buffer(image_data)
124126
var invalid_type:
127+
if image_name.get_extension().to_lower() == "pxo":
128+
var temp_file_path := "user://%s" % image_name
129+
var temp_file := File.new()
130+
temp_file.open(temp_file_path, File.WRITE)
131+
temp_file.store_buffer(image_data)
132+
temp_file.close()
133+
OpenSave.open_pxo_file(temp_file_path)
134+
var dir := Directory.new()
135+
dir.remove(temp_file_path)
136+
return
125137
print("Invalid type: " + invalid_type)
126138
return
127139
if image_error:

0 commit comments

Comments
 (0)