Raise-Your-Wand/Scripts/animationBase.gd

53 lines
1.4 KiB
GDScript3
Raw Permalink 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
2024-05-27 19:54:22 -04:00
@onready var data: Data = $/root/Root/Data
@export var inverted: bool = false
@export var index: int = -1
@export var finalIndex: int = 0
@export var spell: Spell
@export var soundEffect: String
@export var soundPlayedIndex: int = -2
var attackName: String = "attackSegment"
var inverseName: String = "attackInverse"
2024-05-03 19:45:30 -04:00
var targetProg: float
var finalProg: float
var stream: AudioStream
# Called when the node enters the scene tree for the first time.
func _ready():
if (soundEffect != ""):
stream = load(soundEffect)
if (stream == null): print(spell.name + " failed")
if inverted:
attackName = inverseName
2024-05-27 19:54:22 -04:00
func _process(delta):
if (!data.playing): self.queue_free()
2024-05-27 19:54:22 -04:00
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):
2024-05-30 22:55:48 -04:00
if (animationPlayer.has_animation(attackName + str(index))): animationPlayer.queue(attackName + str(index))
if (index == soundPlayedIndex && soundEffect != ""):
data.playSound(stream)
index += 1
func animFinished(_s: String):
2024-06-07 16:14:22 -04:00
if (index >= finalIndex):
2024-06-07 16:23:26 -04:00
if (index >= soundPlayedIndex && soundEffect != ""):
data.playSound(stream)
animationFinished.emit(spell)
die()
func die():
queue_free()