@tool
extends Node3D

func get_resource_name(resource:Resource) -> String:
	return resource.resource_path.get_file().trim_suffix('.tres') #todo 性能

func vector_reduce(vector:Vector2,reduce:float) -> Vector2:
	var len = vector.length()
	if len == 0:
		return vector
	var new_len = max(len - reduce,0)
	var scale_rate = new_len / len
	return vector * scale_rate

func refresh_animation_lib():
	var animation_library_path = "res://resource/skill_animation_library/animation_library.tres"
	var animation_library = load(animation_library_path)
	
	var dir_path = "res://resource/skill_animation"
	var dir = DirAccess.open(dir_path)
	for file in dir.get_files():
		var path = dir_path + "/" + file
		var res = load(path)
		if res is Animation:
			var animation = res as Animation
			var animation_name = Util.get_resource_name(animation)
			print(animation_name)
			animation_library.add_animation(animation_name,animation)
			animation_library.animation_added.emit(animation_name)
	
	ResourceSaver.save(animation_library,animation_library_path)
		
func get_all_player_skill():
	var ret = []
	var dir_path = "res://config/player_skill"
	var dir = DirAccess.open(dir_path)
	for file in dir.get_files():
		var path = dir_path + "/" + file
		var res = load(path)
		if res is PlayerSkillCfg:
			ret.append(res)
	return ret
