Skip to content

Commit

Permalink
Load pxo files from the Web version - Fixes #820
Browse files Browse the repository at this point in the history
  • Loading branch information
OverloadedOrama committed Jan 30, 2024
1 parent 41922c1 commit 3dcc517
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Autoload/HTML5FileExchange.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -88,19 +90,19 @@ 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:
break
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:
Expand All @@ -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:
Expand Down

0 comments on commit 3dcc517

Please sign in to comment.