mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Use JavaScript.download_buffer() for file downloading in the Web version
This commit makes Pixelorama unable to run in Godot versions prior to 3.4. I wonder if there are plans for an upload_buffer() method as well...
This commit is contained in:
parent
1278553c80
commit
0c1fcdea89
|
@ -185,7 +185,7 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo
|
||||||
else:
|
else:
|
||||||
for i in range(processed_images.size()):
|
for i in range(processed_images.size()):
|
||||||
if OS.get_name() == "HTML5":
|
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:
|
else:
|
||||||
var err = processed_images[i].save_png(export_paths[i])
|
var err = processed_images[i].save_png(export_paths[i])
|
||||||
if err != OK:
|
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"])
|
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":
|
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:
|
else:
|
||||||
var file: File = File.new()
|
var file: File = File.new()
|
||||||
|
|
|
@ -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)
|
""", true)
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,21 +185,6 @@ func load_palette() -> void:
|
||||||
return
|
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:
|
func load_shader() -> void:
|
||||||
if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'):
|
if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'):
|
||||||
return
|
return
|
||||||
|
|
|
@ -314,11 +314,11 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
|
||||||
|
|
||||||
file.close()
|
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)
|
err = file.open(path, File.READ)
|
||||||
if !err:
|
if !err:
|
||||||
var file_data = Array(file.get_buffer(file.get_len()))
|
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()
|
file.close()
|
||||||
# Remove the .pxo file from memory, as we don't need it anymore
|
# Remove the .pxo file from memory, as we don't need it anymore
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
|
|
Loading…
Reference in a new issue