diff --git a/src/Autoload/Export.gd b/src/Autoload/Export.gd index e650b4fec..73258a6d7 100644 --- a/src/Autoload/Export.gd +++ b/src/Autoload/Export.gd @@ -185,7 +185,7 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo else: for i in range(processed_images.size()): if OS.get_name() == "HTML5": - Html5FileExchange.save_image(processed_images[i], export_paths[i].get_file()) + JavaScript.download_buffer(processed_images[i].save_png_to_buffer(), export_paths[i].get_file(), "image/png") else: var err = processed_images[i].save_png(export_paths[i]) if err != OK: @@ -228,7 +228,7 @@ func export_gif(args: Dictionary) -> void: write_frame_to_gif(processed_images[i], Global.current_project.frames[i].duration * (1 / Global.current_project.fps), exporter, args["export_dialog"]) if OS.get_name() == "HTML5": - Html5FileExchange.save_gif(exporter.export_file_data(), args["export_paths"][0]) + JavaScript.download_buffer(exporter.export_file_data(), args["export_paths"][0], "image/gif") else: var file: File = File.new() diff --git a/src/Autoload/HTML5FileExchange.gd b/src/Autoload/HTML5FileExchange.gd index 1d5274e31..332248b1a 100644 --- a/src/Autoload/HTML5FileExchange.gd +++ b/src/Autoload/HTML5FileExchange.gd @@ -90,14 +90,6 @@ func _define_js() -> void: } }); } - function download(fileName, byte, type) { - var buffer = Uint8Array.from(byte); - var blob = new Blob([buffer], { type: type}); - var link = document.createElement('a'); - link.href = window.URL.createObjectURL(blob); - link.download = fileName; - link.click(); - }; """, true) @@ -193,21 +185,6 @@ func load_palette() -> void: return -func save_image(image : Image, file_name : String = "export") -> void: - if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'): - return - - var png_data = Array(image.save_png_to_buffer()) - JavaScript.eval("download('%s', %s, 'image/png');" % [file_name, str(png_data)], true) - - -func save_gif(data, file_name : String = "export") -> void: - if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'): - return - - JavaScript.eval("download('%s', %s, 'image/gif');" % [file_name, str(Array(data))], true) - - func load_shader() -> void: if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'): return diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index da115c121..b012be9fd 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -314,11 +314,11 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true, file.close() - if OS.get_name() == "HTML5" and !autosave: + if OS.get_name() == "HTML5" and OS.has_feature('JavaScript') and !autosave: err = file.open(path, File.READ) if !err: var file_data = Array(file.get_buffer(file.get_len())) - JavaScript.eval("download('%s', %s, '');" % [path.get_file(), str(file_data)], true) + JavaScript.download_buffer(file_data, path.get_file()) file.close() # Remove the .pxo file from memory, as we don't need it anymore var dir = Directory.new()