Raise-Your-Wand/Scripts/animationBase.gd

39 lines
864 B
GDScript3
Raw Normal View History

class_name AnimationBase extends Node2D
signal animationFinished(spell: Spell)
2024-05-03 19:45:30 -04:00
@onready var animationPlayer: AnimationPlayer = $AnimationPlayer
@export var inverted: bool = false
@export var index: int = -1
@export var finalIndex: int = 0
@export var spell: Spell
var attackName: String = "attackSegment"
var inverseName: String = "attackInverse"
2024-05-03 19:45:30 -04:00
var targetProg: float
var finalProg: float
# Called when the node enters the scene tree for the first time.
func _ready():
if inverted:
attackName = inverseName
func castFailed() -> void:
die()
2024-05-03 19:45:30 -04:00
func setProgress(target: float, final: float = finalProg) -> void:
2024-05-03 19:45:30 -04:00
targetProg = target
finalProg = final
if (index > -1):
animationPlayer.queue(attackName + str(index))
index += 1
func animFinished(_s: String):
if (index == finalIndex):
animationFinished.emit(spell)
die()
func die():
queue_free()