MagicNStuff/game/tools/animation_player_editor_calls.gd

73 lines
1.8 KiB
GDScript

@tool
class_name AnimationPlayerEditorCalls
extends AnimationPlayer
@export var excluded_function_calls: Array[StringName] = [
&"queue_free",
&"free",
]
var EDITOR_PATH: String:
get: return str(get_parent().get_path()) + "/"
var function_calls: Array[Dictionary] = []
func _ready() -> void:
animation_started.connect(animation_started_func)
func _process(_delta: float) -> void:
if not Engine.is_editor_hint():
return
if not is_playing():
function_calls.clear()
return
var remove_these_function_calls: Array = []
for index: int in function_calls.size():
var function_call: Dictionary = function_calls[index]
if function_call.time > current_animation_position:
continue
if excluded_function_calls.has(function_call.name):
remove_these_function_calls.append(index)
continue
var node: Node = get_node(function_call.path)
node.call(function_call.name)
remove_these_function_calls.append(index)
for index: int in remove_these_function_calls:
function_calls.remove_at(index)
func animation_started_func(_dismiss: Variant) -> void:
if not Engine.is_editor_hint():
return
var animation: Animation = get_animation(current_animation)
for track_index: int in animation.get_track_count():
if not animation.track_is_enabled(track_index):
continue
if animation.track_get_type(track_index) != Animation.TYPE_METHOD:
continue
var path: String = EDITOR_PATH + str(animation.track_get_path(track_index))
var track_key_count: int = animation.track_get_key_count(track_index)
for key_index: int in track_key_count:
var time: float = animation.track_get_key_time(track_index, key_index)
if time < current_animation_position:
continue
var _name: StringName = animation.method_track_get_name(track_index, key_index)
function_calls.append({
"path": path,
"name": _name,
"time": time,
})