@tool
extends AnimationSelectCfg

class_name SkillCfg

@export var name : String
@export var skill_animation : Animation
@export var attack_list : Array[AttackCfg]
@export var sub_character_list : Array[CharacterCfg]
@export var free_lock : bool

@export var refresh_animation : bool :
	get:return false
	set(value):if Engine.is_editor_hint():check_animation()

func check_animation():
	var res_name = Util.get_resource_name(self)
	var path = "res://resource/skill_animation/%s.tres" %res_name
	if sprite_frames == null:
		print("未设置技能动画资源")
		return false
	if animation_name == "":
		print("未设置技能动画名")
		return false
	if !sprite_frames.has_animation(animation_name):
		print("技能动画名不存在")
		return false
	var animation = ResourceLoader.load(path) as Animation
	if not animation:
		animation = Animation.new()
		animation.resource_name = res_name
	Util.refresh_animation_by_sprite_frames(path,sprite_frames,animation_name,animation)
	Util.refresh_animation_lib()
	skill_animation = load(path)

func get_attack(index:int)->AttackCfg:
	if !attack_list:
		return ResourceManager.cfg_attack_normal
	if index >= len(attack_list):
		index = len(attack_list) - 1
	var attack = attack_list[index] as AttackCfg
	return attack

func get_attack_particle(index:int)->Resource:
	var res_name = Util.get_resource_name(self)
	var path_index = "res://scene/effect/particle/%s_%d.tscn" % [res_name,index]
	if ResourceLoader.exists(path_index):
		return load(path_index)
	var path_default = "res://scene/effect/particle/%s.tscn" % res_name
	if ResourceLoader.exists(path_default):
		return load(path_default)
	return null
