This commit is contained in:
Eric Vande Voort
2025-01-07 16:10:03 -06:00
commit 7eb0dea424
147 changed files with 9096 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
@tool
extends "../base_inspector_dock.gd"
var sprite_frames_creator = preload("../../../creators/sprite_frames/sprite_frames_creator.gd").new()
func _get_available_layers(global_source_path: String) -> Array:
return sprite_frames_creator.list_layers(global_source_path)
func _get_available_slices(global_source_path: String) -> Array:
return sprite_frames_creator.list_slices(global_source_path)
func _do_import():
var root = get_tree().get_edited_scene_root()
var source_path = ProjectSettings.globalize_path(_source)
var options = {
"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()
var aseprite_output = _aseprite_file_exporter.generate_aseprite_file(source_path, options)
if not aseprite_output.is_ok:
var error = result_code.get_error_message(aseprite_output.code)
printerr(error)
_show_message(error)
return
file_system.scan()
await file_system.filesystem_changed
sprite_frames_creator.create_animations(target_node, aseprite_output.content, { "slice": _slice })
wizard_config.set_source_hash(target_node, FileAccess.get_md5(source_path))
_handle_cleanup(aseprite_output.content)

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://vej7yqkbtd5f"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/animated_sprite/animated_sprite_inspector_dock.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://uxm7b02wry10" path="res://addons/AsepriteWizard/interface/docks/dock_fields.tscn" id="2_2ilip"]
[node name="animated_sprite_inspector_dock" type="PanelContainer"]
offset_right = 14.0
offset_bottom = 14.0
script = ExtResource("1")
[node name="dock_fields" parent="." instance=ExtResource("2_2ilip")]
layout_mode = 2

View File

@@ -0,0 +1,13 @@
@tool
extends EditorInspectorPlugin
const ASInspectorDock = preload("./animated_sprite_inspector_dock.tscn")
func _can_handle(object):
return object is AnimatedSprite2D || object is AnimatedSprite3D
func _parse_end(object):
var dock = ASInspectorDock.instantiate()
dock.target_node = object
add_custom_control(dock)

View File

@@ -0,0 +1,429 @@
@tool
extends PanelContainer
const wizard_config = preload("../../config/wizard_config.gd")
const result_code = preload("../../config/result_codes.gd")
var _aseprite_file_exporter = preload("../../aseprite/file_exporter.gd").new()
var config = preload("../../config/config.gd").new()
var scene: Node
var target_node: Node
var file_system: EditorFileSystem = EditorInterface.get_resource_filesystem()
var _layer: String = ""
var _slice: String = ""
var _source: String = ""
var _file_dialog_aseprite: EditorFileDialog
var _output_folder_dialog: EditorFileDialog
var _importing := false
var _output_folder := ""
var _out_folder_default := "[Same as scene]"
var _layer_default := "[all]"
var _interface_section_state
@onready var _section_title := $dock_fields/VBoxContainer/title as Button
# general
@onready var _source_field := $dock_fields/VBoxContainer/source/button as Button
# layers
@onready var _layer_section_header := $dock_fields/VBoxContainer/extra/sections/layers/section_header as Button
@onready var _layer_section_container := $dock_fields/VBoxContainer/extra/sections/layers/section_content as MarginContainer
@onready var _layer_field := $dock_fields/VBoxContainer/extra/sections/layers/section_content/content/layer/options as OptionButton
@onready var _visible_layers_field := $dock_fields/VBoxContainer/extra/sections/layers/section_content/content/visible_layers/CheckBox as CheckBox
@onready var _ex_pattern_field := $dock_fields/VBoxContainer/extra/sections/layers/section_content/content/ex_pattern/LineEdit as LineEdit
# slice
@onready var _slice_section_header := $dock_fields/VBoxContainer/extra/sections/slices/section_header as Button
@onready var _slice_section_container := $dock_fields/VBoxContainer/extra/sections/slices/section_content as MarginContainer
@onready var _slice_field := $dock_fields/VBoxContainer/extra/sections/slices/section_content/content/slice/options as OptionButton
# output
@onready var _output_section_header := $dock_fields/VBoxContainer/extra/sections/output/section_header as Button
@onready var _output_section_container := $dock_fields/VBoxContainer/extra/sections/output/section_content as MarginContainer
@onready var _out_folder_field := $dock_fields/VBoxContainer/extra/sections/output/section_content/content/out_folder/button as Button
@onready var _out_filename_field := $dock_fields/VBoxContainer/extra/sections/output/section_content/content/out_filename/LineEdit as LineEdit
@onready var _import_button := $dock_fields/VBoxContainer/import as Button
const INTERFACE_SECTION_KEY_LAYER = "layer_section"
const INTERFACE_SECTION_KEY_SLICE = "slice_section"
const INTERFACE_SECTION_KEY_OUTPUT = "output_section"
@onready var _expandable_sections = {
INTERFACE_SECTION_KEY_LAYER: { "header": _layer_section_header, "content": _layer_section_container},
INTERFACE_SECTION_KEY_SLICE: { "header": _slice_section_header, "content": _slice_section_container},
INTERFACE_SECTION_KEY_OUTPUT: { "header": _output_section_header, "content": _output_section_container},
}
func _ready():
_pre_setup()
_setup_interface()
_setup_config()
_setup_field_listeners()
_setup()
_check_for_changes()
func _check_for_changes():
if not _source or _source == "":
return
var saved_hash = wizard_config.get_source_hash(target_node)
if saved_hash == "":
return
if saved_hash != FileAccess.get_md5(_source):
$dock_fields.show_source_change_warning()
func _setup_interface():
_hide_fields()
_show_specific_fields()
var cfg = wizard_config.load_interface_config(target_node)
_interface_section_state = cfg
_section_title.add_theme_stylebox_override("normal", _section_title.get_theme_stylebox("hover"))
for key in _expandable_sections:
_adjust_section_visibility(key)
func _setup_config():
var cfg = wizard_config.load_config(target_node)
if cfg == null:
_load_common_default_config()
else:
_load_common_config(cfg)
func _load_common_config(cfg):
if cfg.has("source"):
_set_source(cfg.source)
if cfg.get("layer", "") != "":
_layer_field.clear()
_set_layer(cfg.layer)
if cfg.get("slice", "") != "":
_slice_field.clear()
_set_slice(cfg.slice)
_set_out_folder(cfg.get("o_folder", ""))
_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", "")
_load_config(cfg)
func _load_common_default_config():
_ex_pattern_field.text = config.get_default_exclusion_pattern()
_visible_layers_field.button_pressed = config.should_include_only_visible_layers_by_default()
#_cleanup_hide_unused_nodes.button_pressed = config.is_set_visible_track_automatically_enabled()
_load_default_config()
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 _set_slice(slice):
_slice = slice
_slice_field.add_item(_slice)
func _set_out_folder(path):
_output_folder = path
_out_folder_field.text = _output_folder if _output_folder != "" else _out_folder_default
_out_folder_field.tooltip_text = _out_folder_field.text
func _toggle_section_visibility(key: String) -> void:
_interface_section_state[key] = not _interface_section_state.get(key, false)
_adjust_section_visibility(key)
wizard_config.save_interface_config(target_node, _interface_section_state)
func _adjust_section_visibility(key: String) -> void:
var section = _expandable_sections[key]
var is_visible = _interface_section_state.get(key, false)
_adjust_icon(section.header, is_visible)
section.content.visible = is_visible
func _adjust_icon(section: Button, is_visible: bool = true) -> void:
var icon_name = "GuiTreeArrowDown" if is_visible else "GuiTreeArrowRight"
section.icon = get_theme_icon(icon_name, "EditorIcons")
func _setup_field_listeners():
_layer_section_header.button_down.connect(_on_layer_header_button_down)
_slice_section_header.button_down.connect(_on_slice_header_button_down)
_output_section_header.button_down.connect(_on_output_header_button_down)
_source_field.pressed.connect(_on_source_pressed)
_source_field.aseprite_file_dropped.connect(_on_source_aseprite_file_dropped)
_layer_field.button_down.connect(_on_layer_button_down)
_layer_field.item_selected.connect(_on_layer_item_selected)
_slice_field.button_down.connect(_on_slice_button_down)
_slice_field.item_selected.connect(_on_slice_item_selected)
_out_folder_field.dir_dropped.connect(_on_out_dir_dropped)
_out_folder_field.pressed.connect(_on_out_folder_pressed)
_import_button.pressed.connect(_on_import_pressed)
func _on_layer_header_button_down():
_toggle_section_visibility(INTERFACE_SECTION_KEY_LAYER)
func _on_slice_header_button_down():
_toggle_section_visibility(INTERFACE_SECTION_KEY_SLICE)
func _on_output_header_button_down():
_toggle_section_visibility(INTERFACE_SECTION_KEY_OUTPUT)
func _on_layer_button_down():
if _source == "":
_show_message("Please. Select source file first.")
return
var layers = _get_available_layers(ProjectSettings.globalize_path(_source))
_populate_options_field(_layer_field, layers, _layer)
func _on_layer_item_selected(index):
if index == 0:
_layer = ""
return
_layer = _layer_field.get_item_text(index)
_save_config()
func _on_slice_item_selected(index):
if index == 0:
_slice = ""
return
_slice = _slice_field.get_item_text(index)
_save_config()
func _on_slice_button_down():
if _source == "":
_show_message("Please, select source file first.")
return
var slices = _get_available_slices(ProjectSettings.globalize_path(_source))
var current = 0
_slice_field.clear()
_slice_field.add_item(_layer_default)
for s in slices:
if s == "":
continue
_slice_field.add_item(s)
if s == _slice:
current = _slice_field.get_item_count() - 1
_slice_field.select(current)
func _on_source_pressed():
_open_source_dialog()
##
## Save current import options to node metadata
##
func _save_config():
var child_config = _get_current_field_values()
var cfg := {
"source": _source,
"layer": _layer,
"slice": _slice,
"o_folder": _output_folder,
"o_name": _out_filename_field.text,
"only_visible": _visible_layers_field.button_pressed,
"o_ex_p": _ex_pattern_field.text,
}
for c in child_config:
cfg[c] = child_config[c]
wizard_config.save_config(target_node, cfg)
func _get_import_options(default_folder: String):
return {
"output_folder": _output_folder if _output_folder != "" else default_folder,
"exception_pattern": _ex_pattern_field.text,
"only_visible_layers": _visible_layers_field.button_pressed,
"output_filename": _out_filename_field.text,
"layer": _layer
}
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 = ProjectSettings.globalize_path(_source.get_base_dir())
_file_dialog_aseprite.popup_centered_ratio()
func _create_aseprite_file_selection():
var file_dialog = EditorFileDialog.new()
file_dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILE
file_dialog.access = EditorFileDialog.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 _on_source_aseprite_file_dropped(path):
_set_source(path)
_save_config()
## Helper method to populate field with values
func _populate_options_field(field: OptionButton, values: Array, current_name: String):
var current = 0
field.clear()
field.add_item("[all]")
for v in values:
if v == "":
continue
field.add_item(v)
if v == current_name:
current = field.get_item_count() - 1
field.select(current)
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 = EditorFileDialog.new()
file_dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_DIR
file_dialog.access = EditorFileDialog.ACCESS_RESOURCES
file_dialog.connect("dir_selected",Callable(self,"_on_output_folder_selected"))
return file_dialog
func _on_output_folder_selected(path):
_set_out_folder(path)
_output_folder_dialog.queue_free()
func _on_out_dir_dropped(path):
_set_out_folder(path)
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 _notify_aseprite_error(aseprite_error_code):
var error = result_code.get_error_message(aseprite_error_code)
printerr(error)
_show_message(error)
func _handle_cleanup(aseprite_content):
if config.should_remove_source_files():
DirAccess.remove_absolute(aseprite_content.data_file)
file_system.call_deferred("scan")
func _on_import_pressed():
if _importing:
return
_importing = true
if _source == "":
_show_message("Aseprite file not selected")
_importing = false
return
await _do_import()
_importing = false
$dock_fields.hide_source_change_warning()
EditorInterface.save_scene()
# This is a little bit leaky as this base scene contains fields only relevant to animation players.
# However, this is the simplest thing I can do without overcomplicating stuff.
func _hide_fields():
$dock_fields/VBoxContainer/modes.hide()
$dock_fields/VBoxContainer/animation_player.hide()
$dock_fields/VBoxContainer/extra/sections/animation.hide()
## this will be called before base class does its setup
func _pre_setup():
pass
## this will be called after base class setup is complete
func _setup():
pass
func _load_default_config():
pass
func _load_config(cfg: Dictionary):
pass
## Override to return available layers
func _get_available_layers(global_source_path: String) -> Array:
return []
## Override to return available slices
func _get_available_slices(global_source_path: String) -> Array:
return []
## Override this method for extra import options to add to node metadata
func _get_current_field_values() -> Dictionary:
return {}
func _do_import():
pass
func _show_specific_fields() -> void:
pass

View File

@@ -0,0 +1,345 @@
[gd_scene load_steps=8 format=3 uid="uid://ljeu0l1ld6v5"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/base_inspector_dock.gd" id="1_0bpq8"]
[ext_resource type="PackedScene" uid="uid://x1f1t87m582u" path="res://addons/AsepriteWizard/interface/shared/animation_player_drop_button.tscn" id="2_pge1b"]
[ext_resource type="PackedScene" uid="uid://dj1uo3blocr8e" path="res://addons/AsepriteWizard/interface/shared/source_drop_button.tscn" id="3_nt1oj"]
[ext_resource type="PackedScene" uid="uid://cwvgnm3o7eed2" path="res://addons/AsepriteWizard/interface/shared/dir_drop_button.tscn" id="4_r7t2l"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x6usu"]
content_margin_left = 4.0
content_margin_top = 4.0
content_margin_right = 4.0
content_margin_bottom = 4.0
bg_color = Color(0.225, 0.225, 0.225, 0.6)
corner_radius_top_left = 3
corner_radius_top_right = 3
corner_radius_bottom_right = 3
corner_radius_bottom_left = 3
corner_detail = 5
[sub_resource type="Image" id="Image_46k7x"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
"height": 16,
"mipmaps": false,
"width": 16
}
[sub_resource type="ImageTexture" id="ImageTexture_dxtgh"]
image = SubResource("Image_46k7x")
[node name="base_inspector_dock" type="PanelContainer"]
offset_right = 14.0
offset_bottom = 14.0
script = ExtResource("1_0bpq8")
[node name="margin" type="MarginContainer" parent="."]
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="margin"]
layout_mode = 2
[node name="title" type="Button" parent="margin/VBoxContainer"]
layout_mode = 2
focus_mode = 0
theme_override_styles/normal = SubResource("StyleBoxFlat_x6usu")
button_mask = 0
text = "Aseprite"
[node name="section_title" type="PanelContainer" parent="margin/VBoxContainer"]
visible = false
layout_mode = 2
size_flags_horizontal = 3
[node name="HBoxContainer" type="HBoxContainer" parent="margin/VBoxContainer/section_title"]
layout_mode = 2
alignment = 1
[node name="icon" type="TextureRect" parent="margin/VBoxContainer/section_title/HBoxContainer"]
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
[node name="title" type="Label" parent="margin/VBoxContainer/section_title/HBoxContainer"]
layout_mode = 2
text = "Aseprite"
horizontal_alignment = 1
[node name="modes" type="HBoxContainer" parent="margin/VBoxContainer"]
layout_mode = 2
tooltip_text = "Import mode.
Animation mode (default): set spritesheet as texture and imports animations to the selected AnimationPlayer.
Image mode: Import only first frame and set as texture."
[node name="Label" type="Label" parent="margin/VBoxContainer/modes"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Mode"
[node name="options" type="OptionButton" parent="margin/VBoxContainer/modes"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
item_count = 2
selected = 0
popup/item_0/text = "Animation"
popup/item_0/id = 0
popup/item_1/text = "Image"
popup/item_1/id = 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" parent="margin/VBoxContainer/animation_player" instance=ExtResource("2_pge1b")]
layout_mode = 2
[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" parent="margin/VBoxContainer/source" instance=ExtResource("3_nt1oj")]
layout_mode = 2
[node name="extra" type="MarginContainer" parent="margin/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 10
[node name="sections" type="VBoxContainer" parent="margin/VBoxContainer/extra"]
layout_mode = 2
[node name="layers" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections"]
layout_mode = 2
[node name="section_header" type="Button" parent="margin/VBoxContainer/extra/sections/layers"]
layout_mode = 2
focus_mode = 0
text = "Layers"
icon = SubResource("ImageTexture_dxtgh")
alignment = 0
[node name="section_content" type="MarginContainer" parent="margin/VBoxContainer/extra/sections/layers"]
visible = false
layout_mode = 2
theme_override_constants/margin_left = 10
[node name="content" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections/layers/section_content"]
layout_mode = 2
[node name="layer" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/layers/section_content/content"]
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/extra/sections/layers/section_content/content/layer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Layer"
[node name="options" type="OptionButton" parent="margin/VBoxContainer/extra/sections/layers/section_content/content/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="ex_pattern" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/layers/section_content/content"]
layout_mode = 2
tooltip_text = "Exclude layers with name matching this pattern (regex)."
[node name="Label" type="Label" parent="margin/VBoxContainer/extra/sections/layers/section_content/content/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/extra/sections/layers/section_content/content/ex_pattern"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
[node name="visible_layers" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/layers/section_content/content"]
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/extra/sections/layers/section_content/content/visible_layers"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Only Visible Layers"
[node name="CheckBox" type="CheckBox" parent="margin/VBoxContainer/extra/sections/layers/section_content/content/visible_layers"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "On"
[node name="slices" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections"]
layout_mode = 2
[node name="section_header" type="Button" parent="margin/VBoxContainer/extra/sections/slices"]
layout_mode = 2
focus_mode = 0
text = "Slices"
icon = SubResource("ImageTexture_dxtgh")
alignment = 0
[node name="section_content" type="MarginContainer" parent="margin/VBoxContainer/extra/sections/slices"]
visible = false
layout_mode = 2
theme_override_constants/margin_left = 10
[node name="content" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections/slices/section_content"]
layout_mode = 2
[node name="slice" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/slices/section_content/content"]
layout_mode = 2
tooltip_text = "Aseprite slice to be used in the animation. By default, the whole file is included."
[node name="Label" type="Label" parent="margin/VBoxContainer/extra/sections/slices/section_content/content/slice"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Slice"
[node name="options" type="OptionButton" parent="margin/VBoxContainer/extra/sections/slices/section_content/content/slice"]
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="animation" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections"]
layout_mode = 2
[node name="section_header" type="Button" parent="margin/VBoxContainer/extra/sections/animation"]
layout_mode = 2
focus_mode = 0
text = "Animation"
icon = SubResource("ImageTexture_dxtgh")
alignment = 0
[node name="section_content" type="MarginContainer" parent="margin/VBoxContainer/extra/sections/animation"]
visible = false
layout_mode = 2
theme_override_constants/margin_left = 10
[node name="content" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections/animation/section_content"]
layout_mode = 2
[node name="keep_length" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/animation/section_content/content"]
layout_mode = 2
tooltip_text = "When this is active the animation length won't be adjusted if other properties were added and the resulting imported animation is shorter."
[node name="Label" type="Label" parent="margin/VBoxContainer/extra/sections/animation/section_content/content/keep_length"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Keep Manual Animation Length"
[node name="CheckBox" type="CheckBox" parent="margin/VBoxContainer/extra/sections/animation/section_content/content/keep_length"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "On"
[node name="auto_visible_track" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/animation/section_content/content"]
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/extra/sections/animation/section_content/content/auto_visible_track"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Hide Unused Sprites"
[node name="CheckBox" type="CheckBox" parent="margin/VBoxContainer/extra/sections/animation/section_content/content/auto_visible_track"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "On"
[node name="output" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections"]
layout_mode = 2
[node name="section_header" type="Button" parent="margin/VBoxContainer/extra/sections/output"]
layout_mode = 2
focus_mode = 0
text = "Output"
icon = SubResource("ImageTexture_dxtgh")
alignment = 0
[node name="section_content" type="MarginContainer" parent="margin/VBoxContainer/extra/sections/output"]
visible = false
layout_mode = 2
theme_override_constants/margin_left = 10
[node name="content" type="VBoxContainer" parent="margin/VBoxContainer/extra/sections/output/section_content"]
layout_mode = 2
[node name="out_folder" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/output/section_content/content"]
layout_mode = 2
tooltip_text = "Location where the spritesheet file should be saved."
[node name="Label" type="Label" parent="margin/VBoxContainer/extra/sections/output/section_content/content/out_folder"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "Output Folder"
[node name="button" parent="margin/VBoxContainer/extra/sections/output/section_content/content/out_folder" instance=ExtResource("4_r7t2l")]
layout_mode = 2
[node name="out_filename" type="HBoxContainer" parent="margin/VBoxContainer/extra/sections/output/section_content/content"]
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/extra/sections/output/section_content/content/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/extra/sections/output/section_content/content/out_filename"]
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="item_selected" from="margin/VBoxContainer/modes/options" to="." method="_on_modes_item_selected"]
[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="node_dropped" from="margin/VBoxContainer/animation_player/options" to="." method="_on_animation_player_node_dropped"]
[connection signal="aseprite_file_dropped" from="margin/VBoxContainer/source/button" to="." method="_on_source_aseprite_file_dropped"]
[connection signal="pressed" from="margin/VBoxContainer/source/button" to="." method="_on_source_pressed"]
[connection signal="button_down" from="margin/VBoxContainer/extra/sections/layers/section_header" to="." method="_on_layer_header_button_down"]
[connection signal="button_down" from="margin/VBoxContainer/extra/sections/layers/section_content/content/layer/options" to="." method="_on_layer_button_down"]
[connection signal="item_selected" from="margin/VBoxContainer/extra/sections/layers/section_content/content/layer/options" to="." method="_on_layer_item_selected"]
[connection signal="button_down" from="margin/VBoxContainer/extra/sections/slices/section_header" to="." method="_on_slice_header_button_down"]
[connection signal="button_down" from="margin/VBoxContainer/extra/sections/slices/section_content/content/slice/options" to="." method="_on_slice_button_down"]
[connection signal="item_selected" from="margin/VBoxContainer/extra/sections/slices/section_content/content/slice/options" to="." method="_on_slice_item_selected"]
[connection signal="button_down" from="margin/VBoxContainer/extra/sections/animation/section_header" to="." method="_on_animation_header_button_down"]
[connection signal="button_down" from="margin/VBoxContainer/extra/sections/output/section_header" to="." method="_on_output_header_button_down"]
[connection signal="dir_dropped" from="margin/VBoxContainer/extra/sections/output/section_content/content/out_folder/button" to="." method="_on_out_dir_dropped"]
[connection signal="pressed" from="margin/VBoxContainer/extra/sections/output/section_content/content/out_folder/button" to="." method="_on_out_folder_pressed"]
[connection signal="pressed" from="margin/VBoxContainer/import" to="." method="_on_import_pressed"]

View File

@@ -0,0 +1,26 @@
@tool
extends MarginContainer
@onready
var _source_changed_warning_container = $VBoxContainer/source_changed_warning
@onready
var _source_changed_warning_icon = $VBoxContainer/source_changed_warning/MarginContainer/HBoxContainer/Icon
func _ready():
var sb = _source_changed_warning_container.get_theme_stylebox("panel")
var color = EditorInterface.get_editor_settings().get_setting("interface/theme/accent_color")
color.a = 0.2
sb.bg_color = color
_source_changed_warning_icon.texture = get_theme_icon("NodeInfo", "EditorIcons")
hide_source_change_warning()
func show_source_change_warning():
_source_changed_warning_container.show()
func hide_source_change_warning():
_source_changed_warning_container.hide()

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
@tool
extends EditorInspectorPlugin
const APInspectorDock = preload("./sprite_inspector_dock.tscn")
func _can_handle(object):
return object is Sprite2D || object is Sprite3D || object is TextureRect
func _parse_end(object):
var dock = APInspectorDock.instantiate()
dock.target_node = object
add_custom_control(dock)

View File

@@ -0,0 +1,255 @@
@tool
extends "../base_inspector_dock.gd"
const AnimationCreator = preload("../../../creators/animation_player/animation_creator.gd")
const SpriteAnimationCreator = preload("../../../creators/animation_player/sprite_animation_creator.gd")
const TextureRectAnimationCreator = preload("../../../creators/animation_player/texture_rect_animation_creator.gd")
const StaticTextureCreator = preload("../../../creators/static_texture/texture_creator.gd")
enum ImportMode {
ANIMATION = 0,
IMAGE = 1
}
var animation_creator: AnimationCreator
var static_texture_creator: StaticTextureCreator
var _import_mode = -1
var _animation_player_path: String
@onready var _import_mode_options_field := $dock_fields/VBoxContainer/modes/options as OptionButton
@onready var _animation_player_field := $dock_fields/VBoxContainer/animation_player/options as OptionButton
@onready var _animation_player_container := $dock_fields/VBoxContainer/animation_player as HBoxContainer
# animation
@onready var _animation_section := $dock_fields/VBoxContainer/extra/sections/animation as VBoxContainer
@onready var _animation_section_header := $dock_fields/VBoxContainer/extra/sections/animation/section_header as Button
@onready var _animation_section_container := $dock_fields/VBoxContainer/extra/sections/animation/section_content as MarginContainer
@onready var _cleanup_hide_unused_nodes := $dock_fields/VBoxContainer/extra/sections/animation/section_content/content/auto_visible_track/CheckBox as CheckBox
@onready var _keep_length := $dock_fields/VBoxContainer/extra/sections/animation/section_content/content/keep_length/CheckBox as CheckBox
const INTERFACE_SECTION_KEY_ANIMATION = "animation_section"
func _pre_setup():
_expandable_sections[INTERFACE_SECTION_KEY_ANIMATION] = { "header": _animation_section_header, "content": _animation_section_container}
func _setup():
if target_node is Sprite2D || target_node is Sprite3D:
animation_creator = SpriteAnimationCreator.new()
if target_node is TextureRect:
animation_creator = TextureRectAnimationCreator.new()
static_texture_creator = StaticTextureCreator.new()
_setup_animation_fields_listeners()
func _load_config(cfg):
if cfg.has("player"):
_animation_player_field.clear()
_set_animation_player(cfg.player)
_cleanup_hide_unused_nodes.button_pressed = cfg.get("set_vis_track", config.is_set_visible_track_automatically_enabled())
_keep_length.button_pressed = cfg.get("keep_anim_length", false)
_set_import_mode(int(cfg.get("i_mode", 0)))
func _load_default_config():
_cleanup_hide_unused_nodes.button_pressed = config.is_set_visible_track_automatically_enabled()
func _set_animation_player(player):
_animation_player_path = player
_animation_player_field.add_item(_animation_player_path)
func _set_import_mode(import_mode):
if _import_mode == import_mode:
return
_import_mode = import_mode
var index = _import_mode_options_field.get_item_index(import_mode)
_import_mode_options_field.select(index)
_handle_import_mode()
func _handle_import_mode():
match _import_mode:
ImportMode.ANIMATION:
_animation_player_container.show()
_animation_section.show()
ImportMode.IMAGE:
_animation_player_container.hide()
_animation_section.hide()
func _setup_animation_fields_listeners():
_animation_section_header.button_down.connect(_on_animation_header_button_down)
_animation_player_field.node_dropped.connect(_on_animation_player_node_dropped)
_animation_player_field.button_down.connect(_on_animation_player_button_down)
_animation_player_field.item_selected.connect(_on_animation_player_item_selected)
_import_mode_options_field.item_selected.connect(_on_modes_item_selected)
func _on_animation_player_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
_animation_player_field.clear()
_animation_player_field.add_item("[empty]")
for ap in animation_players:
_animation_player_field.add_item(ap)
if ap.get_concatenated_names() == _animation_player_path:
current = _animation_player_field.get_item_count() - 1
_animation_player_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_animation_player_item_selected(index):
if index == 0:
_animation_player_path = ""
return
_animation_player_path = _animation_player_field.get_item_text(index)
_save_config()
func _do_import():
if _import_mode == ImportMode.IMAGE:
await _import_static()
return
await _import_for_animation_player()
##
## Import aseprite animations to target AnimationPlayer and set
## spritesheet as the node's texture
##
func _import_for_animation_player():
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
var source_path = ProjectSettings.globalize_path(_source)
var options = _get_import_options(root.scene_file_path.get_base_dir())
_save_config()
var aseprite_output = _aseprite_file_exporter.generate_aseprite_file(source_path, options)
if not aseprite_output.is_ok:
_notify_aseprite_error(aseprite_output.code)
return
file_system.scan()
await file_system.filesystem_changed
var anim_options = {
"keep_anim_length": _keep_length.button_pressed,
"cleanup_hide_unused_nodes": _cleanup_hide_unused_nodes.button_pressed,
"slice": _slice,
}
animation_creator.create_animations(target_node, root.get_node(_animation_player_path), aseprite_output.content, anim_options)
_importing = false
wizard_config.set_source_hash(target_node, FileAccess.get_md5(source_path))
_handle_cleanup(aseprite_output.content)
##
## Import first frame from aseprite file as node texture
##
func _import_static():
var source_path = ProjectSettings.globalize_path(_source)
var root = get_tree().get_edited_scene_root()
var options = _get_import_options(root.scene_file_path.get_base_dir())
options["first_frame_only"] = true
_save_config()
var aseprite_output = _aseprite_file_exporter.generate_aseprite_file(source_path, options)
if not aseprite_output.is_ok:
_notify_aseprite_error(aseprite_output.code)
return
file_system.scan()
await file_system.filesystem_changed
static_texture_creator.load_texture(target_node, aseprite_output.content, { "slice": _slice })
_importing = false
wizard_config.set_source_hash(target_node, FileAccess.get_md5(source_path))
_handle_cleanup(aseprite_output.content)
func _get_current_field_values() -> Dictionary:
var cfg := {
"i_mode": _import_mode,
"player": _animation_player_path,
"keep_anim_length": _keep_length.button_pressed,
}
if _cleanup_hide_unused_nodes.button_pressed != config.is_set_visible_track_automatically_enabled():
cfg["set_vis_track"] = _cleanup_hide_unused_nodes.button_pressed
return cfg
func _get_available_layers(global_source_path: String) -> Array:
return animation_creator.list_layers(global_source_path)
func _get_available_slices(global_source_path: String) -> Array:
return animation_creator.list_slices(global_source_path)
func _on_animation_player_node_dropped(node_path):
var node = get_node(node_path)
var root = get_tree().get_edited_scene_root()
_animation_player_path = root.get_path_to(node)
for i in range(_animation_player_field.get_item_count()):
if _animation_player_field.get_item_text(i) == _animation_player_path:
_animation_player_field.select(i)
break
_save_config()
func _on_modes_item_selected(index):
var id = _import_mode_options_field.get_item_id(index)
_import_mode = id
_handle_import_mode()
func _on_animation_header_button_down():
_toggle_section_visibility(INTERFACE_SECTION_KEY_ANIMATION)
func _show_specific_fields():
_import_mode_options_field.get_parent().show()
_animation_player_container.show()
_animation_section.show()

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://biyshalfalqqw"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/sprite/sprite_inspector_dock.gd" id="1_ku6wj"]
[ext_resource type="PackedScene" uid="uid://uxm7b02wry10" path="res://addons/AsepriteWizard/interface/docks/dock_fields.tscn" id="2_wkqx4"]
[node name="sprite_inspector_dock" type="PanelContainer"]
offset_right = 14.0
offset_bottom = 14.0
script = ExtResource("1_ku6wj")
[node name="dock_fields" parent="." instance=ExtResource("2_wkqx4")]
layout_mode = 2

View File

@@ -0,0 +1,39 @@
@tool
extends TabContainer
signal close_requested
const WizardWindow = preload("./as_wizard_window.tscn")
func _ready():
$Import.close_requested.connect(emit_signal.bind("close_requested"))
$Import.import_success.connect(_on_import_success)
$History.request_edit.connect(_on_edit_request)
$History.request_import.connect(_on_import_request)
$ImportedSpriteFrames.import_success.connect($History.add_entry)
self.set_tab_title(1, "Imported Resources")
func _on_AsWizardDockContainer_tab_changed(tab: int):
match tab:
1:
$ImportedSpriteFrames.init_resources()
2:
$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()
func _on_import_success(settings: Dictionary):
$ImportedSpriteFrames.init_resources()
$ImportedSpriteFrames.reload_tree()
$History.add_entry(settings)

View File

@@ -0,0 +1,28 @@
[gd_scene load_steps=5 format=3 uid="uid://b844j1tk3vxer"]
[ext_resource type="PackedScene" uid="uid://c5dwobjd34w3p" path="res://addons/AsepriteWizard/interface/docks/wizard/as_wizard_window.tscn" id="1"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/as_wizard_dock_container.gd" id="2"]
[ext_resource type="PackedScene" uid="uid://cyoin5ncul0fm" path="res://addons/AsepriteWizard/interface/docks/wizard/sprite_frames_import_history.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://bfhsdslj8kt7b" path="res://addons/AsepriteWizard/interface/docks/wizard/imported_sprite_frames.tscn" id="3_25qb4"]
[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")]
layout_mode = 2
tooltip_text = "SpriteFrames Importer"
[node name="ImportedSpriteFrames" parent="." instance=ExtResource("3_25qb4")]
visible = false
layout_mode = 2
metadata/_tab_name = "Imported Resources"
[node name="History" parent="." instance=ExtResource("3")]
visible = false
layout_mode = 2
[connection signal="tab_changed" from="." to="." method="_on_AsWizardDockContainer_tab_changed"]

View File

@@ -0,0 +1,274 @@
@tool
extends PanelContainer
signal close_requested
signal import_success(file_settings)
const result_code = preload("../../../config/result_codes.gd")
var _config = preload("../../../config/config.gd").new()
var _import_helper = preload("./wizard_import_helper.gd").new()
var _file_system: EditorFileSystem = EditorInterface.get_resource_filesystem()
var _file_dialog_aseprite: EditorFileDialog
var _output_folder_dialog: EditorFileDialog
var _warning_dialog: AcceptDialog
@onready var _layer_section_btn: Button = $container/options/layer_section/header/section_header
@onready var _layer_section_content: MarginContainer = $container/options/layer_section/section_content
@onready var _output_section_btn: Button = $container/options/output_section/header/section_header
@onready var _output_section_content: MarginContainer = $container/options/output_section/section_content
@onready var _file_location_field: LineEdit = $container/options/file_location/HBoxContainer/file_location_path
@onready var _output_folder_field: LineEdit = $container/options/output_section/section_content/items/output_folder/HBoxContainer/file_location_path
@onready var _exception_pattern_field: LineEdit = $container/options/layer_section/section_content/items/exclude_pattern/pattern
@onready var _split_mode_field: CheckBox = $container/options/layer_section/section_content/items/split_layers/field
@onready var _only_visible_layers_field: CheckBox = $container/options/layer_section/section_content/items/visible_layers/field
@onready var _custom_name_field: LineEdit = $container/options/output_section/section_content/items/custom_filename/pattern
@onready var _do_not_create_res_field: CheckBox = $container/options/output_section/section_content/items/disable_resource_creation/field
const INTERFACE_SECTION_KEY_LAYER = "layer_section"
const INTERFACE_SECTION_KEY_OUTPUT = "output_section"
@onready var _expandable_sections = {
INTERFACE_SECTION_KEY_LAYER: { "header": _layer_section_btn, "content": _layer_section_content},
INTERFACE_SECTION_KEY_OUTPUT: { "header": _output_section_btn, "content": _output_section_content},
}
var _interface_section_state = {}
func _ready():
_configure_sections()
_load_persisted_config()
func _exit_tree():
if is_instance_valid(_file_dialog_aseprite):
_file_dialog_aseprite.queue_free()
if is_instance_valid(_output_folder_dialog):
_output_folder_dialog.queue_free()
if is_instance_valid(_warning_dialog):
_warning_dialog.queue_free()
func _init_aseprite_file_selection_dialog():
_file_dialog_aseprite = _create_aseprite_file_selection()
get_parent().get_parent().add_child(_file_dialog_aseprite)
func _init_output_folder_selection_dialog():
_output_folder_dialog = _create_outuput_folder_selection()
get_parent().get_parent().add_child(_output_folder_dialog)
func _init_warning_dialog():
_warning_dialog = AcceptDialog.new()
_warning_dialog.exclusive = false
get_parent().get_parent().add_child(_warning_dialog)
func _load_persisted_config() -> void:
var cfg = _load_last_import_cfg()
_load_config(cfg)
func _load_config(cfg: Dictionary) -> void:
_split_mode_field.button_pressed = cfg.split_layers
_only_visible_layers_field.button_pressed = cfg.only_visible_layers
_exception_pattern_field.text = cfg.layer_exclusion_pattern
_custom_name_field.text = cfg.output_name
_file_location_field.text = cfg.source_file
_do_not_create_res_field.button_pressed = cfg.do_not_create_resource
_output_folder_field.text = cfg.output_location if cfg.output_location != "" else "res://"
func _save_config() -> void:
_config.set_standalone_spriteframes_last_import_config(_get_field_values())
func _get_field_values() -> Dictionary:
return {
"split_layers": _split_mode_field.button_pressed,
"only_visible_layers": _only_visible_layers_field.button_pressed,
"layer_exclusion_pattern": _exception_pattern_field.text,
"output_name": _custom_name_field.text,
"source_file": _file_location_field.text,
"do_not_create_resource": _do_not_create_res_field.button_pressed,
"output_location": _output_folder_field.text if _output_folder_field.text != "" else "res://",
}
func _clear_config() -> void:
_config.clear_standalone_spriteframes_last_import_config()
var default = _get_default_config()
_load_config(default)
## This is used by the other tabs to set the form fields
func load_import_config(field_values: Dictionary):
_split_mode_field.button_pressed = field_values.split_layers
_only_visible_layers_field.button_pressed = field_values.only_visible_layers
_exception_pattern_field.text = field_values.layer_exclusion_pattern
_custom_name_field.text = field_values.output_name
_file_location_field.text = field_values.source_file
_do_not_create_res_field.button_pressed = field_values.do_not_create_resource
_output_folder_field.text = field_values.output_location
func _open_aseprite_file_selection_dialog():
if not is_instance_valid(_file_dialog_aseprite):
_init_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():
if not is_instance_valid(_output_folder_dialog):
_init_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 = EditorFileDialog.new()
file_dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILE
file_dialog.access = EditorFileDialog.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 = EditorFileDialog.new()
file_dialog.file_mode = EditorFileDialog.FILE_MODE_OPEN_DIR
file_dialog.access = EditorFileDialog.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
func _on_output_folder_selected(path):
_output_folder_field.text = path
func _on_next_btn_up():
var aseprite_file = _file_location_field.text
var fields = _get_field_values()
var exit_code = await _import_helper.import_and_create_resources(aseprite_file, _get_field_values())
if exit_code != OK:
_show_error(exit_code)
return
emit_signal("import_success", fields)
if _config.should_remove_source_files():
_file_system.call_deferred("scan")
_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 _on_clear_button_up():
_clear_config()
func _show_error(code: int):
_show_error_message(result_code.get_error_message(code))
func _show_error_message(message: String):
if not is_instance_valid(_warning_dialog):
_init_warning_dialog()
_warning_dialog.dialog_text = "Error: %s" % message
_warning_dialog.popup_centered()
func _show_import_success_message():
if not is_instance_valid(_warning_dialog):
_init_warning_dialog()
_warning_dialog.dialog_text = "Aseprite import succeeded"
_warning_dialog.popup_centered()
_save_config()
func _configure_sections():
for key in _expandable_sections:
_adjust_section_visibility(key)
func _adjust_section_visibility(key: String) -> void:
var section = _expandable_sections[key]
var is_visible = _interface_section_state.get(key, true)
_adjust_icon(section.header, is_visible)
section.content.visible = is_visible
func _adjust_icon(section: Button, is_visible: bool = true) -> void:
var icon_name = "GuiTreeArrowDown" if is_visible else "GuiTreeArrowRight"
section.icon = get_theme_icon(icon_name, "EditorIcons")
func _toggle_section_visibility(key: String) -> void:
_interface_section_state[key] = not _interface_section_state.get(key, true)
_adjust_section_visibility(key)
func _on_layer_section_header_button_down():
_toggle_section_visibility(INTERFACE_SECTION_KEY_LAYER)
func _on_output_section_header_button_down():
_toggle_section_visibility(INTERFACE_SECTION_KEY_OUTPUT)
func _load_last_import_cfg() -> Dictionary:
var cfg = _config.get_standalone_spriteframes_last_import_config()
if cfg.is_empty():
return _get_default_config()
return cfg
func _get_default_config() -> Dictionary:
return {
"split_layers": false,
"only_visible_layers": _config.should_include_only_visible_layers_by_default(),
"layer_exclusion_pattern": _config.get_default_exclusion_pattern(),
"output_name": "",
"source_file": "",
"do_not_create_resource": false,
"output_location": "res://",
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,304 @@
@tool
extends PanelContainer
signal import_success(fields)
const result_code = preload("../../../config/result_codes.gd")
const wizard_config = preload("../../../config/wizard_config.gd")
var _import_helper = preload("./wizard_import_helper.gd").new()
@onready var _tree_container = $MarginContainer/HSplitContainer/tree
@onready var _resource_tree = _tree_container.get_resource_tree()
@onready var _nothing_container = $MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/nothing
@onready var _single_item_container = $MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/single_item
@onready var _multiple_items_container = $MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/multiple_items
@onready var _confirmation_warning_container = $MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/confirmation_warning
var _selection_count = 0
var _current_container = null
var _resources_to_process = null
var _is_loaded = false
var _groups = {}
func init_resources():
if _is_loaded:
return
_is_loaded = true
var file_tree = _get_file_tree("res://")
_setup_tree(file_tree)
func _get_file_tree(base_path: String, dir_name: String = "") -> Dictionary:
var dir_path = base_path.path_join(dir_name)
var dir = DirAccess.open(dir_path)
var dir_data = { "path": dir_path, "name": dir_name, "children": [], "type": "dir", }
if not dir:
return dir_data
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir() and _is_importable_folder(dir_path, file_name):
var child_data = _get_file_tree(dir_path, file_name)
if not child_data.children.is_empty():
dir_data.children.push_back(child_data)
elif file_name.ends_with(".res"):
var resource_path = dir_path.path_join(file_name)
var resource = ResourceLoader.load(resource_path)
if resource is SpriteFrames:
if resource.has_meta(wizard_config.WIZARD_CONFIG_META_NAME):
var meta = resource.get_meta(wizard_config.WIZARD_CONFIG_META_NAME)
var parent_node = dir_data
if meta.group != "":
var group
if _groups.has(meta.group):
group = _groups[meta.group]
else:
group = { "folders": {} }
_groups[meta.group] = group
if not group.folders.has(dir_path):
group.folders[dir_path] = {
"node": {
"type": "group",
"name": "Split: %s" % meta.fields.source_file.get_file(),
"has_moved": meta.fields.output_location != dir_path,
"path": meta.fields.source_file,
"folder": dir_path,
"has_changes": _has_source_changes(resource, meta),
"children": [],
}
}
parent_node.children.push_back(group.folders[dir_path].node)
parent_node = group.folders[dir_path].node
parent_node.children.push_back({
"type": "resource",
"resource_type": "SpriteFrames",
"name": resource.resource_path.get_file(),
"path": resource.resource_path,
"meta": meta,
"has_changes": _has_source_changes(resource, meta),
"has_moved": meta.fields.output_location != dir_path,
})
file_name = dir.get_next()
return dir_data
func _is_importable_folder(dir_path: String, dir_name: String) -> bool:
return dir_path != "res://" or dir_name != "addons"
func _setup_tree(resource_tree: Dictionary) -> void:
var root = _resource_tree.create_item()
_add_items_to_tree(root, resource_tree.children)
func _add_items_to_tree(root: TreeItem, children: Array):
for node in children:
var item: TreeItem = _resource_tree.create_item(root)
item.set_text(0, node.name)
item.set_meta("node", node)
match node.type:
"dir":
item.set_icon(0, get_theme_icon("Folder", "EditorIcons"))
_add_items_to_tree(item, node.children)
#
"group":
item.set_icon(0, get_theme_icon("CompressedTexture2D", "EditorIcons"))
_add_items_to_tree(item, node.children)
if node.has_changes:
item.set_text(0, "%s (*)" % node.name)
if node.has_moved:
item.set_suffix(0, "(moved)")
"resource":
item.set_icon(0, get_theme_icon(node.resource_type, "EditorIcons"))
if node.has_changes:
item.set_text(0, "%s (*)" % node.name)
if node.meta.group != "":
item.set_custom_color(0, item.get_icon_modulate(0).darkened(0.5))
item.set_selectable(0, false)
elif node.has_moved:
item.set_suffix(0, "(moved)")
func _has_source_changes(resource: Object, meta: Dictionary) -> bool:
var current_hash = FileAccess.get_md5(meta.fields.source_file)
var saved_hash = wizard_config.get_source_hash(resource)
return saved_hash != current_hash
func _is_supported_type(resource_type: String) -> bool:
return resource_type == "SpriteFrames"
func reload_tree():
_confirmation_warning_container.hide()
_resources_to_process = null
if _current_container != null:
_current_container.show_buttons()
_current_container = null
_groups = {}
_selection_count = 0
_resource_tree.clear()
var file_tree = _get_file_tree("res://")
_setup_tree(file_tree)
func _set_empty_details_state():
_nothing_container.show()
_single_item_container.hide()
_multiple_items_container.hide()
func _on_tree_multi_selected(item: TreeItem, column: int, selected: bool):
_confirmation_warning_container.hide()
_resources_to_process = null
if _current_container != null:
_current_container.show_buttons()
#
if selected:
_selection_count += 1
else:
_selection_count -= 1
#
_nothing_container.hide()
_single_item_container.hide()
_multiple_items_container.hide()
#
match _selection_count:
0:
_nothing_container.show()
1:
_single_item_container.show()
_set_item_details(_resource_tree.get_selected())
_current_container = _single_item_container
_:
_multiple_items_container.show()
_multiple_items_container.set_selected_count(_selection_count)
_current_container = _multiple_items_container
func _set_item_details(item: TreeItem) -> void:
if not item.has_meta("node"):
return
var data = item.get_meta("node")
_single_item_container.set_resource_details(data)
func _on_single_item_import_triggered():
var selected = _resource_tree.get_selected()
var meta = selected.get_meta("node")
match meta.type:
"dir":
var selected_item = _resource_tree.get_selected()
var all_resources = []
var scenes_to_open = _set_all_resources(selected_item.get_meta("node"), all_resources)
_resources_to_process = all_resources
_show_confirmation_message(all_resources.size())
"resource":
var code = await _do_import(meta.path, meta.meta)
_set_tree_item_as_saved(_resource_tree.get_selected())
_single_item_container.hide_source_change_warning()
if code == OK:
EditorInterface.get_resource_filesystem().scan()
"group":
var first_item = meta.children[0]
var code = await _do_import(first_item.path, first_item.meta)
_set_tree_item_as_saved(selected)
_single_item_container.hide_source_change_warning()
if code == OK:
EditorInterface.get_resource_filesystem().scan()
_on_tree_refresh_triggered()
func _on_confirmation_warning_warning_confirmed():
_confirmation_warning_container.hide()
_current_container.show_buttons()
for resource in _resources_to_process:
await _do_import(resource.path, resource.meta)
_resources_to_process = null
EditorInterface.get_resource_filesystem().scan()
_on_tree_refresh_triggered()
func _on_confirmation_warning_warning_declined():
_confirmation_warning_container.hide()
_current_container.show_buttons()
_resources_to_process = null
func _on_tree_refresh_triggered():
_set_empty_details_state()
reload_tree()
func _set_tree_item_as_saved(item: TreeItem) -> void:
var meta = item.get_meta("node")
meta.has_changes = false
meta.has_moved = false
item.set_meta("node", meta)
item.set_text(0, meta.name)
item.set_suffix(0, "")
func _do_import(resource_path: String, metadata: Dictionary) -> int:
var resource_base_dir = resource_path.get_base_dir()
if resource_base_dir != metadata.fields.output_location:
print("Resource has moved. Changing output folder from %s to %s" % [resource_base_dir, metadata.fields.output_location])
metadata.fields.output_location = resource_base_dir
var exit_code := await _import_helper.import_and_create_resources(metadata.fields.source_file, metadata.fields)
if exit_code == OK:
print("Import complete: %s" % resource_path)
import_success.emit(metadata.fields)
else:
printerr("Failed to import %s. Error: %s" % [resource_path, result_code.get_error_message(exit_code)])
return exit_code
func _set_all_resources(meta: Dictionary, resources: Array):
match meta.type:
"dir":
for c in meta.children:
_set_all_resources(c, resources)
"resource":
if not resources.has(meta):
resources.push_back(meta)
"group":
var first_item = meta.children[0]
resources.push_back(first_item)
func _show_confirmation_message(resources: int):
_current_container.hide_buttons()
_confirmation_warning_container.set_message("You are about to re-import %s resources. Do you wish to continue?" % resources)
_confirmation_warning_container.show()
func _on_multiple_items_import_triggered():
var selected_item = _resource_tree.get_next_selected(null)
var all_resources = []
while selected_item != null:
_set_all_resources(selected_item.get_meta("node"), all_resources)
selected_item = _resource_tree.get_next_selected(selected_item)
_resources_to_process = all_resources
_show_confirmation_message(all_resources.size())

View File

@@ -0,0 +1,67 @@
[gd_scene load_steps=6 format=3 uid="uid://bfhsdslj8kt7b"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/imported_sprite_frames.gd" id="1_dk2ra"]
[ext_resource type="PackedScene" uid="uid://cisgsfvp4nf1g" path="res://addons/AsepriteWizard/interface/shared/tree/resource_tree.tscn" id="2_svrqo"]
[ext_resource type="PackedScene" uid="uid://q7eyyg2kvvv2" path="res://addons/AsepriteWizard/interface/docks/wizard/resource_tree_single_item.tscn" id="3_pe1cg"]
[ext_resource type="PackedScene" uid="uid://fscemkx5w1dw" path="res://addons/AsepriteWizard/interface/docks/wizard/resource_tree_multiple_items.tscn" id="4_vteew"]
[ext_resource type="PackedScene" uid="uid://qgmln507kjnm" path="res://addons/AsepriteWizard/interface/shared/tree/tree_selection_confirmation_warning.tscn" id="5_jigim"]
[node name="ImportedSpriteFrames" type="PanelContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_dk2ra")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
[node name="HSplitContainer" type="HSplitContainer" parent="MarginContainer"]
layout_mode = 2
[node name="tree" parent="MarginContainer/HSplitContainer" instance=ExtResource("2_svrqo")]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HSplitContainer"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HSplitContainer/MarginContainer"]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/MarginContainer"]
layout_mode = 2
text = "Details"
horizontal_alignment = 1
[node name="HSeparator" type="HSeparator" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="nothing" type="Label" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "Nothing selected"
horizontal_alignment = 1
[node name="single_item" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("3_pe1cg")]
visible = false
layout_mode = 2
[node name="multiple_items" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("4_vteew")]
visible = false
layout_mode = 2
[node name="confirmation_warning" parent="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("5_jigim")]
visible = false
layout_mode = 2
[connection signal="multi_selected" from="MarginContainer/HSplitContainer/tree" to="." method="_on_tree_multi_selected"]
[connection signal="refresh_triggered" from="MarginContainer/HSplitContainer/tree" to="." method="_on_tree_refresh_triggered"]
[connection signal="import_triggered" from="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/single_item" to="." method="_on_single_item_import_triggered"]
[connection signal="import_triggered" from="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/multiple_items" to="." method="_on_multiple_items_import_triggered"]
[connection signal="warning_confirmed" from="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/confirmation_warning" to="." method="_on_confirmation_warning_warning_confirmed"]
[connection signal="warning_declined" from="MarginContainer/HSplitContainer/MarginContainer/VBoxContainer/confirmation_warning" to="." method="_on_confirmation_warning_warning_declined"]

View File

@@ -0,0 +1,22 @@
@tool
extends VBoxContainer
signal import_triggered
@onready var _import_message = $message
@onready var _import_button = $buttons
func set_selected_count(number_of_items: int) -> void:
_import_message.text = "%2d items selected" % number_of_items
func show_buttons():
_import_button.show()
func hide_buttons():
_import_button.hide()
func _on_import_selected_button_up():
import_triggered.emit()

View File

@@ -0,0 +1,24 @@
[gd_scene load_steps=2 format=3 uid="uid://fscemkx5w1dw"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/resource_tree_multiple_items.gd" id="1_lg81l"]
[node name="multiple_items" type="VBoxContainer"]
size_flags_vertical = 3
script = ExtResource("1_lg81l")
[node name="message" type="Label" parent="."]
layout_mode = 2
size_flags_vertical = 6
text = "Multiple items selected
"
horizontal_alignment = 1
[node name="buttons" type="HFlowContainer" parent="."]
layout_mode = 2
[node name="import_selected" type="Button" parent="buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import all"
[connection signal="button_up" from="buttons/import_selected" to="." method="_on_import_selected_button_up"]

View File

@@ -0,0 +1,171 @@
@tool
extends VBoxContainer
signal import_triggered
@onready var _file_name = $GridContainer/file_name_value
@onready var _type = $GridContainer/type_value
@onready var _path = $GridContainer/path_value
@onready var _source_label = $GridContainer/source_file_label
@onready var _source = $GridContainer/source_file_value
@onready var _only_visible_layers_label = $GridContainer/only_visible_layers_label
@onready var _only_visible_layers = $GridContainer/only_visible_layers_value
@onready var _layer_ex_pattern_label = $GridContainer/layer_ex_patt_label
@onready var _layer_ex_pattern = $GridContainer/layer_ex_patt_value
@onready var _o_name_label = $GridContainer/o_name_label
@onready var _o_name = $GridContainer/o_name_value
@onready var _o_folder_label = $GridContainer/o_folder_label
@onready var _o_folder_value = $GridContainer/o_folder_value
@onready var _resource_list_label = $GridContainer/resource_list_label
@onready var _resource_list = $GridContainer/resource_list
@onready var _resource_list_separator_1 = $GridContainer/HSeparator3
@onready var _resource_list_separator_2 = $GridContainer/HSeparator4
@onready var _resource_buttons = $resource_buttons
@onready var _dir_buttons = $dir_buttons
@onready var _group_buttons = $group_buttons
@onready var _source_change_warning = $source_changed_warning
@onready var _resource_only_fields = [
_source_label,
_source,
_only_visible_layers_label,
_only_visible_layers,
_layer_ex_pattern_label,
_layer_ex_pattern,
_o_name_label,
_o_name,
_o_folder_label,
_o_folder_value,
_source_change_warning,
]
var _current_resource_type = "resource"
var _resource_config: Dictionary = {}
func _ready():
_source_change_warning.set_text("Source file changed since last import")
_source_change_warning.hide()
func set_resource_details(resource_details: Dictionary) -> void:
_resource_config = resource_details
_resource_buttons.hide()
_dir_buttons.hide()
_group_buttons.hide()
_hide_resource_list()
_source_change_warning.hide()
_file_name.text = resource_details.name
_path.text = resource_details.path
_current_resource_type = resource_details.type
match resource_details.type:
"resource":
_type.text = resource_details.resource_type
_show_resource_fields()
_resource_buttons.show()
var fields = resource_details.meta.fields
_load_fields(fields)
_resource_buttons.show()
_source_change_warning.visible = resource_details.has_changes
"group":
_type.text = "Split Group"
_show_resource_fields()
_load_fields(resource_details.children[0].meta.fields)
_source_change_warning.visible = resource_details.children[0].has_changes
_group_buttons.show()
_show_resource_list()
for c in _resource_list.get_children():
c.queue_free()
for child_resource in resource_details.children:
var label = Label.new()
label.text = child_resource.name
_resource_list.add_child(label)
_:
_type.text = "Folder"
_hide_resource_fields()
_dir_buttons.show()
return
func _load_fields(fields: Dictionary):
_only_visible_layers.text = "Yes" if fields.only_visible_layers else "No"
_layer_ex_pattern.text = fields.layer_exclusion_pattern
_o_name.text = fields.output_name
_o_folder_value.text = fields.output_location
_source.text = fields.source_file
func _hide_resource_fields():
for f in _resource_only_fields:
f.hide()
func _show_resource_fields():
for f in _resource_only_fields:
f.show()
func show_buttons():
match _current_resource_type:
"resource":
_resource_buttons.show()
_:
_dir_buttons.show()
func hide_buttons():
_resource_buttons.hide()
_dir_buttons.hide()
func hide_source_change_warning():
_source_change_warning.hide()
func _on_show_in_fs_button_up():
EditorInterface.get_file_system_dock().navigate_to_path(_path.text)
func _on_show_dir_in_fs_button_up():
EditorInterface.get_file_system_dock().navigate_to_path(_path.text)
func _on_import_all_button_up():
import_triggered.emit()
func _on_import_button_up():
import_triggered.emit()
func _hide_resource_list():
_resource_list_separator_1.hide()
_resource_list_separator_2.hide()
_resource_list_label.hide()
_resource_list.hide()
func _show_resource_list():
_resource_list_separator_1.show()
_resource_list_separator_2.show()
_resource_list_label.show()
_resource_list.show()
func _on_import_all_pressed():
import_triggered.emit()
func _on_show_in_fs_pressed():
EditorInterface.get_file_system_dock().navigate_to_path(_resource_config.children[0].path)

View File

@@ -0,0 +1,172 @@
[gd_scene load_steps=3 format=3 uid="uid://q7eyyg2kvvv2"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/resource_tree_single_item.gd" id="1_h1q4t"]
[ext_resource type="PackedScene" uid="uid://c1l0bk12iwln3" path="res://addons/AsepriteWizard/interface/shared/tree/inline_warning_panel.tscn" id="2_hmv61"]
[node name="single_item" type="VBoxContainer"]
script = ExtResource("1_h1q4t")
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/h_separation = 10
columns = 2
[node name="type_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Type"
[node name="type_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="file_name_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "File"
[node name="file_name_value" type="Label" parent="GridContainer"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
text = "-"
autowrap_mode = 1
[node name="path_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Path"
[node name="path_value" type="Label" parent="GridContainer"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
autowrap_mode = 1
[node name="HSeparator" type="HSeparator" parent="GridContainer"]
layout_mode = 2
[node name="HSeparator2" type="HSeparator" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="source_file_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Aseprite File"
[node name="source_file_value" type="Label" parent="GridContainer"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
autowrap_mode = 1
[node name="only_visible_layers_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Only Visible Layers"
[node name="only_visible_layers_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="layer_ex_patt_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Slice"
[node name="layer_ex_patt_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="o_folder_label" type="Label" parent="GridContainer"]
visible = false
layout_mode = 2
size_flags_vertical = 0
text = "Output Folder"
[node name="o_folder_value" type="Label" parent="GridContainer"]
visible = false
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
autowrap_mode = 2
[node name="o_name_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Output Name"
[node name="o_name_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="HSeparator3" type="HSeparator" parent="GridContainer"]
layout_mode = 2
[node name="HSeparator4" type="HSeparator" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="resource_list_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Resources"
[node name="resource_list" type="VBoxContainer" parent="GridContainer"]
layout_mode = 2
[node name="source_changed_warning" parent="." instance=ExtResource("2_hmv61")]
layout_mode = 2
[node name="resource_buttons" type="HFlowContainer" parent="."]
visible = false
layout_mode = 2
[node name="import" type="Button" parent="resource_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import"
[node name="show_in_fs" type="Button" parent="resource_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Show In FileSystem"
[node name="group_buttons" type="HFlowContainer" parent="."]
visible = false
layout_mode = 2
[node name="import_all" type="Button" parent="group_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import all"
[node name="show_in_fs" type="Button" parent="group_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Show In FileSystem"
[node name="dir_buttons" type="HFlowContainer" parent="."]
visible = false
layout_mode = 2
[node name="import_all" type="Button" parent="dir_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import all"
[node name="show_dir_in_fs" type="Button" parent="dir_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Show In FileSystem"
[connection signal="button_up" from="resource_buttons/import" to="." method="_on_import_button_up"]
[connection signal="button_up" from="resource_buttons/show_in_fs" to="." method="_on_show_in_fs_button_up"]
[connection signal="pressed" from="group_buttons/import_all" to="." method="_on_import_all_pressed"]
[connection signal="pressed" from="group_buttons/show_in_fs" to="." method="_on_show_in_fs_pressed"]
[connection signal="button_up" from="dir_buttons/import_all" to="." method="_on_import_all_button_up"]
[connection signal="button_up" from="dir_buttons/show_dir_in_fs" to="." method="_on_show_dir_in_fs_button_up"]

View File

@@ -0,0 +1,260 @@
@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 DetailsField = preload("./wizard_nodes/details.tscn")
const SORT_BY_DATE := 0
const SORT_BY_PATH := 1
const INITIAL_GRID_INDEX := 4
var _config = preload("../../../config/config.gd").new()
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 reload():
if _history:
return
if _config.has_old_history():
_migrate_history()
_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 import_date = ImportDateField.instantiate()
import_date.set_date(entry.import_date)
var source_path = SourcePathField.instantiate()
source_path.set_entry(entry)
var output_path = OutputPathField.instantiate()
output_path.text = entry.output_location
output_path.tooltip_text = entry.output_location
var details = DetailsField.instantiate()
details.set_details(entry)
var actions = ItemActions.instantiate()
actions.history_index = index
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"))
grid.get_child(INITIAL_GRID_INDEX).add_sibling(import_date)
import_date.add_sibling(source_path)
source_path.add_sibling(output_path)
output_path.add_sibling(details)
details.add_sibling(actions)
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,
"details_node": details,
}
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 _history.size() > _config.get_history_max_entries():
_remove_entries(_history[0].source_file, 0)
#
_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()
entry_history_node.details_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.import_date_node, INITIAL_GRID_INDEX + 1)
grid.move_child(entry.source_path_node, INITIAL_GRID_INDEX + 2)
grid.move_child(entry.output_path_node, INITIAL_GRID_INDEX + 3)
grid.move_child(entry.details_node, INITIAL_GRID_INDEX + 4)
grid.move_child(entry.actions_node, INITIAL_GRID_INDEX + 5)
func _migrate_history():
var history = _config.get_old_import_history()
var new_history = []
for index in range(history.size()):
var entry = history[index]
new_history.push_back({
"split_layers": true if entry.options.export_mode else false,
"only_visible_layers": entry.options.only_visible_layers,
"layer_exclusion_pattern": entry.options.exception_pattern,
"output_name": entry.options.output_filename,
"source_file": entry.source_file,
"do_not_create_resource": entry.options.do_not_create_resource,
"output_location": entry.output_location,
"import_date": entry.import_date,
})
_config.save_import_history(new_history)
_config.remove_old_history_setting()

View File

@@ -0,0 +1,85 @@
[gd_scene load_steps=2 format=3 uid="uid://cyoin5ncul0fm"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/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 = "Source File"
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 = 5
[node name="date_label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/GridContainer"]
layout_mode = 2
text = "Date"
[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="details_label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/GridContainer"]
layout_mode = 2
text = "Details"
[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"]

View File

@@ -0,0 +1,69 @@
@tool
extends Node
const wizard_meta = preload("../../../config/wizard_config.gd")
const result_code = preload("../../../config/result_codes.gd")
var _aseprite_file_exporter = preload("../../../aseprite/file_exporter.gd").new()
var _sf_creator = preload("../../../creators/sprite_frames/sprite_frames_creator.gd").new()
var _config = preload("../../../config/config.gd").new()
var _file_system: EditorFileSystem = EditorInterface.get_resource_filesystem()
# fields
# "split_layers"
# "only_visible_layers"
# "layer_exclusion_pattern"
# "output_name"
# "source_file"
# "do_not_create_resource"
# "output_location"
func import_and_create_resources(aseprite_file: String, fields: Dictionary) -> int:
var export_mode = _aseprite_file_exporter.LAYERS_EXPORT_MODE if fields.split_layers else _aseprite_file_exporter.FILE_EXPORT_MODE
var options = {
"export_mode": export_mode,
"exception_pattern": fields.layer_exclusion_pattern,
"only_visible_layers": fields.only_visible_layers,
"output_filename": fields.output_name,
"do_not_create_resource": fields.do_not_create_resource,
"output_folder": fields.output_location,
}
var aseprite_output = _aseprite_file_exporter.generate_aseprite_files(
ProjectSettings.globalize_path(aseprite_file),
options
)
if not aseprite_output.is_ok:
return aseprite_output.code
_file_system.scan()
await _file_system.filesystem_changed
var exit_code = OK
if !options.get("do_not_create_resource", false):
var resources = _sf_creator.create_resources(aseprite_output.content)
if resources.is_ok:
_add_metadata(resources.content, aseprite_file, fields, options)
exit_code = _sf_creator.save_resources(resources.content)
if _config.should_remove_source_files():
_remove_source_files(aseprite_output.content)
return exit_code
func _add_metadata(resources: Array, aseprite_file: String, fields: Dictionary, options: Dictionary) -> void:
var source_hash = FileAccess.get_md5(aseprite_file)
var group = str(ResourceUID.create_id()) if options.export_mode == _aseprite_file_exporter.LAYERS_EXPORT_MODE else ""
for r in resources:
wizard_meta.set_source_hash(r.resource, source_hash)
wizard_meta.save_config(r.resource, { "fields": fields, "group": group })
func _remove_source_files(source_files: Array):
for s in source_files:
DirAccess.remove_absolute(s.data_file)

View File

@@ -0,0 +1,42 @@
@tool
extends VBoxContainer
@onready var _details_btn = $label
@onready var _details_container = $MarginContainer/GridContainer
@onready var _split_layers_field = $MarginContainer/GridContainer/split_layers
@onready var _only_visible_layers = $MarginContainer/GridContainer/only_visible_layers
@onready var _layer_exclusion_pattern = $MarginContainer/GridContainer/layer_exclusion_pattern
@onready var _output_name = $MarginContainer/GridContainer/output_name
@onready var _do_not_create_resource = $MarginContainer/GridContainer/do_not_create_resource
var _entry
func _ready():
_adjust_icon(false)
_details_container.hide()
_load_fields()
func set_details(entry: Dictionary):
_entry = entry
func _load_fields():
_split_layers_field.text = "Yes" if _entry.split_layers else "No"
_only_visible_layers.text = "Yes" if _entry.only_visible_layers else "No"
_layer_exclusion_pattern.text = _entry.layer_exclusion_pattern
_output_name.text = _entry.output_name
_output_name.text = _entry.output_name
_do_not_create_resource.text = "Yes" if _entry.do_not_create_resource else "No"
func _adjust_icon(is_visible: bool) -> void:
var icon_name = "GuiTreeArrowDown" if is_visible else "GuiTreeArrowRight"
_details_btn.icon = get_theme_icon(icon_name, "EditorIcons")
func _on_label_pressed():
_details_container.visible = not _details_container.visible
_adjust_icon(_details_container.visible)

View File

@@ -0,0 +1,60 @@
[gd_scene load_steps=2 format=3 uid="uid://b1jb5yierm2bq"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/wizard_nodes/details.gd" id="1_1v4dc"]
[node name="Details" type="VBoxContainer"]
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_1v4dc")
[node name="label" type="Button" parent="."]
layout_mode = 2
text = "Details"
flat = true
alignment = 0
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 10
[node name="GridContainer" type="GridContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/h_separation = 5
columns = 2
[node name="split_layers_label" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
text = "Split layers:"
[node name="split_layers" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
[node name="only_visible_layers_label" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
text = "Only visible layers:"
[node name="only_visible_layers" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
[node name="layer_exclusion_pattern_label" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
text = "Layer Ex Pattern:"
[node name="layer_exclusion_pattern" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
[node name="output_name_label" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
text = "Output name:"
[node name="output_name" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
[node name="do_not_create_resource_label" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
text = "Do not create resource:"
[node name="do_not_create_resource" type="Label" parent="MarginContainer/GridContainer"]
layout_mode = 2
[connection signal="pressed" from="label" to="." method="_on_label_pressed"]

View File

@@ -0,0 +1,6 @@
@tool
extends Label
func set_date(timestamp: String):
self.text = timestamp

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://bs0i357m5d7ho"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/wizard_nodes/import_date.gd" id="1"]
[node name="import_date" type="Label"]
offset_left = 660.0
offset_top = 39.0
offset_right = 774.0
offset_bottom = 53.0
size_flags_vertical = 0
text = "2022-07-18 18:01"
script = ExtResource("1")

View File

@@ -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)

View File

@@ -0,0 +1,35 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/wizard_nodes/list_actions.gd" 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"]

View File

@@ -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

View File

@@ -0,0 +1,6 @@
@tool
extends LineEdit
func set_entry(entry: Dictionary):
self.text = entry.source_file
self.tooltip_text = entry.source_file

View File

@@ -0,0 +1,18 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/docks/wizard/wizard_nodes/source_path.gd" 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 )

View File

@@ -0,0 +1,5 @@
@tool
extends Window
func _on_close_requested():
self.queue_free()

View File

@@ -0,0 +1,14 @@
[gd_scene load_steps=2 format=3 uid="uid://0x3mlxsex7eb"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/imports_manager/aseprite_imports_manager.gd" id="1_wrm15"]
[node name="AsepriteDockImportsWindow" type="Window"]
title = "Aseprite Imports Manager"
initial_position = 1
size = Vector2i(612, 458)
wrap_controls = true
transient = true
min_size = Vector2i(600, 400)
script = ExtResource("1_wrm15")
[connection signal="close_requested" from="." to="." method="_on_close_requested"]

View File

@@ -0,0 +1,330 @@
@tool
extends Panel
const wizard_config = preload("../../config/wizard_config.gd")
var _import_helper = preload("./import_helper.gd").new()
@onready var _tree_container = $MarginContainer/VBoxContainer/HSplitContainer/tree
@onready var _resource_tree = _tree_container.get_resource_tree()
@onready var _details = $MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer
@onready var _nothing_container = $MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/nothing
@onready var _single_item_container = $MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/single_item
@onready var _multiple_items_container = $MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/multiple_items
@onready var _confirmation_warning_container = $MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/confirmation_warning
const supported_types = [
"Sprite2D",
"Sprite3D",
"AnimatedSprite2D",
"AnimatedSprite3D",
"TextureRect",
]
var _selection_count = 0
var _current_buttons_container
var _resources_to_process
var _should_save_in = 0
func _ready():
_set_empty_details_state()
var file_tree = _get_file_tree("res://")
_setup_tree(file_tree)
# Unfortunately godot throws some nasty warnings when trying to save after
# multiple import operations. I implemented this late save as a workaround
func _process(delta):
if _should_save_in > 0:
_should_save_in -= delta
if _should_save_in <= 0:
_should_save_in = 0
_save_all_scenes()
func _get_file_tree(base_path: String, dir_name: String = "") -> Dictionary:
var dir_path = base_path.path_join(dir_name)
var dir = DirAccess.open(dir_path)
var dir_data = { "path": dir_path, "name": dir_name, "children": [], "type": "dir", }
if not dir:
return dir_data
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir() and _is_importable_folder(dir_path, file_name):
var child_data = _get_file_tree(dir_path, file_name)
if not child_data.children.is_empty():
dir_data.children.push_back(child_data)
elif file_name.ends_with(".tscn"):
var file_path = dir_path.path_join(file_name)
var metadata = _get_aseprite_metadata(file_path)
if not metadata.is_empty():
dir_data.children.push_back({
"name": file_name,
"path": file_path,
"resources": metadata,
"type": "file",
})
file_name = dir.get_next()
return dir_data
func _is_importable_folder(dir_path: String, dir_name: String) -> bool:
return dir_path != "res://" or dir_name != "addons"
func _setup_tree(resource_tree: Dictionary) -> void:
_resource_tree.set_column_title(0, "Resource")
var root = _resource_tree.create_item()
_add_items_to_tree(root, resource_tree.children)
func _add_items_to_tree(root: TreeItem, children: Array):
for node in children:
var item: TreeItem = _resource_tree.create_item(root)
item.set_text(0, node.name)
item.set_meta("node", node)
match node.type:
"dir":
item.set_icon(0, get_theme_icon("Folder", "EditorIcons"))
_add_items_to_tree(item, node.children)
"file":
item.set_icon(0, get_theme_icon("PackedScene", "EditorIcons"))
_add_items_to_tree(item, node.resources)
"resource":
item.set_icon(0, get_theme_icon(node.node_type, "EditorIcons"))
if node.has_changes:
item.set_text(0, "%s (*)" % node.name)
func _get_aseprite_metadata(file_path: String) -> Array:
var scene: PackedScene = load(file_path)
var root = scene.instantiate()
var state = scene.get_state()
var resources = []
for i in range(state.get_node_count()):
var node_type = state.get_node_type(i)
if _is_supported_type(node_type):
var node_path = state.get_node_path(i)
var target_node = root.get_node(node_path)
var meta = wizard_config.load_config(target_node)
if meta != null:
resources.push_back({
"type": "resource",
"node_type": node_type,
"name": node_path,
"node_path": node_path,
"node_name": state.get_node_name(i),
"meta": meta,
"scene_path": file_path,
"has_changes": _has_source_changes(target_node, meta.get("source"))
})
return resources
func _has_source_changes(target_node: Node, source_path: String) -> bool:
if not source_path or source_path == "":
return false
var saved_hash = wizard_config.get_source_hash(target_node)
if saved_hash == "":
return false
var current_hash = FileAccess.get_md5(source_path)
return saved_hash != current_hash
func _is_supported_type(node_type: String) -> bool:
return supported_types.has(node_type)
func _open_scene(item: TreeItem) -> void:
var meta = item.get_meta("node")
if meta:
EditorInterface.open_scene_from_path(meta.path)
func _trigger_import(meta: Dictionary) -> void:
# A more elegant way would have been to change the PackedScene directly, however
# during my attempts changing external resources this way was buggy. I decided
# to open and edit the scene via editor with the caveat of having to keep it open afterwards.
EditorInterface.open_scene_from_path(meta.scene_path)
var root_node = EditorInterface.get_edited_scene_root()
if not root_node:
printerr("couldn´t open scene %s" % meta.scene_path)
await _import_helper.import_node(root_node, meta)
print("Import complete: %s (%s) node from %s" % [ meta.node_path, meta.meta.source, meta.scene_path])
func _on_resource_tree_multi_selected(_item: TreeItem, _column: int, selected: bool) -> void:
_confirmation_warning_container.hide()
_resources_to_process = null
if _current_buttons_container != null:
_current_buttons_container.show_buttons()
if selected:
_selection_count += 1
else:
_selection_count -= 1
_nothing_container.hide()
_single_item_container.hide()
_multiple_items_container.hide()
match _selection_count:
0:
_nothing_container.show()
1:
_single_item_container.show()
_set_item_details(_resource_tree.get_selected())
_current_buttons_container = _single_item_container
_:
_multiple_items_container.show()
_multiple_items_container.set_selected_count(_selection_count)
_current_buttons_container = _multiple_items_container
func _set_item_details(item: TreeItem) -> void:
if not item.has_meta("node"):
return
var data = item.get_meta("node")
_single_item_container.set_resource_details(data)
func _on_multiple_items_import_triggered():
var selected_item = _resource_tree.get_next_selected(null)
var all_resources = []
var scenes_to_open = 0
while selected_item != null:
scenes_to_open += _set_all_resources(selected_item.get_meta("node"), all_resources)
selected_item = _resource_tree.get_next_selected(selected_item)
_resources_to_process = all_resources
_show_confirmation_message(scenes_to_open, all_resources.size())
func _on_single_item_import_triggered():
var selected = _resource_tree.get_selected()
var meta = selected.get_meta("node")
if meta.type == "resource":
await _trigger_import(_resource_tree.get_selected().get_meta("node"))
_set_tree_item_as_saved(_resource_tree.get_selected())
_single_item_container.hide_source_change_warning()
EditorInterface.save_scene()
else:
var selected_item = _resource_tree.get_selected()
var all_resources = []
var scenes_to_open = _set_all_resources(selected_item.get_meta("node"), all_resources)
_resources_to_process = all_resources
_show_confirmation_message(scenes_to_open, all_resources.size())
func _on_single_item_open_scene_triggered():
var selected_item = _resource_tree.get_selected()
var meta = selected_item.get_meta("node")
if meta.type == "file":
EditorInterface.open_scene_from_path(meta.path)
else:
EditorInterface.open_scene_from_path(meta.scene_path)
func _set_all_resources(meta: Dictionary, resources: Array):
var scenes_to_open = 0
match meta.type:
"dir":
for c in meta.children:
scenes_to_open += _set_all_resources(c, resources)
"file":
scenes_to_open += 1
for r in meta.resources:
if not resources.has(r):
resources.push_back(r)
"resource":
if not resources.has(meta):
resources.push_back(meta)
return scenes_to_open
func _save_all_scenes():
EditorInterface.save_all_scenes()
_reload_tree()
func _show_confirmation_message(scenes: int, resources: int):
_current_buttons_container.hide_buttons()
if scenes > 1:
_confirmation_warning_container.set_message("You are about to open %s scenes and re-import %s resources. Do you wish to continue?" % [scenes, resources])
else:
_confirmation_warning_container.set_message("You are about to re-import %s resources. Do you wish to continue?" % resources)
_confirmation_warning_container.show()
func _on_resource_tree_refresh_triggered():
_set_empty_details_state()
_reload_tree()
func _reload_tree():
_confirmation_warning_container.hide()
_resources_to_process = null
if _current_buttons_container != null:
_current_buttons_container.show_buttons()
_current_buttons_container = null
_selection_count = 0
_resource_tree.clear()
var file_tree = _get_file_tree("res://")
_setup_tree(file_tree)
func _set_empty_details_state():
_nothing_container.show()
_single_item_container.hide()
_multiple_items_container.hide()
_confirmation_warning_container.hide()
func _set_tree_item_as_saved(item: TreeItem) -> void:
var meta = item.get_meta("node")
meta.has_changes = false
item.set_meta("node", meta)
item.set_text(0, meta.name)
func _on_confirmation_warning_warning_confirmed():
_confirmation_warning_container.hide()
_current_buttons_container.show_buttons()
for resource in _resources_to_process:
await _trigger_import(resource)
EditorInterface.mark_scene_as_unsaved()
_resources_to_process = null
_should_save_in = 1
func _on_confirmation_warning_warning_declined():
_confirmation_warning_container.hide()
_current_buttons_container.show_buttons()
_resources_to_process = null

View File

@@ -0,0 +1,87 @@
[gd_scene load_steps=7 format=3 uid="uid://ci67r2f2btg5"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/imports_manager/dock_imports_panel.gd" id="1_1xyeb"]
[ext_resource type="PackedScene" uid="uid://cisgsfvp4nf1g" path="res://addons/AsepriteWizard/interface/shared/tree/resource_tree.tscn" id="2_d1s4o"]
[ext_resource type="PackedScene" uid="uid://qgmln507kjnm" path="res://addons/AsepriteWizard/interface/shared/tree/tree_selection_confirmation_warning.tscn" id="3_2us73"]
[ext_resource type="PackedScene" uid="uid://dnlk2yep7teea" path="res://addons/AsepriteWizard/interface/imports_manager/tree_selection_single_item.tscn" id="3_4ufqa"]
[ext_resource type="PackedScene" uid="uid://bhtu6mlwmthqo" path="res://addons/AsepriteWizard/interface/imports_manager/tree_selection_multiple_items.tscn" id="3_pw8ds"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_edrvq"]
[node name="dock_imports" type="Panel"]
custom_minimum_size = Vector2(600, 400)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_styles/panel = SubResource("StyleBoxEmpty_edrvq")
script = ExtResource("1_1xyeb")
[node name="MarginContainer" type="MarginContainer" parent="."]
custom_minimum_size = Vector2(400, 300)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="HSplitContainer" type="HSplitContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="tree" parent="MarginContainer/VBoxContainer/HSplitContainer" instance=ExtResource("2_d1s4o")]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer/HSplitContainer"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer"]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/MarginContainer"]
layout_mode = 2
text = "Details"
horizontal_alignment = 1
[node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="nothing" type="Label" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "Nothing selected"
horizontal_alignment = 1
[node name="single_item" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("3_4ufqa")]
layout_mode = 2
[node name="multiple_items" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("3_pw8ds")]
layout_mode = 2
[node name="confirmation_warning" parent="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer" instance=ExtResource("3_2us73")]
layout_mode = 2
[connection signal="multi_selected" from="MarginContainer/VBoxContainer/HSplitContainer/tree" to="." method="_on_resource_tree_multi_selected"]
[connection signal="refresh_triggered" from="MarginContainer/VBoxContainer/HSplitContainer/tree" to="." method="_on_resource_tree_refresh_triggered"]
[connection signal="import_triggered" from="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/single_item" to="." method="_on_single_item_import_triggered"]
[connection signal="open_scene_triggered" from="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/single_item" to="." method="_on_single_item_open_scene_triggered"]
[connection signal="import_triggered" from="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/multiple_items" to="." method="_on_multiple_items_import_triggered"]
[connection signal="warning_confirmed" from="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/confirmation_warning" to="." method="_on_confirmation_warning_warning_confirmed"]
[connection signal="warning_declined" from="MarginContainer/VBoxContainer/HSplitContainer/MarginContainer/VBoxContainer/confirmation_warning" to="." method="_on_confirmation_warning_warning_declined"]

View File

@@ -0,0 +1,123 @@
@tool
extends RefCounted
const wizard_config = preload("../../config/wizard_config.gd")
const result_code = preload("../../config/result_codes.gd")
var _sprite_animation_creator = preload("../../creators/animation_player/sprite_animation_creator.gd").new()
var _texture_rect_animation_creator = preload("../../creators/animation_player/texture_rect_animation_creator.gd").new()
var _static_texture_creator = preload("../../creators/static_texture/texture_creator.gd").new()
var _sprite_frames_creator = preload("../../creators/sprite_frames/sprite_frames_creator.gd").new()
var _aseprite_file_exporter = preload("../../aseprite/file_exporter.gd").new()
var _config = preload("../../config/config.gd").new()
func import_node(root_node: Node, meta: Dictionary) -> void:
var node = root_node.get_node(meta.node_path)
if node == null:
printerr("Node not found: %s" % meta.node_path)
return
if node is AnimatedSprite2D or node is AnimatedSprite3D:
await _sprite_frames_import(node, meta)
else:
await _animation_import(node, root_node, meta)
func _sprite_frames_import(node: Node, resource_config: Dictionary) -> void:
var config = resource_config.meta
if not config.source:
printerr("Node config missing information.")
return
var source = ProjectSettings.globalize_path(config.source)
var options = _parse_import_options(config, resource_config.scene_path.get_base_dir())
var aseprite_output = _aseprite_file_exporter.generate_aseprite_file(source, options)
if not aseprite_output.is_ok:
printerr(result_code.get_error_message(aseprite_output.code))
return
EditorInterface.get_resource_filesystem().scan()
await EditorInterface.get_resource_filesystem().filesystem_changed
_sprite_frames_creator.create_animations(node, aseprite_output.content, { "slice": options.slice })
wizard_config.set_source_hash(node, FileAccess.get_md5(source))
_handle_cleanup(aseprite_output.content)
func _animation_import(node: Node, root_node: Node, resource_config: Dictionary) -> void:
if not resource_config.meta.source:
printerr("Node config missing information.")
return
if resource_config.meta.get("i_mode", 0) == 0:
await _import_to_animation_player(node, root_node, resource_config)
else:
await _import_static(node, resource_config)
func _import_to_animation_player(node: Node, root: Node, resource_config: Dictionary) -> void:
var config = resource_config.meta
var source = ProjectSettings.globalize_path(config.source)
var options = _parse_import_options(config, resource_config.scene_path.get_base_dir())
var aseprite_output = _aseprite_file_exporter.generate_aseprite_file(source, options)
if not aseprite_output.is_ok:
printerr(result_code.get_error_message(aseprite_output.code))
return
EditorInterface.get_resource_filesystem().scan()
await EditorInterface.get_resource_filesystem().filesystem_changed
var anim_options = {
"keep_anim_length": config.keep_anim_length,
"cleanup_hide_unused_nodes": config.get("set_vis_track"),
"slice": config.get("slice", ""),
}
var animation_creator = _texture_rect_animation_creator if node is TextureRect else _sprite_animation_creator
animation_creator.create_animations(node, root.get_node(config.player), aseprite_output.content, anim_options)
wizard_config.set_source_hash(node, FileAccess.get_md5(source))
_handle_cleanup(aseprite_output.content)
func _import_static(node: Node, resource_config: Dictionary) -> void:
var config = resource_config.meta
var source = ProjectSettings.globalize_path(config.source)
var options = _parse_import_options(config, resource_config.scene_path.get_base_dir())
options["first_frame_only"] = true
var aseprite_output = _aseprite_file_exporter.generate_aseprite_file(source, options)
if not aseprite_output.is_ok:
printerr(result_code.get_error_message(aseprite_output.code))
return
EditorInterface.get_resource_filesystem().scan()
await EditorInterface.get_resource_filesystem().filesystem_changed
_static_texture_creator.load_texture(node, aseprite_output.content, { "slice": options.slice })
wizard_config.set_source_hash(node, FileAccess.get_md5(source))
_handle_cleanup(aseprite_output.content)
func _parse_import_options(config: Dictionary, scene_base_path: String) -> Dictionary:
return {
"output_folder": config.o_folder if config.o_folder != "" else scene_base_path,
"exception_pattern": config.o_ex_p,
"only_visible_layers": config.only_visible,
"output_filename": config.o_name,
"layer": config.get("layer"),
"slice": config.get("slice", ""),
}
func _handle_cleanup(aseprite_content):
if _config.should_remove_source_files():
DirAccess.remove_absolute(aseprite_content.data_file)
EditorInterface.get_resource_filesystem().scan()

View File

@@ -0,0 +1,28 @@
@tool
extends MarginContainer
signal dock_requested
enum Tabs {
DOCK_IMPORTS = 0,
}
@onready var _tabs: TabContainer = $TabContainer
@onready var _dock_button: Button = $dock_button
func _ready():
_tabs.set_tab_title(Tabs.DOCK_IMPORTS, "Dock Imports")
_dock_button.icon = get_theme_icon("MakeFloating", "EditorIcons")
set_as_floating()
func _on_dock_button_pressed():
dock_requested.emit()
func set_as_floating():
_dock_button.tooltip_text = "Dock window"
func set_as_docked():
_dock_button.tooltip_text = "Undock window"

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
@tool
extends LineEdit
signal change_finished(text: String)
@export var debounce_time_in_seconds: float = 0.3
var _time_since_last_change: float = 0.0
var _has_pending_changes: bool = false
func _process(delta: float) -> void:
if _has_pending_changes:
_time_since_last_change += delta
if _time_since_last_change > debounce_time_in_seconds:
_has_pending_changes = false
change_finished.emit(self.text)
func _on_text_changed(_new_text: String) -> void:
_has_pending_changes = true
_time_since_last_change = 0

View File

@@ -0,0 +1,22 @@
@tool
extends VBoxContainer
signal import_triggered
@onready var _import_message = $message
@onready var _import_button = $buttons
func set_selected_count(number_of_items: int) -> void:
_import_message.text = "%2d items selected" % number_of_items
func show_buttons():
_import_button.show()
func hide_buttons():
_import_button.hide()
func _on_import_selected_button_up():
import_triggered.emit()

View File

@@ -0,0 +1,25 @@
[gd_scene load_steps=2 format=3 uid="uid://bhtu6mlwmthqo"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/imports_manager/tree_selection_multiple_items.gd" id="1_beamo"]
[node name="multiple_items" type="VBoxContainer"]
visible = false
size_flags_vertical = 3
script = ExtResource("1_beamo")
[node name="message" type="Label" parent="."]
layout_mode = 2
size_flags_vertical = 6
text = "Multiple items selected
"
horizontal_alignment = 1
[node name="buttons" type="HFlowContainer" parent="."]
layout_mode = 2
[node name="import_selected" type="Button" parent="buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import all"
[connection signal="button_up" from="buttons/import_selected" to="." method="_on_import_selected_button_up"]

View File

@@ -0,0 +1,141 @@
@tool
extends VBoxContainer
signal import_triggered
signal open_scene_triggered
@onready var _name = $GridContainer/name_value
@onready var _type = $GridContainer/type_value
@onready var _path = $GridContainer/path_value
@onready var _source_label = $GridContainer/source_file_label
@onready var _source = $GridContainer/source_file_value
@onready var _layer_label = $GridContainer/layer_label
@onready var _layer = $GridContainer/layer_value
@onready var _slice_label = $GridContainer/slice_label
@onready var _slice = $GridContainer/slice_value
@onready var _o_name_label = $GridContainer/o_name_label
@onready var _o_name = $GridContainer/o_name_value
@onready var _o_folder_label = $GridContainer/o_folder_label
@onready var _o_folder_value = $GridContainer/o_folder_value
@onready var _resource_buttons = $resource_buttons
@onready var _dir_buttons = $dir_buttons
@onready var _scene_buttons = $scene_buttons
@onready var _source_change_warning = $source_changed_warning
@onready var _resource_only_fields = [
_source_label,
_source,
_layer_label,
_layer,
_slice_label,
_slice,
_o_name_label,
_o_name,
_o_folder_label,
_o_folder_value,
_source_change_warning,
]
var _current_resource_type = "resource"
var _resource_config: Dictionary = {}
func _ready():
_source_change_warning.set_text("Source file changed since last import")
_source_change_warning.hide()
func set_resource_details(resource_details: Dictionary) -> void:
_resource_config = resource_details
_resource_buttons.hide()
_dir_buttons.hide()
_scene_buttons.hide()
_source_change_warning.hide()
_current_resource_type = resource_details.type
match resource_details.type:
"dir":
_name.text = resource_details.name
_type.text = "Folder"
_path.text = resource_details.path
_hide_resource_fields()
_dir_buttons.show()
"file":
_name.text = resource_details.name
_type.text = "File"
_path.text = resource_details.path
_hide_resource_fields()
_scene_buttons.show()
"resource":
_name.text = resource_details.node_name
_type.text = resource_details.node_type
_path.text = resource_details.node_path
var meta = resource_details.meta
_source.text = meta.source
_layer.text = "All" if meta.get("layer", "") == "" else meta.layer
_slice.text = "All" if meta.get("slice", "") == "" else meta.slice
var folder = resource_details.scene_path.get_base_dir() if meta.get("o_folder", "") == "" else meta.o_folder
var file_name = "" if meta.get("o_name", "") == "" else meta.o_name
if _layer.text != "All":
file_name += _layer.text
elif file_name == "":
file_name = meta.source.get_basename().get_file()
_o_name.text = "%s/%s.png" % [folder, file_name]
_show_resource_fields()
_resource_buttons.show()
_source_change_warning.visible = resource_details.has_changes
func _hide_resource_fields():
for f in _resource_only_fields:
f.hide()
func _show_resource_fields():
for f in _resource_only_fields:
f.show()
func show_buttons():
match _current_resource_type:
"resource":
_resource_buttons.show()
"scene":
_scene_buttons.show()
_:
_dir_buttons.show()
func hide_buttons():
_resource_buttons.hide()
_dir_buttons.hide()
_scene_buttons.hide()
func hide_source_change_warning():
_source_change_warning.hide()
func _on_show_dir_in_fs_button_up():
EditorInterface.get_file_system_dock().navigate_to_path(_path.text)
func _on_import_all_button_up():
import_triggered.emit()
func _on_import_button_up():
import_triggered.emit()
func _on_open_scene_button_up():
open_scene_triggered.emit()

View File

@@ -0,0 +1,158 @@
[gd_scene load_steps=3 format=3 uid="uid://dnlk2yep7teea"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/imports_manager/tree_selection_single_item.gd" id="1_bb3ui"]
[ext_resource type="PackedScene" uid="uid://c1l0bk12iwln3" path="res://addons/AsepriteWizard/interface/shared/tree/inline_warning_panel.tscn" id="2_weuqf"]
[node name="single_item" type="VBoxContainer"]
visible = false
script = ExtResource("1_bb3ui")
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/h_separation = 10
columns = 2
[node name="type_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Type"
[node name="type_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="name_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Name"
[node name="name_value" type="Label" parent="GridContainer"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
autowrap_mode = 2
[node name="path_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Path"
[node name="path_value" type="Label" parent="GridContainer"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
autowrap_mode = 1
[node name="HSeparator" type="HSeparator" parent="GridContainer"]
layout_mode = 2
[node name="HSeparator2" type="HSeparator" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="source_file_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Aseprite File"
[node name="source_file_value" type="Label" parent="GridContainer"]
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
autowrap_mode = 1
[node name="layer_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Layer"
[node name="layer_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="slice_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Slice"
[node name="slice_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="o_folder_label" type="Label" parent="GridContainer"]
visible = false
layout_mode = 2
size_flags_vertical = 0
text = "Output folder"
[node name="o_folder_value" type="Label" parent="GridContainer"]
visible = false
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "-"
[node name="o_name_label" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_vertical = 0
text = "Spritesheet name"
[node name="o_name_value" type="Label" parent="GridContainer"]
layout_mode = 2
text = "-"
[node name="source_changed_warning" parent="." instance=ExtResource("2_weuqf")]
layout_mode = 2
[node name="resource_buttons" type="HFlowContainer" parent="."]
visible = false
layout_mode = 2
[node name="import" type="Button" parent="resource_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import"
[node name="open_scene" type="Button" parent="resource_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Open Scene"
[node name="scene_buttons" type="HFlowContainer" parent="."]
visible = false
layout_mode = 2
[node name="import_all" type="Button" parent="scene_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import all"
[node name="open_scene" type="Button" parent="scene_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Open Scene"
[node name="dir_buttons" type="HFlowContainer" parent="."]
visible = false
layout_mode = 2
[node name="import_all" type="Button" parent="dir_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Re-Import all"
[node name="show_dir_in_fs" type="Button" parent="dir_buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Show In FileSystem"
[connection signal="button_up" from="resource_buttons/import" to="." method="_on_import_button_up"]
[connection signal="button_up" from="resource_buttons/open_scene" to="." method="_on_open_scene_button_up"]
[connection signal="button_up" from="scene_buttons/import_all" to="." method="_on_import_all_button_up"]
[connection signal="button_up" from="scene_buttons/open_scene" to="." method="_on_open_scene_button_up"]
[connection signal="button_up" from="dir_buttons/import_all" to="." method="_on_import_all_button_up"]
[connection signal="button_up" from="dir_buttons/show_dir_in_fs" to="." method="_on_show_dir_in_fs_button_up"]

View File

@@ -0,0 +1,15 @@
@tool
extends Button
signal node_dropped(node_path)
func _can_drop_data(_pos, data):
if data.type == "nodes":
var node = get_node(data.nodes[0])
return node is AnimationPlayer
return false
func _drop_data(_pos, data):
var path = data.nodes[0]
node_dropped.emit(path)

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://x1f1t87m582u"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/shared/animation_player_drop_button.gd" id="1_tfmxw"]
[node name="options" type="OptionButton"]
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
script = ExtResource("1_tfmxw")

View File

@@ -0,0 +1,14 @@
@tool
extends Button
signal dir_dropped(path)
func _can_drop_data(_pos, data):
if data.type == "files_and_dirs":
var dir_access = DirAccess.open(data.files[0])
return dir_access != null
return false
func _drop_data(_pos, data):
dir_dropped.emit(data.files[0])

View File

@@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://cwvgnm3o7eed2"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/shared/dir_drop_button.gd" id="1_7uqph"]
[node name="button" type="Button"]
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "[empty]"
clip_text = true
script = ExtResource("1_7uqph")

View File

@@ -0,0 +1,15 @@
@tool
extends Button
signal aseprite_file_dropped(path)
func _can_drop_data(_pos, data):
if data.type == "files":
var extension = data.files[0].get_extension()
return extension == "ase" or extension == "aseprite"
return false
func _drop_data(_pos, data):
var path = data.files[0]
aseprite_file_dropped.emit(path)

View File

@@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://dj1uo3blocr8e"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/shared/source_drop_button.gd" id="1_smfgi"]
[node name="source_drop_button" type="Button"]
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
text = "[empty]"
clip_text = true
script = ExtResource("1_smfgi")

View File

@@ -0,0 +1,19 @@
@tool
extends PanelContainer
@onready var _message = $MarginContainer/HBoxContainer/Label
func _ready():
_configure_source_warning()
func _configure_source_warning():
var sb = self.get_theme_stylebox("panel")
var color = EditorInterface.get_editor_settings().get_setting("interface/theme/accent_color")
color.a = 0.2
sb.bg_color = color
self.get_node("MarginContainer/HBoxContainer/Icon").texture = get_theme_icon("NodeInfo", "EditorIcons")
func set_text(text: String):
_message.text = text

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,55 @@
@tool
extends VBoxContainer
signal refresh_triggered
signal multi_selected(item: TreeItem, column: int, selected: bool)
@onready var _tree: Tree = $Tree
func _on_tree_filter_change_finished(text):
var tree_root: TreeItem = _tree.get_root()
if text == "":
tree_root.call_recursive("set", "visible", true)
return
tree_root.call_recursive("set", "visible", false)
_make_matching_children_visible(tree_root, text.to_lower())
func _make_matching_children_visible(tree_root: TreeItem, text: String) -> void:
for c in tree_root.get_children():
if c.get_text(0).to_lower().contains(text):
c.visible = true
_ensure_parent_visible(c)
_make_matching_children_visible(c, text)
func _ensure_parent_visible(tree_item: TreeItem) -> void:
var node_parent = tree_item.get_parent()
if node_parent != null and not node_parent.visible:
node_parent.visible = true
_ensure_parent_visible(node_parent)
func _on_expand_all_pressed():
var tree_root: TreeItem = _tree.get_root()
tree_root.set_collapsed_recursive(false)
func _on_collapse_all_pressed():
var tree_root: TreeItem = _tree.get_root()
tree_root.set_collapsed_recursive(true)
tree_root.collapsed = false
func _on_refresh_tree_pressed():
refresh_triggered.emit()
func _on_tree_multi_selected(item: TreeItem, column: int, selected: bool):
multi_selected.emit(item, column, selected)
func get_resource_tree() -> Tree:
return _tree

View File

@@ -0,0 +1,51 @@
[gd_scene load_steps=3 format=3 uid="uid://cisgsfvp4nf1g"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/shared/tree/resource_tree.gd" id="1_io4rc"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/imports_manager/tree_filter_field.gd" id="1_q7epo"]
[node name="resource_tree" type="VBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
script = ExtResource("1_io4rc")
[node name="buttons" type="HFlowContainer" parent="."]
layout_mode = 2
[node name="tree_filter" type="LineEdit" parent="buttons"]
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "Filter..."
clear_button_enabled = true
script = ExtResource("1_q7epo")
[node name="expand_all" type="Button" parent="buttons"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
text = "Expand All"
[node name="collapse_all" type="Button" parent="buttons"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
text = "Collapse All"
[node name="refresh_tree" type="Button" parent="buttons"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
text = "Refresh Tree"
[node name="Tree" type="Tree" parent="."]
layout_mode = 2
size_flags_vertical = 3
hide_root = true
select_mode = 2
[connection signal="change_finished" from="buttons/tree_filter" to="." method="_on_tree_filter_change_finished"]
[connection signal="text_changed" from="buttons/tree_filter" to="buttons/tree_filter" method="_on_text_changed"]
[connection signal="pressed" from="buttons/expand_all" to="." method="_on_expand_all_pressed"]
[connection signal="pressed" from="buttons/collapse_all" to="." method="_on_collapse_all_pressed"]
[connection signal="pressed" from="buttons/refresh_tree" to="." method="_on_refresh_tree_pressed"]
[connection signal="multi_selected" from="Tree" to="." method="_on_tree_multi_selected"]

View File

@@ -0,0 +1,18 @@
@tool
extends VBoxContainer
signal warning_confirmed
signal warning_declined
@onready var _warning_message = $MarginContainer/warning_message
func set_message(text: String) -> void:
_warning_message.text = text
func _on_confirm_button_up():
warning_confirmed.emit()
func _on_cancel_button_up():
warning_declined.emit()

View File

@@ -0,0 +1,34 @@
[gd_scene load_steps=2 format=3 uid="uid://qgmln507kjnm"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/interface/shared/tree/tree_selection_confirmation_warning.gd" id="1_7gtu1"]
[node name="confirmation_warning" type="VBoxContainer"]
script = ExtResource("1_7gtu1")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="warning_message" type="Label" parent="MarginContainer"]
custom_minimum_size = Vector2(100, 0)
layout_mode = 2
autowrap_mode = 2
[node name="buttons" type="HFlowContainer" parent="."]
layout_mode = 2
[node name="confirm" type="Button" parent="buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Confirm"
[node name="cancel" type="Button" parent="buttons"]
layout_mode = 2
size_flags_horizontal = 3
text = "Cancel"
[connection signal="button_up" from="buttons/confirm" to="." method="_on_confirm_button_up"]
[connection signal="button_up" from="buttons/cancel" to="." method="_on_cancel_button_up"]