Add addons
This commit is contained in:
parent
2c862b2235
commit
3367bad24f
527 changed files with 36197 additions and 0 deletions
|
|
@ -0,0 +1,208 @@
|
|||
@tool
|
||||
extends PanelContainer
|
||||
|
||||
const wizard_config = preload("../../config/wizard_config.gd")
|
||||
const result_code = preload("../../config/result_codes.gd")
|
||||
var sprite_frames_creator = preload("../sprite_frames_creator.gd").new()
|
||||
|
||||
var scene: Node
|
||||
var sprite: Node
|
||||
|
||||
var config
|
||||
var file_system: EditorFileSystem
|
||||
|
||||
var _layer: String = ""
|
||||
var _source: String = ""
|
||||
var _file_dialog_aseprite: FileDialog
|
||||
var _output_folder_dialog: FileDialog
|
||||
var _importing := false
|
||||
|
||||
var _output_folder := ""
|
||||
var _out_folder_default := "[Same as scene]"
|
||||
var _layer_default := "[all]"
|
||||
|
||||
@onready var _source_field = $margin/VBoxContainer/source/button
|
||||
@onready var _layer_field = $margin/VBoxContainer/layer/options
|
||||
@onready var _options_title = $margin/VBoxContainer/options_title/options_title
|
||||
@onready var _options_container = $margin/VBoxContainer/options
|
||||
@onready var _out_folder_field = $margin/VBoxContainer/options/out_folder/button
|
||||
@onready var _out_filename_field = $margin/VBoxContainer/options/out_filename/LineEdit
|
||||
@onready var _visible_layers_field = $margin/VBoxContainer/options/visible_layers/CheckButton
|
||||
@onready var _ex_pattern_field = $margin/VBoxContainer/options/ex_pattern/LineEdit
|
||||
|
||||
func _ready():
|
||||
var cfg = wizard_config.load_config(sprite)
|
||||
|
||||
if cfg == null:
|
||||
_load_default_config()
|
||||
else:
|
||||
_load_config(cfg)
|
||||
|
||||
sprite_frames_creator.init(config, file_system)
|
||||
|
||||
|
||||
func _load_config(cfg):
|
||||
if cfg.has("source"):
|
||||
_set_source(cfg.source)
|
||||
|
||||
if cfg.get("layer", "") != "":
|
||||
_layer_field.clear()
|
||||
_set_layer(cfg.layer)
|
||||
|
||||
_output_folder = cfg.get("o_folder", "")
|
||||
_out_folder_field.text = _output_folder if _output_folder != "" else _out_folder_default
|
||||
_out_filename_field.text = cfg.get("o_name", "")
|
||||
_visible_layers_field.button_pressed = cfg.get("only_visible", false)
|
||||
_ex_pattern_field.text = cfg.get("o_ex_p", "")
|
||||
|
||||
_set_options_visible(cfg.get("op_exp", false))
|
||||
|
||||
|
||||
func _load_default_config():
|
||||
_ex_pattern_field.text = config.get_default_exclusion_pattern()
|
||||
_set_options_visible(false)
|
||||
|
||||
|
||||
func _set_source(source):
|
||||
_source = source
|
||||
_source_field.text = _source
|
||||
_source_field.tooltip_text = _source
|
||||
|
||||
|
||||
func _set_layer(layer):
|
||||
_layer = layer
|
||||
_layer_field.add_item(_layer)
|
||||
|
||||
|
||||
func _on_layer_button_down():
|
||||
if _source == "":
|
||||
_show_message("Please. Select source file first.")
|
||||
return
|
||||
|
||||
var layers = sprite_frames_creator.list_layers(ProjectSettings.globalize_path(_source))
|
||||
var current = 0
|
||||
_layer_field.clear()
|
||||
_layer_field.add_item(_layer_default)
|
||||
|
||||
for l in layers:
|
||||
if l == "":
|
||||
continue
|
||||
|
||||
_layer_field.add_item(l)
|
||||
if l == _layer:
|
||||
current = _layer_field.get_item_count() - 1
|
||||
_layer_field.select(current)
|
||||
|
||||
|
||||
func _on_layer_item_selected(index):
|
||||
if index == 0:
|
||||
_layer = ""
|
||||
return
|
||||
_layer = _layer_field.get_item_text(index)
|
||||
_save_config()
|
||||
|
||||
|
||||
func _on_source_pressed():
|
||||
_open_source_dialog()
|
||||
|
||||
|
||||
func _on_import_pressed():
|
||||
if _importing:
|
||||
return
|
||||
_importing = true
|
||||
|
||||
var root = get_tree().get_edited_scene_root()
|
||||
|
||||
if _source == "":
|
||||
_show_message("Aseprite file not selected.")
|
||||
_importing = false
|
||||
return
|
||||
|
||||
var options = {
|
||||
"source": ProjectSettings.globalize_path(_source),
|
||||
"output_folder": _output_folder if _output_folder != "" else root.scene_file_path.get_base_dir(),
|
||||
"exception_pattern": _ex_pattern_field.text,
|
||||
"only_visible_layers": _visible_layers_field.button_pressed,
|
||||
"output_filename": _out_filename_field.text,
|
||||
"layer": _layer
|
||||
}
|
||||
|
||||
_save_config()
|
||||
|
||||
await sprite_frames_creator.create_animations(sprite, options)
|
||||
_importing = false
|
||||
|
||||
|
||||
func _save_config():
|
||||
wizard_config.save_config(sprite, config.is_use_metadata_enabled(), {
|
||||
"source": _source,
|
||||
"layer": _layer,
|
||||
"op_exp": _options_title.button_pressed,
|
||||
"o_folder": _output_folder,
|
||||
"o_name": _out_filename_field.text,
|
||||
"only_visible": _visible_layers_field.button_pressed,
|
||||
"o_ex_p": _ex_pattern_field.text
|
||||
})
|
||||
|
||||
|
||||
func _open_source_dialog():
|
||||
_file_dialog_aseprite = _create_aseprite_file_selection()
|
||||
get_parent().add_child(_file_dialog_aseprite)
|
||||
if _source != "":
|
||||
_file_dialog_aseprite.current_dir = _source.get_base_dir()
|
||||
_file_dialog_aseprite.popup_centered_ratio()
|
||||
|
||||
|
||||
func _create_aseprite_file_selection():
|
||||
var file_dialog = FileDialog.new()
|
||||
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
|
||||
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||
file_dialog.connect("file_selected",Callable(self,"_on_aseprite_file_selected"))
|
||||
file_dialog.set_filters(PackedStringArray(["*.ase","*.aseprite"]))
|
||||
return file_dialog
|
||||
|
||||
|
||||
func _on_aseprite_file_selected(path):
|
||||
_set_source(ProjectSettings.localize_path(path))
|
||||
_save_config()
|
||||
_file_dialog_aseprite.queue_free()
|
||||
|
||||
|
||||
func _show_message(message: String):
|
||||
var _warning_dialog = AcceptDialog.new()
|
||||
get_parent().add_child(_warning_dialog)
|
||||
_warning_dialog.dialog_text = message
|
||||
_warning_dialog.popup_centered()
|
||||
_warning_dialog.connect("popup_hide",Callable(_warning_dialog,"queue_free"))
|
||||
|
||||
|
||||
func _on_options_title_toggled(button_pressed):
|
||||
_set_options_visible(button_pressed)
|
||||
_save_config()
|
||||
|
||||
|
||||
func _set_options_visible(is_visible):
|
||||
_options_container.visible = is_visible
|
||||
_options_title.icon = config.get_icon("expanded") if is_visible else config.get_icon("collapsed")
|
||||
|
||||
|
||||
func _on_out_folder_pressed():
|
||||
_output_folder_dialog = _create_output_folder_selection()
|
||||
get_parent().add_child(_output_folder_dialog)
|
||||
if _output_folder != _out_folder_default:
|
||||
_output_folder_dialog.current_dir = _output_folder
|
||||
_output_folder_dialog.popup_centered_ratio()
|
||||
|
||||
|
||||
func _create_output_folder_selection():
|
||||
var file_dialog = FileDialog.new()
|
||||
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_DIR
|
||||
file_dialog.access = FileDialog.ACCESS_RESOURCES
|
||||
file_dialog.connect("dir_selected",Callable(self,"_on_output_folder_selected"))
|
||||
return file_dialog
|
||||
|
||||
|
||||
func _on_output_folder_selected(path):
|
||||
_output_folder = path
|
||||
_out_folder_field.text = _output_folder if _output_folder != "" else _out_folder_default
|
||||
_output_folder_dialog.queue_free()
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://vej7yqkbtd5f"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/AsepriteWizard/animated_sprite/docks/animated_sprite_inspector_dock.gd" id="1"]
|
||||
|
||||
[node name="animated_sprite_inspector_dock" type="PanelContainer"]
|
||||
offset_right = 14.0
|
||||
offset_bottom = 14.0
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="margin" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="margin"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="section_title" type="PanelContainer" parent="margin/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="title" type="Label" parent="margin/VBoxContainer/section_title"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Aseprite"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="source" type="HBoxContainer" parent="margin/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Location of the Aseprite (*.ase, *.aseprite) source file."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/source"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Aseprite File"
|
||||
|
||||
[node name="button" type="Button" parent="margin/VBoxContainer/source"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "[empty]"
|
||||
clip_text = true
|
||||
|
||||
[node name="layer" type="HBoxContainer" parent="margin/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Aseprite layer to be used in the animation. By default all layers are included."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/layer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Layer"
|
||||
|
||||
[node name="options" type="OptionButton" parent="margin/VBoxContainer/layer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
item_count = 1
|
||||
selected = 0
|
||||
popup/item_0/text = "[all]"
|
||||
popup/item_0/id = 0
|
||||
|
||||
[node name="options_title" type="PanelContainer" parent="margin/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="options_title" type="Button" parent="margin/VBoxContainer/options_title"]
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "Options"
|
||||
|
||||
[node name="options" type="VBoxContainer" parent="margin/VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="out_folder" type="HBoxContainer" parent="margin/VBoxContainer/options"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Location where the spritesheet file should be saved."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/options/out_folder"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Output folder"
|
||||
|
||||
[node name="button" type="Button" parent="margin/VBoxContainer/options/out_folder"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "[empty]"
|
||||
clip_text = true
|
||||
|
||||
[node name="out_filename" type="HBoxContainer" parent="margin/VBoxContainer/options"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Base filename for spritesheet. In case the layer option is used, this works as a prefix to the layer name."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/options/out_filename"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Output file name"
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="margin/VBoxContainer/options/out_filename"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
|
||||
[node name="ex_pattern" type="HBoxContainer" parent="margin/VBoxContainer/options"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Exclude layers with name matching this pattern (regex)."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/options/ex_pattern"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Exclude pattern"
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="margin/VBoxContainer/options/ex_pattern"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
|
||||
[node name="visible_layers" type="HBoxContainer" parent="margin/VBoxContainer/options"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "If active, layers not visible in the source file won't be included in the final image."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/options/visible_layers"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Only visible layers"
|
||||
|
||||
[node name="CheckButton" type="CheckButton" parent="margin/VBoxContainer/options/visible_layers"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
|
||||
[node name="import" type="Button" parent="margin/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Import"
|
||||
|
||||
[connection signal="pressed" from="margin/VBoxContainer/source/button" to="." method="_on_source_pressed"]
|
||||
[connection signal="button_down" from="margin/VBoxContainer/layer/options" to="." method="_on_layer_button_down"]
|
||||
[connection signal="item_selected" from="margin/VBoxContainer/layer/options" to="." method="_on_layer_item_selected"]
|
||||
[connection signal="toggled" from="margin/VBoxContainer/options_title/options_title" to="." method="_on_options_title_toggled"]
|
||||
[connection signal="pressed" from="margin/VBoxContainer/options/out_folder/button" to="." method="_on_out_folder_pressed"]
|
||||
[connection signal="pressed" from="margin/VBoxContainer/import" to="." method="_on_import_pressed"]
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
@tool
|
||||
extends TabContainer
|
||||
|
||||
signal close_requested
|
||||
|
||||
const WizardWindow = preload("./as_wizard_window.tscn")
|
||||
|
||||
var _config
|
||||
var _file_system: EditorFileSystem
|
||||
|
||||
func _ready():
|
||||
$Import.init(_config, _file_system)
|
||||
$Import.connect("close_requested",Callable(self,"emit_signal").bind("close_requested"))
|
||||
$Import.connect("import_success",Callable($History,"add_entry"))
|
||||
$History.init(_config)
|
||||
$History.connect("request_edit",Callable(self,"_on_edit_request"))
|
||||
$History.connect("request_import",Callable(self,"_on_import_request"))
|
||||
|
||||
|
||||
func init(config, editor_file_system: EditorFileSystem):
|
||||
_config = config
|
||||
_file_system = editor_file_system
|
||||
|
||||
|
||||
func _on_AsWizardDockContainer_tab_changed(tab: int):
|
||||
if tab == 1:
|
||||
$History.reload()
|
||||
|
||||
|
||||
func _on_edit_request(import_cfg: Dictionary):
|
||||
$Import.load_import_config(import_cfg)
|
||||
self.current_tab = 0
|
||||
|
||||
|
||||
func _on_import_request(import_cfg: Dictionary):
|
||||
$Import.load_import_config(import_cfg)
|
||||
$Import.trigger_import()
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/AsepriteWizard/animated_sprite/docks/as_wizard_window.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/AsepriteWizard/animated_sprite/docks/as_wizard_dock_container.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/AsepriteWizard/animated_sprite/docks/sprite_frames_import_history.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="AsWizardDockContainer" type="TabContainer"]
|
||||
offset_right = 281.0
|
||||
offset_bottom = 36.0
|
||||
tab_alignment = 2
|
||||
use_hidden_tabs_for_min_size = true
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Import" parent="." instance=ExtResource( 1 )]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 4.0
|
||||
offset_top = 32.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = -4.0
|
||||
tooltip_text = "SpriteFrames Importer"
|
||||
|
||||
[node name="History" parent="." instance=ExtResource( 3 )]
|
||||
visible = false
|
||||
|
||||
[connection signal="tab_changed" from="." to="." method="_on_AsWizardDockContainer_tab_changed"]
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
@tool
|
||||
extends PanelContainer
|
||||
|
||||
signal close_requested
|
||||
signal import_success(file_settings)
|
||||
|
||||
var result_code = preload("../../config/result_codes.gd")
|
||||
var _sf_creator = preload("../sprite_frames_creator.gd").new()
|
||||
|
||||
var _config
|
||||
var _file_system: EditorFileSystem
|
||||
|
||||
var _file_dialog_aseprite: FileDialog
|
||||
var _output_folder_dialog: FileDialog
|
||||
var _warning_dialog: AcceptDialog
|
||||
|
||||
func _exit_tree():
|
||||
_file_dialog_aseprite.queue_free()
|
||||
_output_folder_dialog.queue_free()
|
||||
_warning_dialog.queue_free()
|
||||
|
||||
|
||||
func init(config, editor_file_system: EditorFileSystem):
|
||||
_config = config
|
||||
_file_system = editor_file_system
|
||||
_file_dialog_aseprite = _create_aseprite_file_selection()
|
||||
_output_folder_dialog = _create_outuput_folder_selection()
|
||||
_warning_dialog = AcceptDialog.new()
|
||||
_warning_dialog.exclusive = false
|
||||
|
||||
_sf_creator.init(_config, _file_system)
|
||||
|
||||
get_parent().get_parent().add_child(_file_dialog_aseprite)
|
||||
get_parent().get_parent().add_child(_output_folder_dialog)
|
||||
get_parent().get_parent().add_child(_warning_dialog)
|
||||
|
||||
_load_persisted_config()
|
||||
|
||||
|
||||
func _load_persisted_config():
|
||||
_split_mode_field().button_pressed = _config.should_split_layers()
|
||||
_only_visible_layers_field().button_pressed = _config.should_include_only_visible_layers()
|
||||
_exception_pattern_field().text = _config.get_exception_pattern()
|
||||
_custom_name_field().text = _config.get_last_custom_name()
|
||||
_file_location_field().text = _config.get_last_source_path()
|
||||
_do_not_create_res_field().button_pressed = _config.should_not_create_resource()
|
||||
|
||||
var output_folder = _config.get_last_output_path()
|
||||
_output_folder_field().text = output_folder if output_folder != "" else "res://"
|
||||
|
||||
|
||||
func load_import_config(import_config: Dictionary):
|
||||
_split_mode_field().button_pressed = import_config.options.export_mode == _sf_creator.LAYERS_EXPORT_MODE
|
||||
_only_visible_layers_field().button_pressed = import_config.options.only_visible_layers
|
||||
_exception_pattern_field().text = import_config.options.exception_pattern
|
||||
_custom_name_field().text = import_config.options.output_filename
|
||||
_file_location_field().text = import_config.source_file
|
||||
_do_not_create_res_field().button_pressed = import_config.options.do_not_create_resource
|
||||
_output_folder_field().text = import_config.output_location if import_config.output_location != "" else "res://"
|
||||
|
||||
|
||||
func _open_aseprite_file_selection_dialog():
|
||||
var current_selection = _file_location_field().text
|
||||
if current_selection != "":
|
||||
_file_dialog_aseprite.current_dir = current_selection.get_base_dir()
|
||||
_file_dialog_aseprite.popup_centered_ratio()
|
||||
|
||||
|
||||
func _open_output_folder_selection_dialog():
|
||||
var current_selection = _output_folder_field().text
|
||||
if current_selection != "":
|
||||
_output_folder_dialog.current_dir = current_selection
|
||||
_output_folder_dialog.popup_centered_ratio()
|
||||
|
||||
|
||||
func _create_aseprite_file_selection():
|
||||
var file_dialog = FileDialog.new()
|
||||
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
|
||||
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||
file_dialog.connect("file_selected", _on_aseprite_file_selected)
|
||||
file_dialog.set_filters(PackedStringArray(["*.ase","*.aseprite"]))
|
||||
return file_dialog
|
||||
|
||||
|
||||
func _create_outuput_folder_selection():
|
||||
var file_dialog = FileDialog.new()
|
||||
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_DIR
|
||||
file_dialog.access = FileDialog.ACCESS_RESOURCES
|
||||
file_dialog.connect("dir_selected", _on_output_folder_selected)
|
||||
return file_dialog
|
||||
|
||||
|
||||
func _on_aseprite_file_selected(path):
|
||||
var localized_path = ProjectSettings.localize_path(path)
|
||||
_file_location_field().text = localized_path
|
||||
_config.set_last_source_path(localized_path)
|
||||
|
||||
|
||||
func _on_output_folder_selected(path):
|
||||
_output_folder_field().text = path
|
||||
_config.set_last_output_path(path)
|
||||
|
||||
|
||||
func _on_next_btn_up():
|
||||
var aseprite_file = _file_location_field().text
|
||||
var output_location = _output_folder_field().text
|
||||
var split_layers = _split_mode_field().button_pressed
|
||||
|
||||
var export_mode = _sf_creator.LAYERS_EXPORT_MODE if split_layers else _sf_creator.FILE_EXPORT_MODE
|
||||
var options = {
|
||||
"export_mode": export_mode,
|
||||
"exception_pattern": _exception_pattern_field().text,
|
||||
"only_visible_layers": _only_visible_layers_field().button_pressed,
|
||||
"output_filename": _custom_name_field().text,
|
||||
"do_not_create_resource": _do_not_create_res_field().button_pressed,
|
||||
"remove_source_files_allowed": true,
|
||||
"output_folder": output_location,
|
||||
}
|
||||
var exit_code = await _sf_creator.create_and_save_resources(
|
||||
ProjectSettings.globalize_path(aseprite_file),
|
||||
options
|
||||
)
|
||||
|
||||
if exit_code != OK:
|
||||
_show_error(exit_code)
|
||||
return
|
||||
emit_signal("import_success", {
|
||||
"source_file": aseprite_file,
|
||||
"output_location": output_location,
|
||||
"options": options,
|
||||
})
|
||||
_show_import_success_message()
|
||||
|
||||
|
||||
func trigger_import():
|
||||
_on_next_btn_up()
|
||||
|
||||
|
||||
func _on_close_btn_up():
|
||||
_close_window()
|
||||
|
||||
|
||||
func _close_window():
|
||||
_save_config()
|
||||
self.emit_signal("close_requested")
|
||||
|
||||
|
||||
func _save_config():
|
||||
_config.set_split_layers(_split_mode_field().button_pressed)
|
||||
_config.set_exception_pattern(_exception_pattern_field().text)
|
||||
_config.set_custom_name(_custom_name_field().text)
|
||||
_config.set_include_only_visible_layers(_only_visible_layers_field().button_pressed)
|
||||
_config.set_do_not_create_resource(_do_not_create_res_field().button_pressed)
|
||||
|
||||
|
||||
func _show_error(code: int):
|
||||
_show_error_message(result_code.get_error_message(code))
|
||||
|
||||
|
||||
func _show_error_message(message: String):
|
||||
_warning_dialog.dialog_text = "Error: %s" % message
|
||||
_warning_dialog.popup_centered()
|
||||
|
||||
|
||||
func _show_import_success_message():
|
||||
_warning_dialog.dialog_text = "Aseprite import succeeded"
|
||||
_warning_dialog.popup_centered()
|
||||
_save_config()
|
||||
|
||||
|
||||
func _file_location_field() -> LineEdit:
|
||||
return $container/options/file_location/HBoxContainer/file_location_path as LineEdit
|
||||
|
||||
|
||||
func _output_folder_field() -> LineEdit:
|
||||
return $container/options/output_folder/HBoxContainer/file_location_path as LineEdit
|
||||
|
||||
|
||||
func _exception_pattern_field() -> LineEdit:
|
||||
return $container/options/exclude_pattern/pattern as LineEdit
|
||||
|
||||
|
||||
func _split_mode_field() -> CheckBox:
|
||||
return $container/options/layer_importing_mode/split_layers/field as CheckBox
|
||||
|
||||
|
||||
func _only_visible_layers_field() -> CheckBox:
|
||||
return $container/options/layer_importing_mode/visible_layers/field as CheckBox
|
||||
|
||||
|
||||
func _custom_name_field() -> LineEdit:
|
||||
return $container/options/custom_filename/pattern as LineEdit
|
||||
|
||||
|
||||
func _do_not_create_res_field() -> CheckBox:
|
||||
return $container/options/layer_importing_mode/disable_resource_creation/field as CheckBox
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c5dwobjd34w3p"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/AsepriteWizard/animated_sprite/docks/as_wizard_window.gd" id="1"]
|
||||
|
||||
[node name="ASWizardWindow" type="PanelContainer"]
|
||||
offset_right = 600.0
|
||||
offset_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="container" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="options" type="VBoxContainer" parent="container"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="file_location" type="VBoxContainer" parent="container/options"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="file_location_label" type="Label" parent="container/options/file_location"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Location of the Aseprite *.ase source file"
|
||||
mouse_filter = 1
|
||||
text = "Aseprite File Location:*"
|
||||
clip_text = true
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="container/options/file_location"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="file_location_path" type="LineEdit" parent="container/options/file_location/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
caret_blink = true
|
||||
|
||||
[node name="file_location_btn" type="Button" parent="container/options/file_location/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Select"
|
||||
|
||||
[node name="output_folder" type="VBoxContainer" parent="container/options"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="label" type="Label" parent="container/options/output_folder"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Folder where the SpriteSheet resource is going to be saved"
|
||||
mouse_filter = 1
|
||||
text = "Output folder:*"
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="container/options/output_folder"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="file_location_path" type="LineEdit" parent="container/options/output_folder/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "res://"
|
||||
caret_blink = true
|
||||
|
||||
[node name="output_folder_btn" type="Button" parent="container/options/output_folder/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Select"
|
||||
|
||||
[node name="exclude_pattern" type="VBoxContainer" parent="container/options"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="label" type="Label" parent="container/options/exclude_pattern"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "If layer name matches this pattern, it won't be exported."
|
||||
mouse_filter = 1
|
||||
text = "Exclude layers with name matching pattern:"
|
||||
|
||||
[node name="pattern" type="LineEdit" parent="container/options/exclude_pattern"]
|
||||
layout_mode = 2
|
||||
caret_blink = true
|
||||
|
||||
[node name="custom_filename" type="VBoxContainer" parent="container/options"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="label" type="Label" parent="container/options/custom_filename"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Output filename. In case layers are not being merged, this is used as file prefix.
|
||||
If not set, source filename is used."
|
||||
mouse_filter = 1
|
||||
text = "Output file name / prefix:"
|
||||
|
||||
[node name="pattern" type="LineEdit" parent="container/options/custom_filename"]
|
||||
layout_mode = 2
|
||||
caret_blink = true
|
||||
|
||||
[node name="layer_importing_mode" type="VBoxContainer" parent="container/options"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="label" type="Label" parent="container/options/layer_importing_mode"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
text = "Options:"
|
||||
|
||||
[node name="split_layers" type="HBoxContainer" parent="container/options/layer_importing_mode"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="field" type="CheckBox" parent="container/options/layer_importing_mode/split_layers"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "If selected, one resource will be created for each layer.
|
||||
If not selected, layers will be merged and exported as one SpriteSheet."
|
||||
text = "Split layers in multiple resources"
|
||||
|
||||
[node name="visible_layers" type="HBoxContainer" parent="container/options/layer_importing_mode"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="field" type="CheckBox" parent="container/options/layer_importing_mode/visible_layers"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "If selected, layers not visible in the source file won't be included in the final image."
|
||||
text = "Only include visible layers"
|
||||
|
||||
[node name="disable_resource_creation" type="HBoxContainer" parent="container/options/layer_importing_mode"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="field" type="CheckBox" parent="container/options/layer_importing_mode/disable_resource_creation"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Does not create SpriteFrames resource. Useful if you are only interested in the .json and .png output from Aseprite."
|
||||
text = "Do not create resource file"
|
||||
|
||||
[node name="buttons" type="HBoxContainer" parent="container/options"]
|
||||
layout_mode = 2
|
||||
alignment = 2
|
||||
|
||||
[node name="close" type="Button" parent="container/options/buttons"]
|
||||
layout_mode = 2
|
||||
text = "Close"
|
||||
|
||||
[node name="next" type="Button" parent="container/options/buttons"]
|
||||
layout_mode = 2
|
||||
text = "Import"
|
||||
|
||||
[connection signal="button_up" from="container/options/file_location/HBoxContainer/file_location_btn" to="." method="_open_aseprite_file_selection_dialog"]
|
||||
[connection signal="button_up" from="container/options/output_folder/HBoxContainer/output_folder_btn" to="." method="_open_output_folder_selection_dialog"]
|
||||
[connection signal="button_up" from="container/options/buttons/close" to="." method="_on_close_btn_up"]
|
||||
[connection signal="button_up" from="container/options/buttons/next" to="." method="_on_next_btn_up"]
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
@tool
|
||||
extends PanelContainer
|
||||
|
||||
signal request_edit(import_cfg)
|
||||
signal request_import(import_cfg)
|
||||
|
||||
const SourcePathField = preload("./wizard_nodes/source_path.tscn")
|
||||
const OutputPathField = preload("./wizard_nodes/output_path.tscn")
|
||||
const ImportDateField = preload("./wizard_nodes/import_date.tscn")
|
||||
const ItemActions = preload("./wizard_nodes/list_actions.tscn")
|
||||
|
||||
const SORT_BY_DATE := 0
|
||||
const SORT_BY_PATH := 1
|
||||
const INITIAL_GRID_INDEX := 3
|
||||
|
||||
var _config
|
||||
var _history: Array
|
||||
var _history_nodes := {}
|
||||
var _history_nodes_list := []
|
||||
var _is_busy := false
|
||||
var _import_requested_for := -1
|
||||
var _sort_by = SORT_BY_DATE
|
||||
|
||||
@onready var grid = $MarginContainer/VBoxContainer/ScrollContainer/GridContainer
|
||||
@onready var loading_warning = $MarginContainer/VBoxContainer/loading_warning
|
||||
@onready var no_history_warning = $MarginContainer/VBoxContainer/no_history_warning
|
||||
|
||||
func init(config):
|
||||
_config = config
|
||||
|
||||
|
||||
func reload():
|
||||
if _history:
|
||||
return
|
||||
|
||||
_history = _config.get_import_history()
|
||||
|
||||
for index in range(_history.size()):
|
||||
var entry = _history[index]
|
||||
_create_node_list_entry(entry, index)
|
||||
|
||||
loading_warning.hide()
|
||||
if _history.is_empty():
|
||||
no_history_warning.show()
|
||||
else:
|
||||
grid.get_parent().show()
|
||||
|
||||
|
||||
func _create_node_list_entry(entry: Dictionary, index: int):
|
||||
_add_to_node_list(entry, _create_nodes(entry, index))
|
||||
|
||||
|
||||
func _create_nodes(entry: Dictionary, index: int) -> Dictionary:
|
||||
var source_path = SourcePathField.instantiate()
|
||||
source_path.set_entry(entry)
|
||||
|
||||
grid.get_child(INITIAL_GRID_INDEX).add_sibling(source_path)
|
||||
|
||||
var output_path = OutputPathField.instantiate()
|
||||
output_path.text = entry.output_location
|
||||
source_path.add_sibling(output_path)
|
||||
var import_date = ImportDateField.instantiate()
|
||||
import_date.set_date(entry.import_date)
|
||||
output_path.add_sibling(import_date)
|
||||
var actions = ItemActions.instantiate()
|
||||
actions.history_index = index
|
||||
import_date.add_sibling(actions)
|
||||
actions.connect("import_clicked",Callable(self,"_on_entry_reimport_clicked"))
|
||||
actions.connect("edit_clicked",Callable(self,"_on_entry_edit_clicked"))
|
||||
actions.connect("removed_clicked",Callable(self,"_on_entry_remove_clicked"))
|
||||
return {
|
||||
"history_index": index,
|
||||
"timestamp": entry.import_date,
|
||||
"source_file": entry.source_file,
|
||||
"source_path_node": source_path,
|
||||
"output_path_node": output_path,
|
||||
"import_date_node": import_date,
|
||||
"actions_node": actions,
|
||||
}
|
||||
|
||||
|
||||
func _add_to_node_list(entry: Dictionary, node: Dictionary):
|
||||
if not _history_nodes.has(entry.source_file):
|
||||
_history_nodes[entry.source_file] = []
|
||||
_history_nodes[entry.source_file].push_front(node)
|
||||
_history_nodes_list.push_front(node)
|
||||
|
||||
|
||||
func add_entry(file_settings: Dictionary):
|
||||
if _history == null:
|
||||
reload()
|
||||
|
||||
var dt = Time.get_datetime_dict_from_system()
|
||||
file_settings["import_date"] = "%04d-%02d-%02d %02d:%02d:%02d" % [dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second]
|
||||
|
||||
if _import_requested_for != -1:
|
||||
_remove_item(_import_requested_for)
|
||||
_import_requested_for = -1
|
||||
elif _config.is_single_file_history() and _history_nodes.has(file_settings.source_file):
|
||||
_remove_entries(file_settings.source_file)
|
||||
|
||||
_history.push_back(file_settings)
|
||||
_config.save_import_history(_history)
|
||||
_create_node_list_entry(file_settings, _history.size() - 1)
|
||||
|
||||
if _sort_by == SORT_BY_PATH:
|
||||
_trigger_sort()
|
||||
|
||||
no_history_warning.hide()
|
||||
loading_warning.hide()
|
||||
grid.get_parent().show()
|
||||
_is_busy = false
|
||||
|
||||
|
||||
func _on_entry_reimport_clicked(entry_index: int):
|
||||
if _is_busy:
|
||||
return
|
||||
_is_busy = true
|
||||
_import_requested_for = entry_index
|
||||
emit_signal("request_import", _history[entry_index])
|
||||
|
||||
|
||||
func _on_entry_edit_clicked(entry_index: int):
|
||||
if _is_busy:
|
||||
return
|
||||
emit_signal("request_edit", _history[entry_index])
|
||||
|
||||
|
||||
func _on_entry_remove_clicked(entry_index: int):
|
||||
if _is_busy:
|
||||
return
|
||||
_is_busy = true
|
||||
|
||||
_remove_item(entry_index)
|
||||
_config.save_import_history(_history)
|
||||
|
||||
if (_history.is_empty()):
|
||||
grid.get_parent().hide()
|
||||
no_history_warning.show()
|
||||
|
||||
_is_busy = false
|
||||
|
||||
|
||||
func _remove_item(entry_index: int):
|
||||
var entry = _history[entry_index]
|
||||
_remove_entries(entry.source_file, entry_index)
|
||||
|
||||
|
||||
# removes nodes and entry from history. If entry_index is not provided, all
|
||||
# entries for path are removed.
|
||||
func _remove_entries(source_file_path: String, entry_index: int = -1):
|
||||
var files_entries = _history_nodes[source_file_path]
|
||||
var indexes_to_remove = []
|
||||
|
||||
for f in files_entries:
|
||||
if entry_index == -1 or f.history_index == entry_index:
|
||||
_free_entry_nodes(f)
|
||||
_history_nodes_list.erase(f)
|
||||
|
||||
if entry_index != -1:
|
||||
files_entries.erase(f)
|
||||
_remove_from_history(f.history_index)
|
||||
return
|
||||
|
||||
indexes_to_remove.push_back(f.history_index)
|
||||
|
||||
for i in indexes_to_remove:
|
||||
_remove_from_history(i)
|
||||
|
||||
_history_nodes[source_file_path] = []
|
||||
|
||||
|
||||
func _remove_from_history(entry_index: int):
|
||||
var _already_adjusted = []
|
||||
# to avoid re-creating the whole nodes list, I just decrement
|
||||
# the index from items newer than the excluded one
|
||||
for index in range(entry_index + 1, _history.size()):
|
||||
if _already_adjusted.has(_history[index].source_file):
|
||||
continue
|
||||
_already_adjusted.push_back(_history[index].source_file)
|
||||
var nodes = _history_nodes[_history[index].source_file]
|
||||
for f in nodes:
|
||||
if f.history_index > entry_index:
|
||||
f.history_index -= 1
|
||||
f.actions_node.history_index = f.history_index
|
||||
|
||||
_history.remove_at(entry_index)
|
||||
|
||||
|
||||
func _free_entry_nodes(entry_history_node: Dictionary):
|
||||
entry_history_node.source_path_node.queue_free()
|
||||
entry_history_node.output_path_node.queue_free()
|
||||
entry_history_node.import_date_node.queue_free()
|
||||
entry_history_node.actions_node.queue_free()
|
||||
|
||||
|
||||
func _on_SortOptions_item_selected(index):
|
||||
if index == _sort_by:
|
||||
return
|
||||
|
||||
_trigger_sort(index)
|
||||
|
||||
|
||||
func _trigger_sort(sort_type: int = _sort_by):
|
||||
if sort_type == SORT_BY_DATE:
|
||||
_history_nodes_list.sort_custom(Callable(self,"_sort_by_date"))
|
||||
else:
|
||||
_history_nodes_list.sort_custom(Callable(self,"_sort_by_path"))
|
||||
_reorganise_nodes()
|
||||
_sort_by = sort_type
|
||||
|
||||
|
||||
func _sort_by_date(a, b):
|
||||
return a.timestamp < b.timestamp
|
||||
|
||||
|
||||
func _sort_by_path(a, b):
|
||||
return a.source_file > b.source_file
|
||||
|
||||
|
||||
func _reorganise_nodes():
|
||||
for entry in _history_nodes_list:
|
||||
grid.move_child(entry.source_path_node, INITIAL_GRID_INDEX + 1)
|
||||
grid.move_child(entry.output_path_node, INITIAL_GRID_INDEX + 2)
|
||||
grid.move_child(entry.import_date_node, INITIAL_GRID_INDEX + 3)
|
||||
grid.move_child(entry.actions_node, INITIAL_GRID_INDEX + 4)
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cyoin5ncul0fm"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/AsepriteWizard/animated_sprite/docks/sprite_frames_import_history.gd" id="1"]
|
||||
|
||||
[node name="SpriteFramesImportHistory" type="PanelContainer"]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="list actions" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
alignment = 2
|
||||
|
||||
[node name="divider" type="Label" parent="MarginContainer/VBoxContainer/list actions"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="sort_label" type="Label" parent="MarginContainer/VBoxContainer/list actions"]
|
||||
layout_mode = 2
|
||||
text = "Sort by:"
|
||||
|
||||
[node name="SortOptions" type="OptionButton" parent="MarginContainer/VBoxContainer/list actions"]
|
||||
layout_mode = 2
|
||||
item_count = 2
|
||||
selected = 0
|
||||
popup/item_0/text = "Date"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Name"
|
||||
popup/item_1/id = 1
|
||||
|
||||
[node name="loading_warning" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 6
|
||||
text = "Loading..."
|
||||
|
||||
[node name="no_history_warning" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 6
|
||||
text = "No import history"
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="MarginContainer/VBoxContainer/ScrollContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
columns = 4
|
||||
|
||||
[node name="source_label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Source File"
|
||||
|
||||
[node name="output_label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Output Folder"
|
||||
|
||||
[node name="date_label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Date"
|
||||
|
||||
[node name="actions_label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Actions"
|
||||
|
||||
[connection signal="item_selected" from="MarginContainer/VBoxContainer/list actions/SortOptions" to="." method="_on_SortOptions_item_selected"]
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
@tool
|
||||
extends Label
|
||||
|
||||
|
||||
func set_date(timestamp: String):
|
||||
self.text = timestamp
|
||||
# self.text = _format_date(timestamp)
|
||||
|
||||
|
||||
#func _format_date(timestamp: int) -> String:
|
||||
# var dt = Time.get_datetime_dict_from_system_from_unix_time(timestamp)
|
||||
# return "%04d-%02d-%02d %02d:%02d:%02d" % [dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/AsepriteWizard/animated_sprite/docks/wizard_nodes/import_date.gd" type="Script" id=1]
|
||||
|
||||
[node name="import_date" type="Label"]
|
||||
offset_left = 660.0
|
||||
offset_top = 39.0
|
||||
offset_right = 774.0
|
||||
offset_bottom = 53.0
|
||||
text = "2022-07-18 18:01"
|
||||
script = ExtResource( 1 )
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
@tool
|
||||
extends HBoxContainer
|
||||
|
||||
signal import_clicked(index)
|
||||
signal edit_clicked(index)
|
||||
signal removed_clicked(index)
|
||||
|
||||
var history_index = -1
|
||||
|
||||
|
||||
func _on_edit_pressed():
|
||||
emit_signal("edit_clicked", history_index)
|
||||
|
||||
|
||||
func _on_reimport_pressed():
|
||||
emit_signal("import_clicked", history_index)
|
||||
|
||||
|
||||
func _on_remove_pressed():
|
||||
emit_signal("removed_clicked", history_index)
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/AsepriteWizard/animated_sprite/docks/wizard_nodes/list_actions.gd" type="Script" id=1]
|
||||
|
||||
[node name="actions" type="HBoxContainer"]
|
||||
offset_left = 784.0
|
||||
offset_top = 34.0
|
||||
offset_right = 950.0
|
||||
offset_bottom = 58.0
|
||||
custom_constants/separation = 5
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="edit" type="Button" parent="."]
|
||||
offset_right = 36.0
|
||||
offset_bottom = 20.0
|
||||
size_flags_vertical = 0
|
||||
text = "Edit"
|
||||
|
||||
[node name="reimport" type="Button" parent="."]
|
||||
offset_left = 41.0
|
||||
offset_right = 97.0
|
||||
offset_bottom = 20.0
|
||||
size_flags_vertical = 0
|
||||
text = "Import"
|
||||
|
||||
[node name="remove_at" type="Button" parent="."]
|
||||
offset_left = 102.0
|
||||
offset_right = 166.0
|
||||
offset_bottom = 20.0
|
||||
size_flags_vertical = 0
|
||||
text = "Remove"
|
||||
|
||||
[connection signal="pressed" from="edit" to="." method="_on_edit_pressed"]
|
||||
[connection signal="pressed" from="reimport" to="." method="_on_reimport_pressed"]
|
||||
[connection signal="pressed" from="remove_at" to="." method="_on_remove_pressed"]
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene format=2]
|
||||
|
||||
[node name="output_path" type="LineEdit"]
|
||||
offset_left = 450.0
|
||||
offset_top = 34.0
|
||||
offset_right = 650.0
|
||||
offset_bottom = 58.0
|
||||
minimum_size = Vector2( 200, 0 )
|
||||
size_flags_vertical = 0
|
||||
text = "/some/output"
|
||||
align = 3
|
||||
editable = false
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
@tool
|
||||
extends LineEdit
|
||||
|
||||
|
||||
func set_entry(entry: Dictionary):
|
||||
self.text = entry.source_file
|
||||
self.tooltip_text = _format_hint(entry)
|
||||
|
||||
|
||||
func _format_hint(entry: Dictionary) -> String:
|
||||
return """Output filename/prefix: %s
|
||||
Ex. pattern: %s
|
||||
Split: %s
|
||||
Only visible: %s
|
||||
No Resource: %s
|
||||
""" % [
|
||||
entry.options.output_filename,
|
||||
entry.options.exception_pattern,
|
||||
"yes" if entry.options.export_mode else "no",
|
||||
"yes" if entry.options.only_visible_layers else "no",
|
||||
"yes" if entry.options.do_not_create_resource else "no",
|
||||
]
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/AsepriteWizard/animated_sprite/docks/wizard_nodes/source_path.gd" type="Script" id=1]
|
||||
|
||||
[node name="source_path" type="LineEdit"]
|
||||
offset_top = 34.0
|
||||
offset_right = 440.0
|
||||
offset_bottom = 58.0
|
||||
minimum_size = Vector2( 200, 0 )
|
||||
tooltip_text = "Output name / prefix: some_name
|
||||
Ex. Pattern: $_
|
||||
Split: Yes
|
||||
Only Visible: No
|
||||
No Resource: No"
|
||||
size_flags_vertical = 0
|
||||
text = "/some/very/long/source/path/to/test/field"
|
||||
editable = false
|
||||
script = ExtResource( 1 )
|
||||
129
Sprout/addons/AsepriteWizard/animated_sprite/import_plugin.gd
Normal file
129
Sprout/addons/AsepriteWizard/animated_sprite/import_plugin.gd
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
const result_codes = preload("../config/result_codes.gd")
|
||||
|
||||
var config
|
||||
var _sf_creator = preload("sprite_frames_creator.gd").new()
|
||||
var file_system: EditorFileSystem
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite SpriteFrames Importer"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["aseprite", "ase"]
|
||||
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "SpriteFrames"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 1.0
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return [
|
||||
{"name": "split_layers", "default_value": false},
|
||||
{"name": "exclude_layers_pattern", "default_value": ''},
|
||||
{"name": "only_visible_layers", "default_value": false},
|
||||
{
|
||||
"name": "sheet_type",
|
||||
"default_value": "Packed",
|
||||
"property_hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": get_sheet_type_hint_string()
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
static func replace_vars(pattern : String, vars : Dictionary):
|
||||
var result = pattern;
|
||||
for k in vars:
|
||||
var v = vars[k]
|
||||
result = result.replace("{%s}" % k, v)
|
||||
return result
|
||||
|
||||
|
||||
static func get_sheet_type_hint_string() -> String:
|
||||
var hint_string := "Packed"
|
||||
for number in [2, 4, 8, 16, 32]:
|
||||
hint_string += ",%s columns" % number
|
||||
hint_string += ",Strip"
|
||||
return hint_string
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var absolute_source_file = ProjectSettings.globalize_path(source_file)
|
||||
var absolute_save_path = ProjectSettings.globalize_path(save_path)
|
||||
|
||||
var source_path = source_file.substr(0, source_file.rfind('/'))
|
||||
var source_basename = source_file.substr(source_path.length()+1, -1)
|
||||
source_basename = source_basename.substr(0, source_basename.rfind('.'))
|
||||
|
||||
_sf_creator.init(config, file_system)
|
||||
|
||||
var export_mode = _sf_creator.LAYERS_EXPORT_MODE if options['split_layers'] else _sf_creator.FILE_EXPORT_MODE
|
||||
|
||||
var aseprite_opts = {
|
||||
"export_mode": export_mode,
|
||||
"exception_pattern": options['exclude_layers_pattern'],
|
||||
"only_visible_layers": options['only_visible_layers'],
|
||||
"output_filename": '' if export_mode == _sf_creator.FILE_EXPORT_MODE else '%s_' % source_basename,
|
||||
"column_count" : int(options['sheet_type']) if options['sheet_type'] != "Strip" else 128,
|
||||
"output_folder": source_path,
|
||||
}
|
||||
|
||||
var resources = await _sf_creator.create_resources(absolute_source_file, aseprite_opts)
|
||||
|
||||
if not resources.is_ok:
|
||||
printerr("ERROR - Could not import aseprite file: %s" % result_codes.get_error_message(resources.code))
|
||||
return FAILED
|
||||
|
||||
if export_mode == _sf_creator.LAYERS_EXPORT_MODE:
|
||||
# each layer is saved as one resource using base file name to prevent
|
||||
# collisions
|
||||
# the first layer will be saved in the default resource path to prevent
|
||||
# godot from keeping re-importing it
|
||||
for resource in resources.content:
|
||||
var resource_path = "%s.res" % resource.data_file.get_basename();
|
||||
var exit_code = ResourceSaver.save(resource.resource, resource_path)
|
||||
resource.resource.take_over_path(resource_path)
|
||||
|
||||
if exit_code != OK:
|
||||
printerr("ERROR - Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code))
|
||||
return FAILED
|
||||
|
||||
var resource = resources.content[0]
|
||||
var resource_path = "%s.res" % save_path
|
||||
var exit_code = ResourceSaver.save(resource.resource, resource_path)
|
||||
resource.resource.take_over_path(resource_path)
|
||||
|
||||
if exit_code != OK:
|
||||
printerr("ERROR - Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code))
|
||||
return FAILED
|
||||
return OK
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
@tool
|
||||
extends EditorInspectorPlugin
|
||||
|
||||
const ASInspectorDock = preload("./docks/animated_sprite_inspector_dock.tscn")
|
||||
|
||||
var config
|
||||
var file_system: EditorFileSystem
|
||||
|
||||
func _can_handle(object):
|
||||
return object is AnimatedSprite2D || object is AnimatedSprite3D
|
||||
|
||||
|
||||
func _parse_end(object):
|
||||
var dock = ASInspectorDock.instantiate()
|
||||
dock.sprite = object
|
||||
dock.config = config
|
||||
dock.file_system = file_system
|
||||
add_custom_control(dock)
|
||||
|
|
@ -0,0 +1,352 @@
|
|||
@tool
|
||||
extends RefCounted
|
||||
|
||||
var result_code = preload("../config/result_codes.gd")
|
||||
var _aseprite = preload("../aseprite/aseprite.gd").new()
|
||||
|
||||
enum {
|
||||
FILE_EXPORT_MODE,
|
||||
LAYERS_EXPORT_MODE
|
||||
}
|
||||
|
||||
var _config
|
||||
var _file_system: EditorFileSystem
|
||||
var _should_check_file_system := false
|
||||
|
||||
|
||||
func init(config, editor_file_system: EditorFileSystem = null):
|
||||
_config = config
|
||||
_file_system = editor_file_system
|
||||
_should_check_file_system = _file_system != null
|
||||
_aseprite.init(config)
|
||||
|
||||
|
||||
func _initial_checks(source: String, options: Dictionary) -> int:
|
||||
if not _aseprite.test_command():
|
||||
return result_code.ERR_ASEPRITE_CMD_NOT_FOUND
|
||||
|
||||
if not FileAccess.file_exists(source):
|
||||
return result_code.ERR_SOURCE_FILE_NOT_FOUND
|
||||
|
||||
if not DirAccess.dir_exists_absolute(options.output_folder):
|
||||
return result_code.ERR_OUTPUT_FOLDER_NOT_FOUND
|
||||
|
||||
return result_code.SUCCESS
|
||||
|
||||
|
||||
func create_animations(sprite: Node, options: Dictionary) -> void:
|
||||
var input_check = _initial_checks(options.source, options)
|
||||
|
||||
if input_check != result_code.SUCCESS:
|
||||
printerr(result_code.get_error_message(input_check))
|
||||
return
|
||||
|
||||
var result = await _create_animations_from_file(sprite, options)
|
||||
|
||||
if result != result_code.SUCCESS:
|
||||
printerr(result_code.get_error_message(result))
|
||||
|
||||
|
||||
func _create_animations_from_file(animated_sprite: Node, options: Dictionary) -> int:
|
||||
var output = _export_aseprite_file(options)
|
||||
|
||||
if not output.is_ok:
|
||||
return output.code
|
||||
|
||||
if _config.is_import_preset_enabled():
|
||||
_config.create_import_file(output.content)
|
||||
|
||||
await _scan_filesystem()
|
||||
|
||||
var sprite_frames_result = _create_sprite_frames(output.content)
|
||||
if not sprite_frames_result.is_ok:
|
||||
return sprite_frames_result.code
|
||||
|
||||
animated_sprite.frames = sprite_frames_result.content
|
||||
animated_sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
|
||||
if _config.should_remove_source_files():
|
||||
DirAccess.remove_absolute(output.content.data_file)
|
||||
|
||||
return result_code.SUCCESS
|
||||
|
||||
|
||||
func _export_aseprite_file(options: Dictionary) -> Dictionary:
|
||||
var output
|
||||
|
||||
if options.get("layer", "") == "":
|
||||
output = _aseprite.export_file(options.source, options.output_folder, options)
|
||||
else:
|
||||
output = _aseprite.export_layer(options.source, options.layer, options.output_folder, options)
|
||||
|
||||
if output.is_empty():
|
||||
return result_code.error(result_code.ERR_ASEPRITE_EXPORT_FAILED)
|
||||
|
||||
return result_code.result(output)
|
||||
|
||||
|
||||
func create_and_save_resources(source_file: String, options: Dictionary) -> int:
|
||||
var resources = await create_resources(source_file, options)
|
||||
if resources.is_ok:
|
||||
return _save_resources(resources.content)
|
||||
|
||||
return resources.code
|
||||
|
||||
|
||||
func create_resources(source_file: String, options = {}) -> Dictionary:
|
||||
var input_check = _initial_checks(source_file, options)
|
||||
|
||||
if input_check != result_code.SUCCESS:
|
||||
return result_code.error(input_check)
|
||||
|
||||
var output = _create_aseprite_output_files(source_file, options)
|
||||
|
||||
if not output.is_ok:
|
||||
return output
|
||||
|
||||
await _scan_filesystem()
|
||||
|
||||
var result = await _create_sprite_frames_from_source(output.content, options)
|
||||
|
||||
if not result.is_ok:
|
||||
return result
|
||||
|
||||
var should_remove_source = options.get("remove_source_files_allowed", false) and _config.should_remove_source_files()
|
||||
|
||||
if should_remove_source:
|
||||
_remove_source_files(result.content)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func _remove_source_files(source_files: Array):
|
||||
for s in source_files:
|
||||
DirAccess.remove_absolute(s.data_file)
|
||||
|
||||
await _scan_filesystem()
|
||||
|
||||
|
||||
func _create_aseprite_output_files(source_file: String, options: Dictionary):
|
||||
match options.get('export_mode', FILE_EXPORT_MODE):
|
||||
FILE_EXPORT_MODE:
|
||||
return result_code.result(
|
||||
[_aseprite.export_file(source_file, options.output_folder, options)]
|
||||
)
|
||||
LAYERS_EXPORT_MODE:
|
||||
var output = _aseprite.export_layers(source_file, options.output_folder, options)
|
||||
if output.is_empty():
|
||||
return result_code.error(result_code.ERR_NO_VALID_LAYERS_FOUND)
|
||||
return result_code.result(output)
|
||||
_:
|
||||
return result_code.error(result_code.ERR_UNKNOWN_EXPORT_MODE)
|
||||
|
||||
|
||||
func _create_sprite_frames_from_source(source_files: Array, options: Dictionary) -> Dictionary:
|
||||
var should_remove_source = options.get("remove_source_files_allowed", false) and _config.should_remove_source_files()
|
||||
|
||||
var resources = []
|
||||
|
||||
for o in source_files:
|
||||
if o.is_empty():
|
||||
return result_code.error(result_code.ERR_ASEPRITE_EXPORT_FAILED)
|
||||
|
||||
var resource = _create_sprite_frames(o)
|
||||
|
||||
if not resource.is_ok:
|
||||
return resource
|
||||
|
||||
resources.push_back({
|
||||
"data_file": o.data_file,
|
||||
"resource": resource.content,
|
||||
})
|
||||
|
||||
return result_code.result(resources)
|
||||
|
||||
|
||||
func _create_sprite_frames(data) -> Dictionary:
|
||||
var aseprite_resources = _load_aseprite_resources(data)
|
||||
if not aseprite_resources.is_ok:
|
||||
return aseprite_resources
|
||||
|
||||
return result_code.result(
|
||||
_create_sprite_frames_with_animations(
|
||||
aseprite_resources.content.metadata,
|
||||
aseprite_resources.content.texture
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
func _load_aseprite_resources(aseprite_data: Dictionary):
|
||||
var content_result = _load_json_content(aseprite_data.data_file)
|
||||
|
||||
if not content_result.is_ok:
|
||||
return content_result
|
||||
|
||||
var texture = _parse_texture_path(aseprite_data.sprite_sheet)
|
||||
|
||||
return result_code.result({
|
||||
"metadata": content_result.content,
|
||||
"texture": texture
|
||||
})
|
||||
|
||||
|
||||
func _load_json_content(source_file: String) -> Dictionary:
|
||||
var file = FileAccess.open(source_file, FileAccess.READ)
|
||||
if file == null:
|
||||
return result_code.error(file.get_open_error())
|
||||
var test_json_conv = JSON.new()
|
||||
test_json_conv.parse(file.get_as_text())
|
||||
|
||||
var content = test_json_conv.get_data()
|
||||
|
||||
if not _aseprite.is_valid_spritesheet(content):
|
||||
return result_code.error(result_code.ERR_INVALID_ASEPRITE_SPRITESHEET)
|
||||
|
||||
return result_code.result(content)
|
||||
|
||||
|
||||
func _save_resources(resources: Array) -> int:
|
||||
for resource in resources:
|
||||
var code = _save_resource(resource.resource, resource.data_file)
|
||||
if code != OK:
|
||||
return code
|
||||
return OK
|
||||
|
||||
|
||||
func _save_resource(resource, source_path: String) -> int:
|
||||
var save_path = "%s.%s" % [source_path.get_basename(), "res"]
|
||||
var code = ResourceSaver.save(resource, save_path, ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS)
|
||||
resource.take_over_path(save_path)
|
||||
return code
|
||||
|
||||
|
||||
func _create_sprite_frames_with_animations(content, texture) -> SpriteFrames:
|
||||
var frame_cache = {}
|
||||
var frames = _aseprite.get_content_frames(content)
|
||||
var sprite_frames := SpriteFrames.new()
|
||||
sprite_frames.remove_animation("default")
|
||||
|
||||
if content.meta.has("frameTags") and content.meta.frameTags.size() > 0:
|
||||
for tag in content.meta.frameTags:
|
||||
var selected_frames = frames.slice(tag.from, tag.to + 1)
|
||||
_add_animation_frames(sprite_frames, tag.name, selected_frames, texture, tag.direction, frame_cache)
|
||||
else:
|
||||
_add_animation_frames(sprite_frames, "default", frames, texture)
|
||||
|
||||
return sprite_frames
|
||||
|
||||
|
||||
func _add_animation_frames(
|
||||
sprite_frames: SpriteFrames,
|
||||
anim_name: String,
|
||||
frames : Array,
|
||||
texture,
|
||||
direction = 'forward',
|
||||
frame_cache = {}
|
||||
):
|
||||
var animation_name := anim_name
|
||||
var is_loopable = _is_loop_config_enabled()
|
||||
|
||||
var loop_prefix := _loop_config_prefix()
|
||||
if animation_name.begins_with(loop_prefix):
|
||||
animation_name = anim_name.trim_prefix(loop_prefix)
|
||||
is_loopable = not is_loopable
|
||||
|
||||
sprite_frames.add_animation(animation_name)
|
||||
|
||||
var min_duration = _get_min_duration(frames)
|
||||
var fps = _calculate_fps(min_duration)
|
||||
|
||||
if direction == 'reverse':
|
||||
frames.reverse()
|
||||
|
||||
for frame in frames:
|
||||
_add_to_sprite_frames(sprite_frames, animation_name, texture, frame, min_duration, frame_cache)
|
||||
|
||||
if direction == 'pingpong':
|
||||
frames.remove_at(frames.size() - 1)
|
||||
if is_loopable:
|
||||
frames.remove_at(0)
|
||||
frames.reverse()
|
||||
|
||||
for frame in frames:
|
||||
_add_to_sprite_frames(sprite_frames, animation_name, texture, frame, min_duration, frame_cache)
|
||||
|
||||
sprite_frames.set_animation_loop(animation_name, is_loopable)
|
||||
sprite_frames.set_animation_speed(animation_name, fps)
|
||||
|
||||
|
||||
func _calculate_fps(min_duration: int) -> float:
|
||||
return ceil(1000.0 / min_duration)
|
||||
|
||||
|
||||
func _get_min_duration(frames) -> int:
|
||||
var min_duration = 100000
|
||||
for frame in frames:
|
||||
if frame.duration < min_duration:
|
||||
min_duration = frame.duration
|
||||
return min_duration
|
||||
|
||||
|
||||
func _parse_texture_path(path):
|
||||
return ResourceLoader.load(path, 'Image', ResourceLoader.CACHE_MODE_REPLACE)
|
||||
|
||||
|
||||
func _add_to_sprite_frames(
|
||||
sprite_frames,
|
||||
animation_name: String,
|
||||
texture,
|
||||
frame: Dictionary,
|
||||
min_duration: int,
|
||||
frame_cache: Dictionary
|
||||
):
|
||||
var atlas : AtlasTexture = _create_atlastexture_from_frame(texture, frame, sprite_frames, frame_cache)
|
||||
|
||||
var number_of_sprites = ceil(frame.duration / min_duration)
|
||||
for _i in range(number_of_sprites):
|
||||
sprite_frames.add_frame(animation_name, atlas)
|
||||
|
||||
|
||||
func _create_atlastexture_from_frame(
|
||||
image,
|
||||
frame_data,
|
||||
sprite_frames: SpriteFrames,
|
||||
frame_cache: Dictionary
|
||||
) -> AtlasTexture:
|
||||
var frame = frame_data.frame
|
||||
var region := Rect2(frame.x, frame.y, frame.w, frame.h)
|
||||
var key := "%s_%s_%s_%s" % [frame.x, frame.y, frame.w, frame.h]
|
||||
|
||||
var texture = frame_cache.get(key)
|
||||
|
||||
if texture != null and texture.atlas == image:
|
||||
return texture
|
||||
|
||||
var atlas_texture := AtlasTexture.new()
|
||||
atlas_texture.atlas = image
|
||||
atlas_texture.region = region
|
||||
|
||||
frame_cache[key] = atlas_texture
|
||||
|
||||
return atlas_texture
|
||||
|
||||
|
||||
func _scan_filesystem():
|
||||
_file_system.scan()
|
||||
await _file_system.filesystem_changed
|
||||
|
||||
|
||||
func list_layers(file: String, only_visibles = false) -> Array:
|
||||
return _aseprite.list_layers(file, only_visibles)
|
||||
|
||||
|
||||
func _get_file_basename(file_path: String) -> String:
|
||||
return file_path.get_file().trim_suffix('.%s' % file_path.get_extension())
|
||||
|
||||
|
||||
func _loop_config_prefix() -> String:
|
||||
return _config.get_animation_loop_exception_prefix()
|
||||
|
||||
|
||||
func _is_loop_config_enabled() -> bool:
|
||||
return _config.is_default_animation_loop_enabled()
|
||||
Loading…
Add table
Add a link
Reference in a new issue