Add addons
This commit is contained in:
parent
2c862b2235
commit
3367bad24f
527 changed files with 36197 additions and 0 deletions
|
|
@ -0,0 +1,281 @@
|
|||
@tool
|
||||
extends PanelContainer
|
||||
|
||||
const wizard_config = preload("../../config/wizard_config.gd")
|
||||
const result_code = preload("../../config/result_codes.gd")
|
||||
|
||||
const AnimationCreator = preload("../animation_creator.gd")
|
||||
const SpriteAnimationCreator = preload("../sprite_animation_creator.gd")
|
||||
const TextureRectAnimationCreator = preload("../texture_rect_animation_creator.gd")
|
||||
|
||||
var animation_creator: AnimationCreator
|
||||
|
||||
var scene: Node
|
||||
var target_node: Node
|
||||
|
||||
var config
|
||||
var file_system: EditorFileSystem
|
||||
|
||||
var _layer: String = ""
|
||||
var _source: String = ""
|
||||
var _animation_player_path: 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 _options_field = $margin/VBoxContainer/animation_player/options
|
||||
@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
|
||||
@onready var _cleanup_hide_unused_nodes = $margin/VBoxContainer/options/auto_visible_track/CheckButton
|
||||
|
||||
|
||||
func _ready():
|
||||
var cfg = wizard_config.load_config(target_node)
|
||||
if cfg == null:
|
||||
_load_default_config()
|
||||
else:
|
||||
_load_config(cfg)
|
||||
|
||||
if target_node is Sprite2D || target_node is Sprite3D:
|
||||
animation_creator = SpriteAnimationCreator.new()
|
||||
if target_node is TextureRect:
|
||||
animation_creator = TextureRectAnimationCreator.new()
|
||||
|
||||
animation_creator.init(config, file_system)
|
||||
|
||||
|
||||
func _load_config(cfg):
|
||||
if cfg.has("source"):
|
||||
_set_source(cfg.source)
|
||||
|
||||
if cfg.has("player"):
|
||||
_options_field.clear()
|
||||
_set_animation_player(cfg.player)
|
||||
|
||||
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", "")
|
||||
_cleanup_hide_unused_nodes.button_pressed = cfg.get("set_vis_track", config.is_set_visible_track_automatically_enabled())
|
||||
|
||||
_set_options_visible(cfg.get("op_exp", false))
|
||||
|
||||
|
||||
func _load_default_config():
|
||||
_ex_pattern_field.text = config.get_default_exclusion_pattern()
|
||||
_cleanup_hide_unused_nodes.button_pressed = config.is_set_visible_track_automatically_enabled()
|
||||
_set_options_visible(false)
|
||||
|
||||
|
||||
func _set_source(source):
|
||||
_source = source
|
||||
_source_field.text = _source
|
||||
_source_field.tooltip_text = _source
|
||||
|
||||
|
||||
func _set_animation_player(player):
|
||||
_animation_player_path = player
|
||||
_options_field.add_item(_animation_player_path)
|
||||
|
||||
|
||||
func _set_layer(layer):
|
||||
_layer = layer
|
||||
_layer_field.add_item(_layer)
|
||||
|
||||
|
||||
func _on_options_button_down():
|
||||
_refresh_animation_players()
|
||||
|
||||
|
||||
func _refresh_animation_players():
|
||||
var animation_players = []
|
||||
var root = get_tree().get_edited_scene_root()
|
||||
_find_animation_players(root, root, animation_players)
|
||||
|
||||
var current = 0
|
||||
_options_field.clear()
|
||||
_options_field.add_item("[empty]")
|
||||
|
||||
for ap in animation_players:
|
||||
_options_field.add_item(ap)
|
||||
if ap.get_concatenated_names() == _animation_player_path:
|
||||
current = _options_field.get_item_count() - 1
|
||||
|
||||
_options_field.select(current)
|
||||
|
||||
|
||||
func _find_animation_players(root: Node, node: Node, players: Array):
|
||||
if node is AnimationPlayer:
|
||||
players.push_back(root.get_path_to(node))
|
||||
|
||||
for c in node.get_children():
|
||||
_find_animation_players(root, c, players)
|
||||
|
||||
|
||||
func _on_options_item_selected(index):
|
||||
if index == 0:
|
||||
_animation_player_path = ""
|
||||
return
|
||||
_animation_player_path = _options_field.get_item_text(index)
|
||||
_save_config()
|
||||
|
||||
|
||||
func _on_layer_button_down():
|
||||
if _source == "":
|
||||
_show_message("Please. Select source file first.")
|
||||
return
|
||||
|
||||
var layers = animation_creator.list_layers(ProjectSettings.globalize_path(_source))
|
||||
var current = 0
|
||||
_layer_field.clear()
|
||||
_layer_field.add_item("[all]")
|
||||
|
||||
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 _animation_player_path == "" or not root.has_node(_animation_player_path):
|
||||
_show_message("AnimationPlayer not found")
|
||||
_importing = false
|
||||
return
|
||||
|
||||
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,
|
||||
"cleanup_hide_unused_nodes": _cleanup_hide_unused_nodes.button_pressed,
|
||||
"layer": _layer
|
||||
}
|
||||
|
||||
_save_config()
|
||||
|
||||
await animation_creator.create_animations(target_node, root.get_node(_animation_player_path), options)
|
||||
_importing = false
|
||||
|
||||
|
||||
func _save_config():
|
||||
var cfg := {
|
||||
"player": _animation_player_path,
|
||||
"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,
|
||||
}
|
||||
|
||||
if _cleanup_hide_unused_nodes.button_pressed != config.is_set_visible_track_automatically_enabled():
|
||||
cfg["set_vis_track"] = _cleanup_hide_unused_nodes.button_pressed
|
||||
|
||||
wizard_config.save_config(target_node, config.is_use_metadata_enabled(), cfg)
|
||||
|
||||
|
||||
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,181 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://biyshalfalqqw"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/AsepriteWizard/animation_player/docks/animation_player_inspector_dock.gd" id="1"]
|
||||
|
||||
[node name="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="animation_player" type="HBoxContainer" parent="margin/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "AnimationPlayer node where animations should be added to."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/animation_player"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "AnimationPlayer"
|
||||
|
||||
[node name="options" type="OptionButton" parent="margin/VBoxContainer/animation_player"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
item_count = 1
|
||||
selected = 0
|
||||
popup/item_0/text = "[empty]"
|
||||
popup/item_0/id = 0
|
||||
|
||||
[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="auto_visible_track" type="HBoxContainer" parent="margin/VBoxContainer/options"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "If active, it will automatically determine unused Sprite2D and Sprite3D nodes in each animation and hide them."
|
||||
|
||||
[node name="Label" type="Label" parent="margin/VBoxContainer/options/auto_visible_track"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 2.0
|
||||
text = "Hide unused sprites"
|
||||
|
||||
[node name="CheckButton" type="CheckButton" parent="margin/VBoxContainer/options/auto_visible_track"]
|
||||
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="button_down" from="margin/VBoxContainer/animation_player/options" to="." method="_on_options_button_down"]
|
||||
[connection signal="item_selected" from="margin/VBoxContainer/animation_player/options" to="." method="_on_options_item_selected"]
|
||||
[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"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue