init
This commit is contained in:
commit
f389e4e807
186 changed files with 10853 additions and 0 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue