2024-05-13 22:38:17 -04:00
|
|
|
class_name AnimationBase extends Node2D
|
2024-05-03 07:56:32 -04:00
|
|
|
|
2024-05-13 22:38:17 -04:00
|
|
|
signal animationFinished(spell: Spell)
|
2024-05-03 19:45:30 -04:00
|
|
|
|
2024-05-14 21:40:18 -04:00
|
|
|
@onready var animationPlayer: AnimationPlayer = $AnimationPlayer
|
2024-05-27 19:54:22 -04:00
|
|
|
@onready var data: Data = $/root/Root/Data
|
2024-05-14 21:40:18 -04:00
|
|
|
|
2024-05-03 07:56:32 -04:00
|
|
|
@export var inverted: bool = false
|
2024-05-13 22:38:17 -04:00
|
|
|
@export var index: int = -1
|
|
|
|
@export var finalIndex: int = 0
|
|
|
|
@export var spell: Spell
|
2024-05-29 16:13:26 -04:00
|
|
|
@export var soundEffect: String
|
|
|
|
@export var soundPlayedIndex: int = -2
|
|
|
|
|
2024-05-13 22:38:17 -04:00
|
|
|
var attackName: String = "attackSegment"
|
|
|
|
var inverseName: String = "attackInverse"
|
2024-05-03 19:45:30 -04:00
|
|
|
var targetProg: float
|
|
|
|
var finalProg: float
|
2024-05-29 16:13:26 -04:00
|
|
|
var stream: AudioStream
|
2024-05-03 07:56:32 -04:00
|
|
|
|
2024-05-14 21:40:18 -04:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2024-05-30 15:56:16 -04:00
|
|
|
if (soundEffect != ""):
|
2024-05-29 20:50:12 -04:00
|
|
|
stream = load(soundEffect)
|
|
|
|
if (stream == null): print(spell.name + " failed")
|
2024-05-14 21:40:18 -04:00
|
|
|
if inverted:
|
|
|
|
attackName = inverseName
|
|
|
|
|
2024-05-27 19:54:22 -04:00
|
|
|
func _process(delta):
|
2024-06-01 11:01:21 -04:00
|
|
|
if (!data.playing): self.queue_free()
|
2024-05-27 19:54:22 -04:00
|
|
|
|
2024-05-09 22:21:58 -04:00
|
|
|
func castFailed() -> void:
|
2024-05-14 21:40:18 -04:00
|
|
|
die()
|
2024-05-03 19:45:30 -04:00
|
|
|
|
2024-05-09 22:21:58 -04:00
|
|
|
func setProgress(target: float, final: float = finalProg) -> void:
|
2024-05-03 19:45:30 -04:00
|
|
|
targetProg = target
|
|
|
|
finalProg = final
|
2024-05-14 21:40:18 -04:00
|
|
|
if (index > -1):
|
2024-05-30 22:55:48 -04:00
|
|
|
if (animationPlayer.has_animation(attackName + str(index))): animationPlayer.queue(attackName + str(index))
|
2024-05-30 15:56:16 -04:00
|
|
|
if (index == soundPlayedIndex && soundEffect != ""):
|
2024-05-29 20:50:12 -04:00
|
|
|
data.playSound(stream)
|
2024-05-14 21:40:18 -04:00
|
|
|
index += 1
|
|
|
|
|
|
|
|
func animFinished(_s: String):
|
2024-06-07 16:14:22 -04:00
|
|
|
if (index >= finalIndex):
|
2024-05-30 15:56:16 -04:00
|
|
|
if (index == soundPlayedIndex && soundEffect != ""):
|
2024-05-29 20:50:12 -04:00
|
|
|
data.playSound(stream)
|
2024-05-14 21:40:18 -04:00
|
|
|
animationFinished.emit(spell)
|
|
|
|
die()
|
|
|
|
|
|
|
|
func die():
|
|
|
|
queue_free()
|