1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

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:

View file

@ -145,6 +145,13 @@ func _on_SaveSprite_file_selected(path : String) -> void:
_on_QuitDialog_confirmed()
func _on_SaveSpriteHTML5_confirmed() -> void:
var file_name = Global.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text
file_name += ".pxo"
var path = "user://".plus_file(file_name)
OpenSave.save_pxo_file(path, false)
func _on_OpenSprite_popup_hide() -> void:
if !opensprite_file_selected:
_can_draw_true()

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=20 format=2]
[ext_resource path="res://assets/themes/dark/theme.tres" type="Theme" id=1]
[ext_resource path="res://src/Main.gd" type="Script" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://src/UI/PatternsPopup.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/UI/BrushesPopup.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/UI/Dialogs/ResizeCanvas.tscn" type="PackedScene" id=7]
[ext_resource path="res://src/UI/Dialogs/SaveSpriteHTML5.tscn" type="PackedScene" id=8]
[ext_resource path="res://src/UI/Dialogs/SaveSprite.tscn" type="PackedScene" id=11]
[ext_resource path="res://src/UI/Dialogs/OpenSprite.tscn" type="PackedScene" id=12]
[ext_resource path="res://src/UI/Dialogs/SplashDialog.tscn" type="PackedScene" id=27]
@ -54,6 +55,8 @@ __meta__ = {
[node name="SaveSprite" parent="." instance=ExtResource( 11 )]
[node name="SaveSpriteHTML5" parent="." instance=ExtResource( 8 )]
[node name="ExportDialog" parent="." instance=ExtResource( 39 )]
[node name="ScaleImage" parent="." instance=ExtResource( 31 )]
@ -120,6 +123,8 @@ visible = false
[connection signal="popup_hide" from="OpenSprite" to="." method="_on_OpenSprite_popup_hide"]
[connection signal="file_selected" from="SaveSprite" to="." method="_on_SaveSprite_file_selected"]
[connection signal="popup_hide" from="SaveSprite" to="." method="_can_draw_true"]
[connection signal="confirmed" from="SaveSpriteHTML5" to="." method="_on_SaveSpriteHTML5_confirmed"]
[connection signal="popup_hide" from="SaveSpriteHTML5" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="ExportDialog" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="ScaleImage" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="ResizeCanvas" to="." method="_can_draw_true"]

View file

@ -346,8 +346,8 @@ window_title = "Open a Directory"
resizable = true
mode = 2
access = 2
current_dir = "C:/Users"
current_path = "C:/Users/"
current_dir = "/Users"
current_path = "/Users/"
[node name="PathValidationAlert" type="AcceptDialog" parent="Popups"]
margin_left = 8.0

View file

@ -8,5 +8,5 @@ resizable = true
mode = 0
access = 2
filters = PoolStringArray( "*.pxo ; Pixelorama Project", "*.png ; PNG Image", "*.bmp ; BMP Image", "*.hdr ; Radiance HDR Image", "*.jpg,*.jpeg ; JPEG Image", "*.svg ; SVG Image", "*.tga ; TGA Image", "*.webp ; WebP Image" )
current_dir = "C:/Users"
current_path = "C:/Users/"
current_dir = "/Users"
current_path = "/Users/"

View file

@ -12,5 +12,5 @@ margin_bottom = 48.0
resizable = true
access = 2
filters = PoolStringArray( "*.pxo ; Pixelorama Project" )
current_dir = "C:/Users"
current_path = "C:/Users/"
current_dir = "/Users"
current_path = "/Users/"

View file

@ -0,0 +1,33 @@
[gd_scene format=2]
[node name="SaveSpriteHTML5" type="ConfirmationDialog"]
visible = true
margin_right = 200.0
margin_bottom = 70.0
[node name="FileNameContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
margin_bottom = 41.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="FileNameLabel" type="Label" parent="FileNameContainer"]
margin_top = 13.0
margin_right = 67.0
margin_bottom = 27.0
text = "File name:"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="FileNameLineEdit" type="LineEdit" parent="FileNameContainer"]
margin_left = 71.0
margin_top = 8.0
margin_right = 200.0
margin_bottom = 32.0
size_flags_horizontal = 3
size_flags_vertical = 4
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -162,16 +162,23 @@ func on_open_last_project_file_menu_option_pressed() -> void:
func save_project_file() -> void:
Global.control.is_quitting_on_save = false
if OpenSave.current_save_paths[Global.current_project_index] == "":
Global.save_sprites_dialog.popup_centered()
var path = OpenSave.current_save_paths[Global.current_project_index]
if path == "":
if OS.get_name() == "HTML5":
Global.save_sprites_html5_dialog.popup_centered()
else:
Global.save_sprites_dialog.popup_centered()
Global.dialog_open(true)
else:
Global.control._on_SaveSprite_file_selected(OpenSave.current_save_paths[Global.current_project_index])
Global.control._on_SaveSprite_file_selected(path)
func save_project_file_as() -> void:
Global.control.is_quitting_on_save = false
Global.save_sprites_dialog.popup_centered()
if OS.get_name() == "HTML5":
Global.save_sprites_html5_dialog.popup_centered()
else:
Global.save_sprites_dialog.popup_centered()
Global.dialog_open(true)