This commit is contained in:
2024-05-28 11:03:13 -05:00
commit 277fb03a69
75 changed files with 5206 additions and 0 deletions

View File

@@ -0,0 +1,295 @@
@tool
extends RefCounted
# GLOBAL SETTINGS
const _CONFIG_SECTION_KEY = 'aseprite'
const _COMMAND_KEY = 'aseprite/general/command_path'
# PROJECT SETTINGS
# animation import defaults
const _DEFAULT_EXCLUSION_PATTERN_KEY = 'aseprite/animation/layers/exclusion_pattern'
const _DEFAULT_ONLY_VISIBLE_LAYERS = 'aseprite/animation/layers/only_include_visible_layers_by_default'
const _DEFAULT_LOOP_EX_PREFIX = '_'
const _LOOP_ENABLED = 'aseprite/animation/loop/enabled'
const _LOOP_EXCEPTION_PREFIX = 'aseprite/animation/loop/exception_prefix'
const _USE_METADATA = 'aseprite/animation/storage/use_metadata'
# cleanup
const _REMOVE_SOURCE_FILES_KEY = 'aseprite/import/cleanup/remove_json_file'
const _SET_VISIBLE_TRACK_AUTOMATICALLY = 'aseprite/import/cleanup/automatically_hide_sprites_not_in_animation'
# automatic importer
const _IMPORTER_ENABLE_KEY = 'aseprite/import/import_plugin/enable_automatic_importer'
const _DEFAULT_IMPORTER_KEY = 'aseprite/import/import_plugin/default_automatic_importer'
const IMPORTER_SPRITEFRAMES_NAME = "SpriteFrames"
const IMPORTER_NOOP_NAME = "No Import"
const IMPORTER_TILESET_TEXTURE_NAME = "Tileset Texture"
const IMPORTER_STATIC_TEXTURE_NAME = "Static Texture"
# wizard history
const _HISTORY_CONFIG_FILE_CFG_KEY = 'aseprite/wizard/history/cache_file_path'
const _HISTORY_SINGLE_ENTRY_KEY = 'aseprite/wizard/history/keep_one_entry_per_source_file'
const _DEFAULT_HISTORY_CONFIG_FILE_PATH = 'res://.aseprite_wizard_history'
# IMPORT SETTINGS
const _I_LAST_SOURCE_PATH_KEY = 'i_source'
const _I_LAST_OUTPUT_DIR_KEY = 'i_output'
const _I_SHOULD_SPLIT_LAYERS_KEY = 'i_split_layers'
const _I_EXCEPTIONS_KEY = 'i_exceptions_key'
const _I_ONLY_VISIBLE_LAYERS_KEY = 'i_only_visible_layers'
const _I_CUSTOM_NAME_KEY = 'i_custom_name'
const _I_DO_NOT_CREATE_RES_KEY = 'i_disable_resource_creation'
# export
const _EXPORTER_ENABLE_KEY = 'aseprite/animation/storage/enable_metadata_removal_on_export'
var _editor_settings: EditorSettings
# INTERFACE SETTINGS
var _plugin_icons: Dictionary
#######################################################
# GLOBAL CONFIGS
######################################################
func default_command() -> String:
return 'aseprite'
func is_command_or_control_pressed() -> String:
var command = _editor_settings.get(_COMMAND_KEY) if _editor_settings.has_setting(_COMMAND_KEY) else ""
return command if command != "" else default_command()
#######################################################
# PROJECT SETTINGS
######################################################
# remove this config in the next major version
func is_importer_enabled() -> bool:
return _get_project_setting(_IMPORTER_ENABLE_KEY, false)
func get_default_importer() -> String:
return _get_project_setting(_DEFAULT_IMPORTER_KEY, IMPORTER_SPRITEFRAMES_NAME if is_importer_enabled() else IMPORTER_NOOP_NAME)
func is_exporter_enabled() -> bool:
return _get_project_setting(_EXPORTER_ENABLE_KEY, true)
func should_remove_source_files() -> bool:
return _get_project_setting(_REMOVE_SOURCE_FILES_KEY, true)
func is_default_animation_loop_enabled() -> bool:
return _get_project_setting(_LOOP_ENABLED, true)
func get_animation_loop_exception_prefix() -> String:
return _get_project_setting(_LOOP_EXCEPTION_PREFIX, _DEFAULT_LOOP_EX_PREFIX)
func is_use_metadata_enabled() -> bool:
return _get_project_setting(_USE_METADATA, true)
func get_default_exclusion_pattern() -> String:
return _get_project_setting(_DEFAULT_EXCLUSION_PATTERN_KEY, "")
func should_include_only_visible_layers_by_default() -> bool:
return _get_project_setting(_DEFAULT_ONLY_VISIBLE_LAYERS, false)
func is_single_file_history() -> bool:
return ProjectSettings.get(_HISTORY_SINGLE_ENTRY_KEY) == true
func get_import_history() -> Array:
var history = []
var history_path := _get_history_file_path()
if not FileAccess.file_exists(history_path):
return history
var file_object = FileAccess.open(history_path, FileAccess.READ)
while not file_object.eof_reached():
var line = file_object.get_line()
if line:
var test_json_conv = JSON.new()
test_json_conv.parse(line)
history.push_back(test_json_conv.get_data())
return history
func is_set_visible_track_automatically_enabled() -> bool:
return _get_project_setting(_SET_VISIBLE_TRACK_AUTOMATICALLY, false)
# history is saved and retrieved line-by-line so
# file becomes version control friendly
func save_import_history(history: Array):
var file = FileAccess.open(_get_history_file_path(), FileAccess.WRITE)
for entry in history:
file.store_line(JSON.new().stringify(entry))
file = null
func _get_history_file_path() -> String:
return _get_project_setting(_HISTORY_CONFIG_FILE_CFG_KEY, _DEFAULT_HISTORY_CONFIG_FILE_PATH)
#######################################################
# IMPORT CONFIGS
######################################################
func get_last_source_path() -> String:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_LAST_SOURCE_PATH_KEY, "")
func set_last_source_path(source_path: String) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_LAST_SOURCE_PATH_KEY, source_path)
func get_last_output_path() -> String:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_LAST_OUTPUT_DIR_KEY, "")
func set_last_output_path(output_path: String) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_LAST_OUTPUT_DIR_KEY, output_path)
func should_split_layers() -> bool:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_SHOULD_SPLIT_LAYERS_KEY, false)
func set_split_layers(should_split: bool) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_SHOULD_SPLIT_LAYERS_KEY, false)
func get_exception_pattern() -> String:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_EXCEPTIONS_KEY, "")
func set_exception_pattern(pattern: String) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_EXCEPTIONS_KEY, pattern)
func should_include_only_visible_layers() -> bool:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_ONLY_VISIBLE_LAYERS_KEY, false)
func set_include_only_visible_layers(include_only_visible: bool) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_ONLY_VISIBLE_LAYERS_KEY, include_only_visible)
func get_last_custom_name() -> String:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_CUSTOM_NAME_KEY, "")
func set_custom_name(custom_name: String) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_CUSTOM_NAME_KEY, custom_name)
func should_not_create_resource() -> bool:
return _editor_settings.get_project_metadata(_CONFIG_SECTION_KEY, _I_DO_NOT_CREATE_RES_KEY, false)
func set_do_not_create_resource(do_no_create: bool) -> void:
_editor_settings.set_project_metadata(_CONFIG_SECTION_KEY, _I_DO_NOT_CREATE_RES_KEY, do_no_create)
#######################################################
# INTERFACE SETTINGS
######################################################
func set_icons(plugin_icons: Dictionary) -> void:
_plugin_icons = plugin_icons
func get_icon(icon_name: String) -> Texture2D:
return _plugin_icons[icon_name]
#######################################################
# INITIALIZATION
######################################################
func initialize_project_settings():
_initialize_project_cfg(_DEFAULT_EXCLUSION_PATTERN_KEY, "", TYPE_STRING)
_initialize_project_cfg(_DEFAULT_ONLY_VISIBLE_LAYERS, false, TYPE_BOOL)
_initialize_project_cfg(_LOOP_ENABLED, true, TYPE_BOOL)
_initialize_project_cfg(_LOOP_EXCEPTION_PREFIX, _DEFAULT_LOOP_EX_PREFIX, TYPE_STRING)
_initialize_project_cfg(_USE_METADATA, true, TYPE_BOOL)
_initialize_project_cfg(_REMOVE_SOURCE_FILES_KEY, true, TYPE_BOOL)
_initialize_project_cfg(
_DEFAULT_IMPORTER_KEY,
IMPORTER_SPRITEFRAMES_NAME if is_importer_enabled() else IMPORTER_NOOP_NAME,
TYPE_STRING,
PROPERTY_HINT_ENUM,
"%s,%s,%s,%s" % [IMPORTER_NOOP_NAME, IMPORTER_SPRITEFRAMES_NAME, IMPORTER_TILESET_TEXTURE_NAME, IMPORTER_STATIC_TEXTURE_NAME]
)
_initialize_project_cfg(_EXPORTER_ENABLE_KEY, true, TYPE_BOOL)
_initialize_project_cfg(_HISTORY_CONFIG_FILE_CFG_KEY, _DEFAULT_HISTORY_CONFIG_FILE_PATH, TYPE_STRING, PROPERTY_HINT_GLOBAL_FILE)
_initialize_project_cfg(_HISTORY_SINGLE_ENTRY_KEY, false, TYPE_BOOL)
_initialize_project_cfg(_SET_VISIBLE_TRACK_AUTOMATICALLY, false, TYPE_BOOL)
ProjectSettings.save()
_initialize_editor_cfg(_COMMAND_KEY, default_command(), TYPE_STRING)
func clear_project_settings():
var _all_settings = [
_DEFAULT_EXCLUSION_PATTERN_KEY,
_LOOP_ENABLED,
_LOOP_EXCEPTION_PREFIX,
_USE_METADATA,
_REMOVE_SOURCE_FILES_KEY,
_DEFAULT_IMPORTER_KEY,
_EXPORTER_ENABLE_KEY,
_HISTORY_CONFIG_FILE_CFG_KEY,
_HISTORY_SINGLE_ENTRY_KEY,
_SET_VISIBLE_TRACK_AUTOMATICALLY,
_DEFAULT_ONLY_VISIBLE_LAYERS,
]
for key in _all_settings:
ProjectSettings.clear(key)
ProjectSettings.save()
func _initialize_project_cfg(key: String, default_value, type: int, hint: int = PROPERTY_HINT_NONE, hint_string = null):
if not ProjectSettings.has_setting(key):
ProjectSettings.set(key, default_value)
ProjectSettings.set_initial_value(key, default_value)
ProjectSettings.add_property_info({
"name": key,
"type": type,
"hint": hint,
"hint_string": hint_string,
})
func _get_project_setting(key: String, default_value):
if not ProjectSettings.has_setting(key):
return default_value
var p = ProjectSettings.get(key)
return p if p != null else default_value
func _initialize_editor_cfg(key: String, default_value, type: int, hint: int = PROPERTY_HINT_NONE):
if not _editor_settings.has_setting(key):
_editor_settings.set(key, default_value)
_editor_settings.set_initial_value(key, default_value, false)
_editor_settings.add_property_info({
"name": key,
"type": type,
"hint": hint,
})

View File

@@ -0,0 +1,33 @@
@tool
extends PopupPanel
var _config
@onready var _aseprite_command_field = $MarginContainer/VBoxContainer/VBoxContainer/HBoxContainer/aseprite_command
@onready var _version_label = $MarginContainer/VBoxContainer/VBoxContainer/version_found
func _ready():
_aseprite_command_field.text = _config.is_command_or_control_pressed()
_version_label.modulate.a = 0
func init(config):
_config = config
func _on_close_button_up():
self.hide()
func _on_test_pressed():
var output = []
if _test_command(output):
_version_label.text = "%s found." % "\n".join(PackedStringArray(output)).strip_edges()
else:
_version_label.text = "Command not found."
_version_label.modulate.a = 1
func _test_command(output):
var exit_code = OS.execute(_aseprite_command_field.text, ['--version'], output, true, true)
return exit_code == 0

View File

@@ -0,0 +1,80 @@
[gd_scene load_steps=2 format=3 uid="uid://d0whlywijwa6s"]
[ext_resource type="Script" path="res://addons/AsepriteWizard/config/config_dialog.gd" id="1"]
[node name="config_dialog" type="PopupPanel"]
title = "Aseprite Wizard Config"
size = Vector2i(624, 236)
visible = true
unresizable = false
borderless = false
min_size = Vector2i(624, 236)
content_scale_mode = 1
script = ExtResource("1")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 4.0
offset_top = 4.0
offset_right = -532.0
offset_bottom = -416.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 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
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "This configuration moved.
- To edit the aseprite command path, go to Editor > Editor Settings > Aseprite.
- To edit project specific settings, go to Project > Project Settings > Aseprite."
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Aseprite Command" type="Label" parent="MarginContainer/VBoxContainer/VBoxContainer"]
layout_mode = 2
tooltip_text = "Define the path for Aseprite command"
mouse_filter = 1
text = "Aseprite Command Path"
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="aseprite_command" type="LineEdit" parent="MarginContainer/VBoxContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
editable = false
caret_blink = true
[node name="test" type="Button" parent="MarginContainer/VBoxContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Test"
[node name="version_found" type="Label" parent="MarginContainer/VBoxContainer/VBoxContainer"]
modulate = Color(1, 1, 1, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "Aseprite version found"
[node name="VBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
alignment = 2
[node name="close" type="Button" parent="MarginContainer/VBoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Close"
[connection signal="pressed" from="MarginContainer/VBoxContainer/VBoxContainer/HBoxContainer/test" to="." method="_on_test_pressed"]
[connection signal="button_up" from="MarginContainer/VBoxContainer/VBoxContainer2/close" to="." method="_on_close_button_up"]

View File

@@ -0,0 +1,37 @@
@tool
extends RefCounted
const SUCCESS = 0
const ERR_ASEPRITE_CMD_NOT_FOUND = 1
const ERR_SOURCE_FILE_NOT_FOUND = 2
const ERR_OUTPUT_FOLDER_NOT_FOUND = 3
const ERR_ASEPRITE_EXPORT_FAILED = 4
const ERR_UNKNOWN_EXPORT_MODE = 5
const ERR_NO_VALID_LAYERS_FOUND = 6
const ERR_INVALID_ASEPRITE_SPRITESHEET = 7
static func get_error_message(code: int):
match code:
ERR_ASEPRITE_CMD_NOT_FOUND:
return "Aseprite command failed. Please, check if the right command is in your PATH or configured through \"Project > Tools > Aseprite Wizard Config\"."
ERR_SOURCE_FILE_NOT_FOUND:
return "source file does not exist"
ERR_OUTPUT_FOLDER_NOT_FOUND:
return "output location does not exist"
ERR_ASEPRITE_EXPORT_FAILED:
return "unable to import file"
ERR_INVALID_ASEPRITE_SPRITESHEET:
return "aseprite generated bad data file"
ERR_NO_VALID_LAYERS_FOUND:
return "no valid layers found"
_:
return "import failed with code %d" % code
static func error(error_code: int):
return { "code": error_code, "content": null, "is_ok": false }
static func result(result):
return { "code": SUCCESS, "content": result, "is_ok": true }

View File

@@ -0,0 +1,82 @@
@tool
extends RefCounted
const WIZARD_CONFIG_META_NAME = "_aseprite_wizard_config_"
const WIZARD_CONFIG_MARKER = "aseprite_wizard_config"
const WIZARD_INTERFACE_CONFIG_META_NAME = "_aseprite_wizard_interface_config_"
const SEPARATOR = "|="
static func encode(object: Dictionary):
var text = "%s\n" % WIZARD_CONFIG_MARKER
for prop in object:
text += "%s%s%s\n" % [prop, SEPARATOR, object[prop]]
return Marshalls.utf8_to_base64(text)
static func decode(string: String):
var decoded = _decode_base64(string)
if not _is_wizard_config(decoded):
return null
var cfg = decoded.split("\n")
var config = {}
for c in cfg:
var parts = c.split(SEPARATOR, 1)
if parts.size() == 2:
var key = parts[0].strip_edges()
var value = parts[1].strip_edges()
#Convert bool properties
if key == "only_visible" or key == "op_exp":
match value:
"True":
config[key] = true
"False":
config[key] = false
_:
config[key] = false
else:
config[key] = value
return config
static func _decode_base64(string: String):
if string != "":
return Marshalls.base64_to_utf8(string)
return null
static func _is_wizard_config(cfg) -> bool:
return cfg != null and cfg.begins_with(WIZARD_CONFIG_MARKER)
static func load_config(node:Node):
if node.has_meta(WIZARD_CONFIG_META_NAME):
return node.get_meta(WIZARD_CONFIG_META_NAME)
return decode(node.editor_description)
static func save_config(node:Node, use_metadata:bool, cfg:Dictionary):
if use_metadata:
node.set_meta(WIZARD_CONFIG_META_NAME, cfg)
#Delete config from editor_description
var decoded = _decode_base64(node.editor_description)
if _is_wizard_config(decoded):
node.editor_description = ""
else:
node.editor_description = encode(cfg)
static func load_interface_config(node: Node, default: Dictionary = {}) -> Dictionary:
if node.has_meta(WIZARD_INTERFACE_CONFIG_META_NAME):
return node.get_meta(WIZARD_INTERFACE_CONFIG_META_NAME)
return default
static func save_interface_config(node:Node, cfg:Dictionary) -> void:
node.set_meta(WIZARD_INTERFACE_CONFIG_META_NAME, cfg)