Saving .pxo files in HTML5 is now possible

Addresses #280
This commit is contained in:
OverloadedOrama 2020-06-30 20:25:43 +03:00
parent a517f9178a
commit 637a60d9ee
9 changed files with 75 additions and 11 deletions

View file

@ -153,6 +153,7 @@ var zoom_level_label : Label
var new_image_dialog : ConfirmationDialog
var open_sprites_dialog : FileDialog
var save_sprites_dialog : FileDialog
var save_sprites_html5_dialog : ConfirmationDialog
var export_dialog : AcceptDialog
var preferences_dialog : AcceptDialog
var unsaved_changes_dialog : ConfirmationDialog
@ -288,6 +289,7 @@ func _ready() -> void:
new_image_dialog = find_node_by_name(root, "CreateNewImage")
open_sprites_dialog = find_node_by_name(root, "OpenSprite")
save_sprites_dialog = find_node_by_name(root, "SaveSprite")
save_sprites_html5_dialog = find_node_by_name(root, "SaveSpriteHTML5")
export_dialog = find_node_by_name(root, "ExportDialog")
preferences_dialog = find_node_by_name(root, "PreferencesDialog")
unsaved_changes_dialog = find_node_by_name(root, "UnsavedCanvasDialog")

View file

@ -286,6 +286,16 @@ func save_pxo_file(path : String, autosave : bool, project : Project = Global.cu
file.close()
if OS.get_name() == "HTML5" and !autosave:
file.open_compressed(path, File.READ, File.COMPRESSION_ZSTD)
if !err:
var file_data = Array(file.get_buffer(file.get_len()))
JavaScript.eval("download('%s', %s, '');" % [path.get_file(), str(file_data)], true)
file.close()
# Remove the .pxo file from memory, as we don't need it anymore
var dir = Directory.new()
dir.remove(path)
if autosave:
Global.notification_label("File autosaved")
else: