2024-05-23 22:58:20 -04:00
|
|
|
class_name SpellSlot extends TextureRect
|
|
|
|
|
|
|
|
@onready var overlay: ColorRect = $Overlay
|
|
|
|
@onready var particles: GPUParticles2D = $GPUParticles2D
|
2024-05-25 23:51:28 -04:00
|
|
|
@onready var data: Data = $/root/Root/Data
|
2024-05-23 22:58:20 -04:00
|
|
|
|
|
|
|
@export var spell: Spell
|
|
|
|
var timer: float = 0
|
|
|
|
var canCast: bool = true
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
2024-05-25 23:51:28 -04:00
|
|
|
if (spell == null || !data.playing): return
|
2024-05-23 22:58:20 -04:00
|
|
|
timer = clampf(timer - delta, 0, spell.cooldown)
|
|
|
|
if (!canCast && timer == 0):
|
|
|
|
canCast = true
|
|
|
|
particles.emitting = true
|
|
|
|
overlay.scale.y = timer / spell.cooldown
|
|
|
|
|
|
|
|
func setSpell(spel: Spell):
|
|
|
|
spell = spel
|
|
|
|
texture = spel.icon
|
|
|
|
|
|
|
|
func spellCast(down: float):
|
|
|
|
timer = down
|
|
|
|
canCast = false
|