mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Add an option to export a JSON file with the project data
Probably temporary, it might be a good idea to add a third "Data" tab in the export dialog, if we add stuff like exporting to Godot resources, such as AnimatedSprite, AnimationPlayer etc.
This commit is contained in:
parent
8c0a194468
commit
785701b093
|
@ -2378,6 +2378,10 @@ msgstr ""
|
|||
msgid "minute(s)"
|
||||
msgstr ""
|
||||
|
||||
#. A setting found in the export dialog. When enabled, a JSON file containing the project's data is also being exported. JSON refers to this https://en.wikipedia.org/wiki/JSON
|
||||
msgid "Export JSON data"
|
||||
msgstr ""
|
||||
|
||||
#. A setting found in the export dialog. When enabled, each layer is being exported as a different file, or as different frames if the target format is gif/apng/video.
|
||||
msgid "Split layers"
|
||||
msgstr ""
|
||||
|
|
|
@ -46,6 +46,7 @@ var custom_exporter_generators := {}
|
|||
var current_tab := ExportTab.IMAGE
|
||||
## All frames and their layers processed/blended into images
|
||||
var processed_images: Array[ProcessedImage] = []
|
||||
var export_json := false
|
||||
var split_layers := false
|
||||
|
||||
# Spritesheet options
|
||||
|
@ -351,7 +352,16 @@ func export_processed_images(
|
|||
return false
|
||||
|
||||
_scale_processed_images()
|
||||
|
||||
if export_json:
|
||||
var json := JSON.stringify(project.serialize())
|
||||
var json_file_name := project.name + ".json"
|
||||
if OS.has_feature("web"):
|
||||
var json_buffer := json.to_utf8_buffer()
|
||||
JavaScriptBridge.download_buffer(json_buffer, json_file_name, "application/json")
|
||||
else:
|
||||
var json_path := project.export_directory_path.path_join(json_file_name)
|
||||
var json_file := FileAccess.open(json_path, FileAccess.WRITE)
|
||||
json_file.store_string(json)
|
||||
# override if a custom export is chosen
|
||||
if project.file_format in custom_exporter_generators.keys():
|
||||
# Divert the path to the custom exporter instead
|
||||
|
|
10
src/Main.gd
10
src/Main.gd
|
@ -24,7 +24,7 @@ var splash_dialog: AcceptDialog:
|
|||
|
||||
|
||||
class CLI:
|
||||
static var args_list = {
|
||||
static var args_list := {
|
||||
["--version", "--pixelorama-version"]:
|
||||
[CLI.print_version, "Prints current Pixelorama version"],
|
||||
["--size"]: [CLI.print_project_size, "Prints size of the given project"],
|
||||
|
@ -36,8 +36,9 @@ class CLI:
|
|||
["--scale"]: [CLI.set_export_scale, "[integer] Scales up the export image by a number"],
|
||||
["--frames", "-f"]: [CLI.set_frames, "[integer-integer] Used to specify frame range"],
|
||||
["--direction", "-d"]: [CLI.set_direction, "[0, 1, 2] Specifies direction"],
|
||||
["--json"]: [CLI.set_json, "Export the JSON data of the project"],
|
||||
["--split-layers"]: [CLI.set_split_layers, "Each layer exports separately"],
|
||||
["--help", "-h"]: [CLI.generate_help, "Use to print HELP"]
|
||||
["--help", "-h", "-?"]: [CLI.generate_help, "Displays this help page"]
|
||||
}
|
||||
|
||||
static func generate_help(_project: Project, _next_arg: String):
|
||||
|
@ -59,7 +60,7 @@ some useful [SYSTEM OPTIONS] are:
|
|||
|
||||
|
||||
[USER OPTIONS]:\n
|
||||
(The terms in [ ] reflects the valid type for corresponding argument).
|
||||
(The terms in [ ] reflect the valid type for corresponding argument).
|
||||
|
||||
"""
|
||||
% OS.get_executable_path().get_file()
|
||||
|
@ -142,6 +143,9 @@ some useful [SYSTEM OPTIONS] are:
|
|||
else:
|
||||
print(Export.AnimationDirection.keys()[Export.direction])
|
||||
|
||||
static func set_json(_project: Project, _next_arg: String) -> void:
|
||||
Export.export_json = true
|
||||
|
||||
static func set_split_layers(_project: Project, _next_arg: String) -> void:
|
||||
Export.split_layers = true
|
||||
|
||||
|
|
|
@ -419,6 +419,10 @@ func _on_ExportDialog_popup_hide() -> void:
|
|||
frame_timer.stop()
|
||||
|
||||
|
||||
func _on_export_json_toggled(toggled_on: bool) -> void:
|
||||
Export.export_json = toggled_on
|
||||
|
||||
|
||||
func _on_split_layers_toggled(toggled_on: bool) -> void:
|
||||
Export.split_layers = toggled_on
|
||||
Export.process_data()
|
||||
|
|
|
@ -281,7 +281,12 @@ layout_mode = 2
|
|||
tooltip_text = "The character(s) that separate the file name and the frame number"
|
||||
text = "_"
|
||||
|
||||
[node name="SplitLayers" type="CheckBox" parent="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer" groups=["ExportImageOptions"]]
|
||||
[node name="ExportJSON" type="CheckBox" parent="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer"]
|
||||
layout_mode = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Export JSON data"
|
||||
|
||||
[node name="SplitLayers" type="CheckBox" parent="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer"]
|
||||
layout_mode = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Split layers"
|
||||
|
@ -348,6 +353,7 @@ size_flags_horizontal = 3
|
|||
[connection signal="item_selected" from="VBoxContainer/VSplitContainer/VBoxContainer/FilePath/FileFormat" to="." method="_on_FileFormat_item_selected"]
|
||||
[connection signal="item_selected" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/Interpolation" to="." method="_on_Interpolation_item_selected"]
|
||||
[connection signal="text_changed" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/SeparatorCharacter" to="." method="_on_SeparatorCharacter_text_changed"]
|
||||
[connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/ExportJSON" to="." method="_on_export_json_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/SplitLayers" to="." method="_on_split_layers_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/IncludeTagsInFilename" to="." method="_on_IncludeTagsInFilename_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer/VSplitContainer/VBoxContainer/AdvancedOptions/GridContainer/MultipleAnimationsDirectories" to="." method="_on_MultipleAnimationsDirectories_toggled"]
|
||||
|
|
Loading…
Reference in a new issue