init
This commit is contained in:
commit
f389e4e807
186 changed files with 10853 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
uid://x4p5dv0r0oye
|
||||
70
addons/AsepriteWizard/importers/helpers/bakery.gd
Normal file
70
addons/AsepriteWizard/importers/helpers/bakery.gd
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
@tool
|
||||
extends RefCounted
|
||||
|
||||
const logger = preload("../../config/logger.gd")
|
||||
|
||||
func save_bake_file(source_path: String, resource: Resource) -> int:
|
||||
var bake_path = _bake_path(source_path)
|
||||
var hash = FileAccess.get_md5(source_path)
|
||||
|
||||
resource.set_meta('source_hash', hash)
|
||||
|
||||
var result = ResourceSaver.save(resource, bake_path)
|
||||
ResourceLoader.load(bake_path, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func has_bake_file(source_path: String) -> bool:
|
||||
var bake_path = _bake_path(source_path)
|
||||
return ResourceLoader.exists(bake_path)
|
||||
|
||||
|
||||
func load_bake_file(source_path: String, target_path: String) -> int:
|
||||
var source_hash = FileAccess.get_md5(source_path)
|
||||
var bake_path = _bake_path(source_path)
|
||||
var bake = ResourceLoader.load(bake_path, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
if bake.get_meta('source_hash') != source_hash:
|
||||
logger.warn("baked file hash does not match current source file", source_path)
|
||||
|
||||
var result = ResourceSaver.save(bake, target_path)
|
||||
|
||||
ResourceLoader.load(target_path, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func load_bake_texture(source_path: String, target_path: String) -> int:
|
||||
var source_hash = FileAccess.get_md5(source_path)
|
||||
var bake_path = _bake_path(source_path)
|
||||
var bake: PortableCompressedTexture2D = ResourceLoader.load(bake_path, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
if bake.get_meta('source_hash') != source_hash:
|
||||
logger.warn("baked file hash does not match current source file", source_path)
|
||||
|
||||
|
||||
var tex := PortableCompressedTexture2D.new()
|
||||
tex.create_from_image(bake.get_image(), PortableCompressedTexture2D.COMPRESSION_MODE_LOSSLESS)
|
||||
|
||||
var result = ResourceSaver.save(tex, target_path)
|
||||
ResourceLoader.load(target_path, "PortableCompressedTexture2D", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func delete_bake_file(source_path: String) -> int:
|
||||
return DirAccess.remove_absolute(_bake_path(source_path))
|
||||
|
||||
|
||||
func move_bake_file(old_path: String, new_path: String) -> int:
|
||||
var old_bake_path = _bake_path(old_path)
|
||||
var new_bake_path = _bake_path(new_path)
|
||||
|
||||
return DirAccess.rename_absolute(old_bake_path, new_bake_path)
|
||||
|
||||
|
||||
func _bake_path(source_path: String) -> String:
|
||||
var file = source_path.get_file()
|
||||
var dir = source_path.get_base_dir()
|
||||
return dir.path_join(".%s.ase_bake.res" % file)
|
||||
1
addons/AsepriteWizard/importers/helpers/bakery.gd.uid
Normal file
1
addons/AsepriteWizard/importers/helpers/bakery.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://crehekgicyf6e
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
@tool
|
||||
extends Node
|
||||
|
||||
const WAIT_TIME_IN_SECONDS := 0.8
|
||||
var _time_left := 0.0
|
||||
var _scheduled := false
|
||||
|
||||
## Schedule a file system scan. This method works like a debouncer
|
||||
## postponing the scan until no more calls are being made
|
||||
func schedule_file_system_scan() -> void:
|
||||
_time_left = WAIT_TIME_IN_SECONDS
|
||||
_scheduled = true
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _scheduled:
|
||||
if _time_left > 0.0:
|
||||
_time_left -= delta
|
||||
else:
|
||||
_scheduled = false
|
||||
if not EditorInterface.get_resource_filesystem().is_scanning():
|
||||
EditorInterface.get_resource_filesystem().scan.call_deferred()
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://gc2xkqnjlarn
|
||||
158
addons/AsepriteWizard/importers/multiple_import_plugin_base.gd
Normal file
158
addons/AsepriteWizard/importers/multiple_import_plugin_base.gd
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
const result_codes = preload("../config/result_codes.gd")
|
||||
const logger = preload("../config/logger.gd")
|
||||
|
||||
var config = preload("../config/config.gd").new()
|
||||
var _aseprite = preload("../aseprite/aseprite.gd").new()
|
||||
var _bakery = preload("./helpers/bakery.gd").new()
|
||||
|
||||
var file_system_helper
|
||||
|
||||
func _init(fs_helper) -> void:
|
||||
file_system_helper = fs_helper
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["aseprite", "ase"]
|
||||
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "PackedDataContainer"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var old_data = _load_old_data(source_file)
|
||||
|
||||
if not _aseprite.test_command():
|
||||
if config.should_generate_bake_files() && _bakery.has_bake_file(source_file):
|
||||
logger.warn("Aseprite command failed. Falling back to baked file. No changes will be made to children resources", source_file)
|
||||
return _bakery.load_bake_file(source_file, "%s.%s" % [save_path, _get_save_extension()])
|
||||
else:
|
||||
return ERR_UNCONFIGURED
|
||||
|
||||
var exception_pattern = options.get('layer/exclude_layers_pattern', "")
|
||||
var should_include_only_visibles = options.get('layer/only_visible_layers', false)
|
||||
var should_merge_duplicates = options.get('layer/merge_duplicate_layers', false)
|
||||
|
||||
var absolute_source_file = ProjectSettings.globalize_path(source_file)
|
||||
|
||||
var layers = _aseprite.list_valid_layers(
|
||||
absolute_source_file,
|
||||
exception_pattern,
|
||||
should_include_only_visibles,
|
||||
should_merge_duplicates,
|
||||
true
|
||||
)
|
||||
|
||||
var layers_resources_folder = options["output/layers_resources_folder"]
|
||||
|
||||
if layers_resources_folder.is_relative_path():
|
||||
var source_base_dir = source_file.get_base_dir()
|
||||
layers_resources_folder = source_base_dir.path_join(layers_resources_folder).simplify_path()
|
||||
|
||||
var import_options = _get_base_import_options(options)
|
||||
import_options["source"] = source_file
|
||||
|
||||
var base_name = source_file.get_basename()
|
||||
|
||||
if layers_resources_folder != "":
|
||||
if not DirAccess.dir_exists_absolute(layers_resources_folder):
|
||||
DirAccess.make_dir_recursive_absolute(layers_resources_folder)
|
||||
base_name = "%s/%s" % [layers_resources_folder, base_name.get_file()]
|
||||
|
||||
var data_to_save = {
|
||||
"layers": {}
|
||||
}
|
||||
|
||||
for layer in layers:
|
||||
var flat_layer_name = (layer as String).replace("/", "_")
|
||||
var layer_save_path = "%s_%s.%s" % [base_name, flat_layer_name, _layer_extension()]
|
||||
var file = FileAccess.open(layer_save_path, FileAccess.WRITE)
|
||||
var source_hash = FileAccess.get_md5(absolute_source_file)
|
||||
file.store_string(JSON.stringify({
|
||||
"layer": layer,
|
||||
"import_options": import_options,
|
||||
"source_hash": source_hash
|
||||
}))
|
||||
data_to_save.layers[layer] = layer_save_path
|
||||
|
||||
var packed = PackedDataContainer.new()
|
||||
packed.pack(data_to_save)
|
||||
|
||||
var exit_code = ResourceSaver.save(packed, "%s.%s" % [save_path, _get_save_extension()])
|
||||
|
||||
if config.should_generate_bake_files():
|
||||
var bake_code = _bakery.save_bake_file(source_file, packed)
|
||||
if bake_code != OK:
|
||||
logger.error('Bake file creation failed (%s) ' % bake_code, source_file)
|
||||
|
||||
_cleanup_old_layers(old_data, layers)
|
||||
|
||||
file_system_helper.schedule_file_system_scan()
|
||||
|
||||
return exit_code
|
||||
|
||||
|
||||
func _layer_extension() -> String:
|
||||
return ""
|
||||
|
||||
func _get_base_import_options(options: Dictionary):
|
||||
return {}
|
||||
|
||||
|
||||
func _load_old_data(source_file: String):
|
||||
var old_data = {}
|
||||
|
||||
if ResourceLoader.exists(source_file):
|
||||
var d = ResourceLoader.load(source_file)
|
||||
# handling JSON to keep it backwards compatible
|
||||
# remove it in the next major version
|
||||
if d is JSON:
|
||||
old_data = d.data.layers
|
||||
elif d is PackedDataContainer:
|
||||
if d["layers"] != null:
|
||||
old_data = _packed_container_to_dictionary(d["layers"])
|
||||
|
||||
return old_data
|
||||
|
||||
|
||||
func _packed_container_to_dictionary(packed):
|
||||
var dic = {}
|
||||
for k in packed:
|
||||
if packed[k] is PackedDataContainerRef:
|
||||
dic[k] = _packed_container_to_dictionary(packed[k])
|
||||
else:
|
||||
dic[k] = packed[k]
|
||||
return dic
|
||||
|
||||
|
||||
func _cleanup_old_layers(old_data: Dictionary, layers: Array):
|
||||
var old_layers = old_data.keys()
|
||||
|
||||
for old_layer in old_layers:
|
||||
if not layers.has(old_layer):
|
||||
var file = old_data[old_layer]
|
||||
if FileAccess.file_exists(file):
|
||||
DirAccess.remove_absolute(file)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://7corquvc7sgw
|
||||
57
addons/AsepriteWizard/importers/noop_import_plugin.gd
Normal file
57
addons/AsepriteWizard/importers/noop_import_plugin.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
##
|
||||
## No-op importer to allow files to be seen and
|
||||
## managed, but without triggering a real import
|
||||
##
|
||||
|
||||
var config = preload("../config/config.gd").new()
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.noop"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite (No Import)"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["aseprite", "ase"]
|
||||
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "PackedDataContainer"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 2.0 if config.get_default_importer() == config.IMPORTER_NOOP_NAME else 1.0
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return []
|
||||
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var container = PackedDataContainer.new()
|
||||
return ResourceSaver.save(container, "%s.%s" % [save_path, _get_save_extension()])
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dx4cql03pnqwk
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
const result_codes = preload("../../config/result_codes.gd")
|
||||
const logger = preload("../../config/logger.gd")
|
||||
|
||||
var config = preload("../../config/config.gd").new()
|
||||
var _aseprite = preload("../../aseprite/aseprite.gd").new()
|
||||
var _sf_creator = preload("../../creators/sprite_frames/sprite_frames_creator.gd").new()
|
||||
var _bakery = preload("../helpers/bakery.gd").new()
|
||||
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.spriteframes-split-layer"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite Layer SpriteFrames"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["ase_layer"]
|
||||
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "SpriteFrames"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 1.0
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return []
|
||||
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var resource_path = "%s.res" % save_path
|
||||
var is_baking_enabled = config.should_generate_bake_files()
|
||||
|
||||
if not _aseprite.test_command():
|
||||
if is_baking_enabled && _bakery.has_bake_file(source_file):
|
||||
logger.warn("Aseprite command failed. Falling back to baked file...")
|
||||
return _bakery.load_bake_file(source_file, resource_path)
|
||||
else:
|
||||
return ERR_UNCONFIGURED
|
||||
|
||||
var file = FileAccess.open(source_file, FileAccess.READ)
|
||||
var data = JSON.parse_string(file.get_as_text())
|
||||
|
||||
var source_path = source_file.get_base_dir()
|
||||
|
||||
var absolute_source_file = ProjectSettings.globalize_path(data.import_options.source)
|
||||
|
||||
var export_options = {
|
||||
"sheet_type": data.import_options.sheet_type,
|
||||
"frame_padding": data.import_options.frame_padding,
|
||||
"sheet_columns": data.import_options.sheet_columns,
|
||||
"should_round_fps": data.import_options.should_round_fps,
|
||||
"scale": data.import_options.get("scale"),
|
||||
}
|
||||
|
||||
var source_files = _aseprite.export_file_with_layers(
|
||||
absolute_source_file,
|
||||
[data.layer],
|
||||
source_path,
|
||||
export_options,
|
||||
)
|
||||
|
||||
if source_files.is_empty():
|
||||
logger.error("Could not import aseprite file. Layer not found.", source_file)
|
||||
return FAILED
|
||||
#
|
||||
var resources = _sf_creator.create_resources([source_files], {
|
||||
"should_round_fps": data.import_options.should_round_fps,
|
||||
"should_create_portable_texture": true,
|
||||
})
|
||||
|
||||
if not resources.is_ok:
|
||||
logger.error("Could not import aseprite file: %s" % result_codes.get_error_message(resources.code), source_file)
|
||||
return FAILED
|
||||
|
||||
var resource = resources.content[0]
|
||||
resource.resource.set_meta("imported_via_aw", true)
|
||||
|
||||
var exit_code = ResourceSaver.save(resource.resource, resource_path)
|
||||
resource.resource.take_over_path(resource_path)
|
||||
ResourceLoader.load(resource_path, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
if is_baking_enabled:
|
||||
var bake_code = _bakery.save_bake_file(source_file, resource.resource)
|
||||
if bake_code != OK:
|
||||
logger.error('Bake file creation failed (%s) ' % bake_code, source_file)
|
||||
|
||||
for extra_file in resource.extra_gen_files:
|
||||
gen_files.push_back(extra_file)
|
||||
#
|
||||
if config.should_remove_source_files():
|
||||
_remove_source_files(source_files)
|
||||
|
||||
if exit_code != OK:
|
||||
logger.error("Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code), source_file)
|
||||
return FAILED
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func _remove_source_files(source_files: Dictionary):
|
||||
DirAccess.remove_absolute(source_files.data_file)
|
||||
DirAccess.remove_absolute(source_files.sprite_sheet)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://djd4ehetolxqy
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
@tool
|
||||
extends "../static_texture_import_plugin_base.gd"
|
||||
|
||||
##
|
||||
## Static texture importer (Split).
|
||||
## Imports Aseprite layer as texture (either first frame or full spritesheet)
|
||||
##
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.static-texture-split-layer"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite Layer Texture"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["ase_layer_tex"]
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 1.0
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return []
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var bake_result = _handle_bake_fallback(source_file, save_path)
|
||||
|
||||
if bake_result != CONTINUE_STATUS_CODE:
|
||||
return bake_result
|
||||
|
||||
var file = FileAccess.open(source_file, FileAccess.READ)
|
||||
var i_data = JSON.parse_string(file.get_as_text())
|
||||
|
||||
var source_path = source_file.get_base_dir()
|
||||
var absolute_source_file = ProjectSettings.globalize_path(i_data.import_options.source)
|
||||
|
||||
var aseprite_opts = {
|
||||
"layer": i_data.layer,
|
||||
"output_filename": '',
|
||||
"output_folder": source_path,
|
||||
"first_frame_only": i_data.import_options.get("first_frame_only", false),
|
||||
"frame_padding": i_data.import_options.get("frame_padding", 0),
|
||||
"trim_cels": i_data.import_options.get("trim_cels", false),
|
||||
"scale": i_data.import_options.get("scale"),
|
||||
}
|
||||
|
||||
if not aseprite_opts.first_frame_only:
|
||||
aseprite_opts['sheet_type'] = i_data.import_options.get("sheet_type")
|
||||
aseprite_opts['sheet_columns'] = i_data.import_options.get("sheet_columns")
|
||||
|
||||
|
||||
var result = _generate_texture(absolute_source_file, aseprite_opts)
|
||||
|
||||
if not result.is_ok:
|
||||
logger.error("Could not import aseprite file: %s" % result_codes.get_error_message(result.code), source_file)
|
||||
return FAILED
|
||||
|
||||
var sprite_sheet = result.content.sprite_sheet
|
||||
var data = result.content.data
|
||||
|
||||
return _save_resource(source_file, sprite_sheet, save_path, result.content.data_file, data.meta.size)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dg4et7ryc5xjm
|
||||
149
addons/AsepriteWizard/importers/sprite_frames_import_plugin.gd
Normal file
149
addons/AsepriteWizard/importers/sprite_frames_import_plugin.gd
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
const result_codes = preload("../config/result_codes.gd")
|
||||
const logger = preload("../config/logger.gd")
|
||||
|
||||
var config = preload("../config/config.gd").new()
|
||||
var _aseprite_file_exporter = preload("../aseprite/file_exporter.gd").new()
|
||||
var _sf_creator = preload("../creators/sprite_frames/sprite_frames_creator.gd").new()
|
||||
var _bakery = preload("./helpers/bakery.gd").new()
|
||||
var file_system: EditorFileSystem = EditorInterface.get_resource_filesystem()
|
||||
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.spriteframes"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite SpriteFrames"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["aseprite", "ase"]
|
||||
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "SpriteFrames"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 2.0 if config.get_default_importer() == config.IMPORTER_SPRITEFRAMES_NAME else 1.0
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return [
|
||||
{"name": "layer/exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
|
||||
{"name": "layer/only_visible_layers", "default_value": false},
|
||||
{
|
||||
"name": "sheet/sheet_type",
|
||||
"default_value": "packed",
|
||||
"property_hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "columns,horizontal,vertical,packed",
|
||||
},
|
||||
{
|
||||
"name": "sheet/sheet_columns",
|
||||
"default_value": 12,
|
||||
},
|
||||
{
|
||||
"name": "sheet/frame_padding",
|
||||
"default_value": 0,
|
||||
},
|
||||
{
|
||||
"name": "sheet/scale",
|
||||
"default_value": 1,
|
||||
},
|
||||
{"name": "animation/round_fps", "default_value": true},
|
||||
]
|
||||
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var resource_path = "%s.res" % save_path
|
||||
var is_baking_enabled = config.should_generate_bake_files()
|
||||
|
||||
if not _aseprite_file_exporter.is_aseprite_command_working():
|
||||
if is_baking_enabled && _bakery.has_bake_file(source_file):
|
||||
logger.warn("Aseprite command failed. Falling back to baked file...", source_file)
|
||||
return _bakery.load_bake_file(source_file, resource_path)
|
||||
else:
|
||||
return ERR_UNCONFIGURED
|
||||
|
||||
var absolute_source_file = ProjectSettings.globalize_path(source_file)
|
||||
var absolute_save_path = ProjectSettings.globalize_path(save_path)
|
||||
|
||||
var source_path = source_file.get_base_dir()
|
||||
var source_basename = source_file.substr(source_path.length()+1, -1)
|
||||
source_basename = source_basename.substr(0, source_basename.rfind('.'))
|
||||
|
||||
var aseprite_opts = {
|
||||
"export_mode": _sf_creator.FILE_EXPORT_MODE,
|
||||
"exception_pattern": options['layer/exclude_layers_pattern'],
|
||||
"only_visible_layers": options['layer/only_visible_layers'],
|
||||
"output_filename": '',
|
||||
"output_folder": source_path,
|
||||
"sheet_type": options["sheet/sheet_type"],
|
||||
"frame_padding": options["sheet/frame_padding"],
|
||||
"sheet_columns": options["sheet/sheet_columns"],
|
||||
"scale": str(options["sheet/scale"]),
|
||||
}
|
||||
|
||||
var source_files = _aseprite_file_exporter.generate_aseprite_files(absolute_source_file, aseprite_opts)
|
||||
if not source_files.is_ok:
|
||||
logger.error("Could not import aseprite file: %s" % result_codes.get_error_message(source_files.code), source_file)
|
||||
return FAILED
|
||||
|
||||
var resources = _sf_creator.create_resources(source_files.content, {
|
||||
"should_round_fps": options["animation/round_fps"],
|
||||
"should_create_portable_texture": true,
|
||||
})
|
||||
|
||||
if not resources.is_ok:
|
||||
logger.error("Could not import aseprite file: %s" % result_codes.get_error_message(resources.code), source_file)
|
||||
return FAILED
|
||||
|
||||
var resource: Dictionary = resources.content[0]
|
||||
resource.resource.set_meta("imported_via_aw", true)
|
||||
var exit_code = ResourceSaver.save(resource.resource, resource_path)
|
||||
resource.resource.take_over_path(resource_path)
|
||||
ResourceLoader.load(resource_path, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
if is_baking_enabled:
|
||||
var bake_code = _bakery.save_bake_file(source_file, resource.resource)
|
||||
if bake_code != OK:
|
||||
logger.error('Bake file creation failed (%s)' % bake_code, source_file)
|
||||
|
||||
|
||||
if config.should_remove_source_files():
|
||||
_remove_source_files(source_files.content)
|
||||
|
||||
if exit_code != OK:
|
||||
logger.error("Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code), source_file)
|
||||
return FAILED
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func _remove_source_files(source_files: Array):
|
||||
for s in source_files:
|
||||
DirAccess.remove_absolute(s.data_file)
|
||||
DirAccess.remove_absolute(s.sprite_sheet)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dkkkxfq3dip6n
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
@tool
|
||||
extends "./multiple_import_plugin_base.gd"
|
||||
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.spriteframes-split"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite SpriteFrames (Split By Layer)"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 2.0 if config.get_default_importer() == config.IMPORTER_SPRITEFRAMES_SPLIT_NAME else 1.0
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return [
|
||||
{"name": "layer/exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
|
||||
{"name": "layer/only_visible_layers", "default_value": false},
|
||||
{
|
||||
"name": "sheet/sheet_type",
|
||||
"default_value": "packed",
|
||||
"property_hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "columns,horizontal,vertical,packed",
|
||||
},
|
||||
{
|
||||
"name": "sheet/sheet_columns",
|
||||
"default_value": 12,
|
||||
},
|
||||
{
|
||||
"name": "sheet/frame_padding",
|
||||
"default_value": 0,
|
||||
},
|
||||
{
|
||||
"name": "sheet/scale",
|
||||
"default_value": 1,
|
||||
},
|
||||
{"name": "animation/round_fps", "default_value": true},
|
||||
{
|
||||
"name": "output/layers_resources_folder",
|
||||
"default_value": "",
|
||||
"property_hint": PROPERTY_HINT_DIR,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
func _layer_extension() -> String:
|
||||
return "ase_layer"
|
||||
|
||||
|
||||
func _get_base_import_options(options: Dictionary):
|
||||
return {
|
||||
"sheet_type": options["sheet/sheet_type"],
|
||||
"frame_padding": options["sheet/frame_padding"],
|
||||
"sheet_columns": options["sheet/sheet_columns"],
|
||||
"should_round_fps": options["animation/round_fps"],
|
||||
"scale": str(options["sheet/scale"]),
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bcweshclibjyf
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
@tool
|
||||
extends "./static_texture_import_plugin_base.gd"
|
||||
|
||||
|
||||
##
|
||||
## Static texture importer.
|
||||
## Imports first frame from Aseprite file as texture
|
||||
##
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.static-texture"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite Texture"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["aseprite", "ase"]
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 2.0 if config.get_default_importer() == config.IMPORTER_STATIC_TEXTURE_NAME else 0.8
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return [
|
||||
{"name": "layer/exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
|
||||
{"name": "layer/only_visible_layers", "default_value": false},
|
||||
{"name": "layer/split_layers", "default_value": false},
|
||||
{"name": "first_frame_only", "default_value": true},
|
||||
{
|
||||
"name": "sheet/sheet_type",
|
||||
"default_value": "packed",
|
||||
"property_hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "columns,horizontal,vertical,packed",
|
||||
},
|
||||
{
|
||||
"name": "sheet/sheet_columns",
|
||||
"default_value": 12,
|
||||
},
|
||||
{
|
||||
"name": "sheet/scale",
|
||||
"default_value": 1,
|
||||
},
|
||||
]
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var bake_result = _handle_bake_fallback(source_file, save_path)
|
||||
|
||||
if bake_result != CONTINUE_STATUS_CODE:
|
||||
return bake_result
|
||||
|
||||
var absolute_source_file = ProjectSettings.globalize_path(source_file)
|
||||
var source_path = source_file.get_base_dir()
|
||||
|
||||
var aseprite_opts = {
|
||||
"exception_pattern": options['layer/exclude_layers_pattern'],
|
||||
"only_visible_layers": options['layer/only_visible_layers'],
|
||||
"split_layers": options.get('layer/split_layers', false),
|
||||
"output_filename": '',
|
||||
"output_folder": source_path,
|
||||
"scale": str(options["sheet/scale"]),
|
||||
}
|
||||
|
||||
if options['first_frame_only']:
|
||||
aseprite_opts['first_frame_only'] = options['first_frame_only']
|
||||
else:
|
||||
aseprite_opts['sheet_type'] = options["sheet/sheet_type"]
|
||||
aseprite_opts['sheet_columns'] = options["sheet/sheet_columns"]
|
||||
|
||||
var result = _generate_texture(absolute_source_file, aseprite_opts)
|
||||
|
||||
if not result.is_ok:
|
||||
logger.error("Could not import aseprite file: %s" % result_codes.get_error_message(result.code), source_file)
|
||||
return FAILED
|
||||
|
||||
var sprite_sheet = result.content.sprite_sheet
|
||||
var data = result.content.data
|
||||
|
||||
return _save_resource(source_file, sprite_sheet, save_path, result.content.data_file, data.meta.size)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dkyusrclhl8ue
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
const result_codes = preload("../config/result_codes.gd")
|
||||
const logger = preload("../config/logger.gd")
|
||||
var _aseprite_file_exporter = preload("../aseprite/file_exporter.gd").new()
|
||||
var _bakery = preload("./helpers/bakery.gd").new()
|
||||
|
||||
var config = preload("../config/config.gd").new()
|
||||
|
||||
const CONTINUE_STATUS_CODE = 91919
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "PortableCompressedTexture2D"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
func _generate_texture(absolute_source_file: String, options: Dictionary) -> Dictionary:
|
||||
var result = _aseprite_file_exporter.generate_aseprite_file(absolute_source_file, options)
|
||||
|
||||
if not result.is_ok:
|
||||
return result
|
||||
|
||||
var sprite_sheet = result.content.sprite_sheet
|
||||
var data_result = _aseprite_file_exporter.load_json_content(result.content.data_file)
|
||||
|
||||
if not data_result.is_ok:
|
||||
return data_result
|
||||
|
||||
var data = data_result.content
|
||||
|
||||
return result_codes.result({
|
||||
"data_file": result.content.data_file,
|
||||
"sprite_sheet": sprite_sheet,
|
||||
"data": data
|
||||
})
|
||||
|
||||
|
||||
func _save_resource(source_file: String, sprite_sheet: String, save_path: String, data_file_path: String, size: Dictionary) -> int:
|
||||
var image = Image.load_from_file(ProjectSettings.globalize_path(sprite_sheet))
|
||||
|
||||
var tex := PortableCompressedTexture2D.new()
|
||||
tex.create_from_image(image, PortableCompressedTexture2D.COMPRESSION_MODE_LOSSLESS)
|
||||
#
|
||||
var exit_code = ResourceSaver.save(tex, "%s.%s" % [save_path, _get_save_extension()])
|
||||
|
||||
if config.should_remove_source_files():
|
||||
DirAccess.remove_absolute(data_file_path)
|
||||
DirAccess.remove_absolute(sprite_sheet)
|
||||
|
||||
if exit_code != OK:
|
||||
logger.error("Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code), source_file)
|
||||
return FAILED
|
||||
|
||||
if config.should_generate_bake_files():
|
||||
var bake_code = _bakery.save_bake_file(source_file, tex)
|
||||
if bake_code != OK:
|
||||
logger.error('Bake file creation failed (%s)' % bake_code, source_file)
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func _handle_bake_fallback(source_file: String, save_path: String) -> int:
|
||||
if _aseprite_file_exporter.is_aseprite_command_working():
|
||||
return CONTINUE_STATUS_CODE
|
||||
|
||||
if config.should_generate_bake_files() && _bakery.has_bake_file(source_file):
|
||||
logger.warn("Aseprite command failed. Falling back to baked file", source_file)
|
||||
var resource_path = "%s.%s" % [save_path, _get_save_extension()]
|
||||
return _bakery.load_bake_texture(source_file, resource_path)
|
||||
else:
|
||||
return ERR_UNCONFIGURED
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cwl3kwrv1vqot
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
@tool
|
||||
extends "./multiple_import_plugin_base.gd"
|
||||
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.static-texture-split"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite Texture (Split By Layer)"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 2.0 if config.get_default_importer() == config.IMPORTER_STATIC_TEXTURE_SPLIT_NAME else 1.0
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return [
|
||||
{"name": "first_frame_only", "default_value": true},
|
||||
{"name": "layer/exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
|
||||
{"name": "layer/only_visible_layers", "default_value": false},
|
||||
{"name": "layer/merge_duplicate_layers", "default_value": false},
|
||||
{"name": "sheet/trim_cels", "default_value": false},
|
||||
{
|
||||
"name": "sheet/sheet_type",
|
||||
"default_value": "packed",
|
||||
"property_hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "columns,horizontal,vertical,packed",
|
||||
},
|
||||
{
|
||||
"name": "sheet/sheet_columns",
|
||||
"default_value": 12,
|
||||
},
|
||||
{
|
||||
"name": "sheet/frame_padding",
|
||||
"default_value": 0,
|
||||
},
|
||||
{"name": "sheet/scale", "default_value": 1 },
|
||||
{
|
||||
"name": "output/layers_resources_folder",
|
||||
"default_value": "",
|
||||
"property_hint": PROPERTY_HINT_DIR,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
func _layer_extension() -> String:
|
||||
return "ase_layer_tex"
|
||||
|
||||
|
||||
func _get_base_import_options(options: Dictionary):
|
||||
return {
|
||||
"trim_cels": options["sheet/trim_cels"],
|
||||
"first_frame_only": options["first_frame_only"],
|
||||
"sheet_type": options["sheet/sheet_type"],
|
||||
"sheet_columns": options["sheet/sheet_columns"],
|
||||
"frame_padding": options["sheet/frame_padding"],
|
||||
"scale": str(options["sheet/scale"]),
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b6j11j841gc32
|
||||
173
addons/AsepriteWizard/importers/tileset_texture_import_plugin.gd
Normal file
173
addons/AsepriteWizard/importers/tileset_texture_import_plugin.gd
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
##
|
||||
## Tileset texture importer.
|
||||
## Imports Aseprite tileset layers as an AtlasTexture
|
||||
##
|
||||
|
||||
const CONTINUE_STATUS_CODE = 91919
|
||||
|
||||
const result_codes = preload("../config/result_codes.gd")
|
||||
const logger = preload("../config/logger.gd")
|
||||
var _bakery = preload("./helpers/bakery.gd").new()
|
||||
var _aseprite_file_exporter = preload("../aseprite/file_exporter.gd").new()
|
||||
|
||||
var config = preload("../config/config.gd").new()
|
||||
var file_system: EditorFileSystem = EditorInterface.get_resource_filesystem()
|
||||
|
||||
|
||||
func _get_importer_name():
|
||||
return "aseprite_wizard.plugin.tileset-texture"
|
||||
|
||||
|
||||
func _get_visible_name():
|
||||
return "Aseprite Tileset Texture"
|
||||
|
||||
|
||||
func _get_recognized_extensions():
|
||||
return ["aseprite", "ase"]
|
||||
|
||||
|
||||
func _get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type():
|
||||
return "PortableCompressedTexture2D"
|
||||
|
||||
|
||||
func _get_preset_count():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_preset_name(i):
|
||||
return "Default"
|
||||
|
||||
|
||||
func _get_priority():
|
||||
return 2.0 if config.get_default_importer() == config.IMPORTER_TILESET_TEXTURE_NAME else 0.9
|
||||
|
||||
|
||||
func _get_import_order():
|
||||
return 1
|
||||
|
||||
|
||||
func _get_import_options(_path, _i):
|
||||
return [
|
||||
{"name": "layer/exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
|
||||
{"name": "layer/only_visible_layers", "default_value": false},
|
||||
{
|
||||
"name": "sheet/sheet_type",
|
||||
"default_value": "columns",
|
||||
"property_hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "columns,horizontal,vertical,packed",
|
||||
},
|
||||
{
|
||||
"name": "sheet/sheet_columns",
|
||||
"default_value": 12,
|
||||
},
|
||||
{
|
||||
"name": "sheet/frame_padding",
|
||||
"default_value": 0,
|
||||
},
|
||||
]
|
||||
|
||||
func _get_option_visibility(path, option, options):
|
||||
return true
|
||||
|
||||
|
||||
func _import(source_file, save_path, options, platform_variants, gen_files):
|
||||
var bake_result = _handle_bake_fallback(source_file, save_path)
|
||||
|
||||
if bake_result != CONTINUE_STATUS_CODE:
|
||||
return bake_result
|
||||
|
||||
var absolute_source_file = ProjectSettings.globalize_path(source_file)
|
||||
var absolute_save_path = ProjectSettings.globalize_path(save_path)
|
||||
var source_path = source_file.get_base_dir()
|
||||
var source_basename = source_file.substr(source_path.length()+1, -1)
|
||||
source_basename = source_basename.substr(0, source_basename.rfind('.'))
|
||||
|
||||
var aseprite_opts = {
|
||||
"exception_pattern": options['layer/exclude_layers_pattern'],
|
||||
"only_visible_layers": options['layer/only_visible_layers'],
|
||||
"output_filename": '',
|
||||
"output_folder": source_path,
|
||||
"sheet_type": options["sheet/sheet_type"],
|
||||
"frame_padding": options["sheet/frame_padding"],
|
||||
"sheet_columns": options["sheet/sheet_columns"],
|
||||
}
|
||||
|
||||
var result = _generate_texture(absolute_source_file, aseprite_opts)
|
||||
|
||||
if not result.is_ok:
|
||||
var extra_error_info = ""
|
||||
if result.code == result_codes.ERR_INVALID_ASEPRITE_SPRITESHEET:
|
||||
extra_error_info = " Make sure your Aseprite file contains at least one Tilemap layer."
|
||||
|
||||
logger.error("Could not import aseprite file: %s.%s" % [result_codes.get_error_message(result.code), extra_error_info], source_file)
|
||||
return FAILED
|
||||
|
||||
var sprite_sheet = result.content.sprite_sheet
|
||||
var data = result.content.data
|
||||
|
||||
return _save_resource(source_file, sprite_sheet, save_path, result.content.data_file, data.meta.size)
|
||||
|
||||
|
||||
func _generate_texture(absolute_source_file: String, options: Dictionary) -> Dictionary:
|
||||
var result = _aseprite_file_exporter.generate_tileset_files(absolute_source_file, options)
|
||||
|
||||
if not result.is_ok:
|
||||
return result
|
||||
|
||||
var sprite_sheet = result.content.sprite_sheet
|
||||
|
||||
var data_result = _aseprite_file_exporter.load_json_content(result.content.data_file)
|
||||
|
||||
if not data_result.is_ok:
|
||||
return data_result
|
||||
|
||||
var data = data_result.content
|
||||
|
||||
return result_codes.result({
|
||||
"data_file": result.content.data_file,
|
||||
"sprite_sheet": sprite_sheet,
|
||||
"data": data
|
||||
})
|
||||
|
||||
|
||||
func _save_resource(source_file: String, sprite_sheet: String, save_path: String, data_file_path: String, size: Dictionary) -> int:
|
||||
var image = Image.load_from_file(ProjectSettings.globalize_path(sprite_sheet))
|
||||
|
||||
var tex := PortableCompressedTexture2D.new()
|
||||
tex.create_from_image(image, PortableCompressedTexture2D.COMPRESSION_MODE_LOSSLESS)
|
||||
|
||||
var exit_code = ResourceSaver.save(tex, "%s.%s" % [save_path, _get_save_extension()])
|
||||
|
||||
if config.should_remove_source_files():
|
||||
DirAccess.remove_absolute(data_file_path)
|
||||
DirAccess.remove_absolute(sprite_sheet)
|
||||
|
||||
if exit_code != OK:
|
||||
logger.error("Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code), source_file)
|
||||
return FAILED
|
||||
|
||||
if config.should_generate_bake_files():
|
||||
var bake_code = _bakery.save_bake_file(source_file, tex)
|
||||
if bake_code != OK:
|
||||
logger.error('Bake file creation failed (%s)' % bake_code, source_file)
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func _handle_bake_fallback(source_file: String, save_path: String) -> int:
|
||||
if _aseprite_file_exporter.is_aseprite_command_working():
|
||||
return CONTINUE_STATUS_CODE
|
||||
|
||||
if config.should_generate_bake_files() && _bakery.has_bake_file(source_file):
|
||||
logger.warn("Aseprite command failed. Falling back to baked file", source_file)
|
||||
var resource_path = "%s.%s" % [save_path, _get_save_extension()]
|
||||
return _bakery.load_bake_texture(source_file, resource_path)
|
||||
else:
|
||||
return ERR_UNCONFIGURED
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://batw4yc3q03hk
|
||||
Loading…
Add table
Add a link
Reference in a new issue