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,58 @@
@tool
extends EditorImportPlugin
##
## No-op importer to allow files to be seen and
## managed, but without triggering a real import
##
var config
var file_system: EditorFileSystem
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()])

View File

@@ -0,0 +1,153 @@
@tool
extends EditorImportPlugin
const result_codes = preload("../config/result_codes.gd")
var config
var _aseprite_file_exporter = preload("../aseprite/file_exporter.gd").new()
var _sf_creator = preload("../creators/sprite_frames/sprite_frames_creator.gd").new()
var file_system: EditorFileSystem
func _get_importer_name():
# ideally this should be called aseprite_wizard.plugin.spriteframes
# but I'm keeping it like this to avoid unnecessary breaking changes
return "aseprite_wizard.plugin"
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": "split_layers", "default_value": false},
{"name": "exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
{"name": "only_visible_layers", "default_value": false},
{
"name": "sheet_type",
"default_value": "Packed",
"property_hint": PROPERTY_HINT_ENUM,
"hint_string": get_sheet_type_hint_string()
},
]
func _get_option_visibility(path, option, options):
return true
static func get_sheet_type_hint_string() -> String:
var hint_string := "Packed"
for number in [2, 4, 8, 16, 32]:
hint_string += ",%s columns" % number
hint_string += ",Strip"
return hint_string
func _import(source_file, save_path, options, platform_variants, gen_files):
var absolute_source_file = ProjectSettings.globalize_path(source_file)
var absolute_save_path = ProjectSettings.globalize_path(save_path)
var source_path = source_file.substr(0, source_file.rfind('/'))
var source_basename = source_file.substr(source_path.length()+1, -1)
source_basename = source_basename.substr(0, source_basename.rfind('.'))
_sf_creator.init(config)
_aseprite_file_exporter.init(config)
var export_mode = _sf_creator.LAYERS_EXPORT_MODE if options['split_layers'] else _sf_creator.FILE_EXPORT_MODE
var aseprite_opts = {
"export_mode": export_mode,
"exception_pattern": options['exclude_layers_pattern'],
"only_visible_layers": options['only_visible_layers'],
"output_filename": '' if export_mode == _sf_creator.FILE_EXPORT_MODE else '%s_' % source_basename,
"column_count" : int(options['sheet_type']) if options['sheet_type'] != "Strip" else 128,
"output_folder": source_path,
}
var source_files = _aseprite_file_exporter.generate_aseprite_files(absolute_source_file, aseprite_opts)
if not source_files.is_ok:
printerr("ERROR - Could not import aseprite file: %s" % result_codes.get_error_message(source_files.code))
return FAILED
var should_trigger_scan = false
for sf in source_files.content:
if sf.is_first_import:
file_system.update_file(sf.sprite_sheet)
append_import_external_resource(sf.sprite_sheet)
else:
should_trigger_scan = true
if should_trigger_scan:
file_system.scan()
var resources = _sf_creator.create_resources(source_files.content)
if not resources.is_ok:
printerr("ERROR - Could not import aseprite file: %s" % result_codes.get_error_message(resources.code))
return FAILED
if export_mode == _sf_creator.LAYERS_EXPORT_MODE:
# each layer is saved as one resource using base file name to prevent collisions
# the first layer will be saved in the default resource path to prevent
# godot from keeping re-importing it
for resource in resources.content:
var resource_path = "%s.res" % resource.data_file.get_basename();
var exit_code = ResourceSaver.save(resource.resource, resource_path)
resource.resource.take_over_path(resource_path)
if exit_code != OK:
printerr("ERROR - Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code))
return FAILED
var resource = resources.content[0]
var resource_path = "%s.res" % save_path
var exit_code = ResourceSaver.save(resource.resource, resource_path)
resource.resource.take_over_path(resource_path)
if config.should_remove_source_files():
_remove_source_files(source_files.content)
if exit_code != OK:
printerr("ERROR - Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code))
return FAILED
return OK
func _remove_source_files(source_files: Array):
for s in source_files:
DirAccess.remove_absolute(s.data_file)
file_system.call_deferred("scan")

View File

@@ -0,0 +1,138 @@
@tool
extends EditorImportPlugin
##
## Static texture importer.
## Imports first frame from Aseprite file as texture
##
const result_codes = preload("../config/result_codes.gd")
var _aseprite_file_exporter = preload("../aseprite/file_exporter.gd").new()
var config
var file_system: EditorFileSystem
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_save_extension():
return "res"
func _get_resource_type():
return "AtlasTexture"
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_STATIC_TEXTURE_NAME else 0.8
func _get_import_order():
return 1
func _get_import_options(_path, _i):
return [
{"name": "exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
{"name": "only_visible_layers", "default_value": false},
]
func _get_option_visibility(path, option, options):
return true
func _import(source_file, save_path, options, platform_variants, gen_files):
var absolute_source_file = ProjectSettings.globalize_path(source_file)
var absolute_save_path = ProjectSettings.globalize_path(save_path)
var source_path = source_file.substr(0, source_file.rfind('/'))
var source_basename = source_file.substr(source_path.length()+1, -1)
source_basename = source_basename.substr(0, source_basename.rfind('.'))
_aseprite_file_exporter.init(config)
var aseprite_opts = {
"exception_pattern": options['exclude_layers_pattern'],
"only_visible_layers": options['only_visible_layers'],
"output_filename": '',
"output_folder": source_path,
"first_frame_only": true,
}
var result = _generate_texture(absolute_source_file, aseprite_opts)
if not result.is_ok:
printerr("ERROR - Could not import aseprite file: %s" % result_codes.get_error_message(result.code))
return FAILED
var sprite_sheet = result.content.sprite_sheet
var data = result.content.data
if ResourceLoader.exists(sprite_sheet):
file_system.scan()
else:
file_system.update_file(sprite_sheet)
append_import_external_resource(sprite_sheet)
var texture: CompressedTexture2D = ResourceLoader.load(sprite_sheet, "CompressedTexture2D", ResourceLoader.CACHE_MODE_REPLACE)
return _save_resource(texture, 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_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(texture: CompressedTexture2D, save_path: String, data_file_path: String, size: Dictionary) -> int:
var resource = AtlasTexture.new()
resource.atlas = texture
resource.region = Rect2(0, 0, size.w, size.h)
var resource_path = "%s.res" % save_path
var exit_code = ResourceSaver.save(resource, resource_path)
resource.take_over_path(resource_path)
if config.should_remove_source_files():
DirAccess.remove_absolute(data_file_path)
file_system.call_deferred("scan")
if exit_code != OK:
printerr("ERROR - Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code))
return FAILED
return OK

View File

@@ -0,0 +1,137 @@
@tool
extends EditorImportPlugin
##
## Tileset texture importer.
## Imports Aseprite tileset layers as an AtlasTexture
##
const result_codes = preload("../config/result_codes.gd")
var _aseprite_file_exporter = preload("../aseprite/file_exporter.gd").new()
var config
var file_system: EditorFileSystem
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 "AtlasTexture"
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": "exclude_layers_pattern", "default_value": config.get_default_exclusion_pattern()},
{"name": "only_visible_layers", "default_value": false},
]
func _get_option_visibility(path, option, options):
return true
func _import(source_file, save_path, options, platform_variants, gen_files):
var absolute_source_file = ProjectSettings.globalize_path(source_file)
var absolute_save_path = ProjectSettings.globalize_path(save_path)
var source_path = source_file.substr(0, source_file.rfind('/'))
var source_basename = source_file.substr(source_path.length()+1, -1)
source_basename = source_basename.substr(0, source_basename.rfind('.'))
_aseprite_file_exporter.init(config)
var aseprite_opts = {
"exception_pattern": options['exclude_layers_pattern'],
"only_visible_layers": options['only_visible_layers'],
"output_filename": '',
"output_folder": source_path,
}
var result = _generate_texture(absolute_source_file, aseprite_opts)
if not result.is_ok:
printerr("ERROR - Could not import aseprite file: %s" % result_codes.get_error_message(result.code))
return FAILED
var sprite_sheet = result.content.sprite_sheet
var data = result.content.data
if ResourceLoader.exists(sprite_sheet):
file_system.scan()
else:
file_system.update_file(sprite_sheet)
append_import_external_resource(sprite_sheet)
var texture: CompressedTexture2D = ResourceLoader.load(sprite_sheet, "CompressedTexture2D", ResourceLoader.CACHE_MODE_REPLACE)
return _save_resource(texture, 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(texture: CompressedTexture2D, save_path: String, data_file_path: String, size: Dictionary) -> int:
var resource = AtlasTexture.new()
resource.atlas = texture
resource.region = Rect2(0, 0, size.w, size.h)
var resource_path = "%s.res" % save_path
var exit_code = ResourceSaver.save(resource, resource_path)
resource.take_over_path(resource_path)
if config.should_remove_source_files():
DirAccess.remove_absolute(data_file_path)
file_system.call_deferred("scan")
if exit_code != OK:
printerr("ERROR - Could not persist aseprite file: %s" % result_codes.get_error_message(exit_code))
return FAILED
return OK