Refactor rhythm action architecture
This commit is contained in:
68
scenes/components/burst_component.gd
Normal file
68
scenes/components/burst_component.gd
Normal file
@@ -0,0 +1,68 @@
|
||||
class_name BurstComponent
|
||||
extends Node
|
||||
|
||||
signal burst_changed(burst_ready: bool, active: bool, cooldown: int)
|
||||
|
||||
@export var active_beats := 16
|
||||
@export var cooldown_beats := 4
|
||||
|
||||
var burst_ready := false
|
||||
var active := false
|
||||
var cooldown := 0
|
||||
var _beats_left := 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var rhythm := get_tree().root.get_node_or_null("RhythmManager")
|
||||
if rhythm != null and not rhythm.is_connected("beat_ticked", _on_beat_ticked):
|
||||
rhythm.connect("beat_ticked", _on_beat_ticked)
|
||||
|
||||
|
||||
func set_ready(value: bool) -> void:
|
||||
if active or cooldown > 0:
|
||||
burst_ready = false
|
||||
else:
|
||||
burst_ready = value
|
||||
burst_changed.emit(burst_ready, active, cooldown)
|
||||
|
||||
|
||||
func activate() -> bool:
|
||||
if not burst_ready or active or cooldown > 0:
|
||||
return false
|
||||
burst_ready = false
|
||||
active = true
|
||||
_beats_left = active_beats
|
||||
_set_rhythm_scale(1.25)
|
||||
burst_changed.emit(burst_ready, active, cooldown)
|
||||
return true
|
||||
|
||||
|
||||
func damage_mult(_action: Resource = null) -> float:
|
||||
return 1.2 if active else 1.0
|
||||
|
||||
|
||||
func cost_mult(_action: Resource = null) -> float:
|
||||
return 0.0 if active else 1.0
|
||||
|
||||
|
||||
func move_mult(_action: Resource = null) -> float:
|
||||
return 1.0
|
||||
|
||||
|
||||
func _on_beat_ticked(_beat_index: int) -> void:
|
||||
if active:
|
||||
_beats_left -= 1
|
||||
if _beats_left <= 0:
|
||||
active = false
|
||||
cooldown = cooldown_beats
|
||||
_set_rhythm_scale(1.0)
|
||||
burst_changed.emit(burst_ready, active, cooldown)
|
||||
elif cooldown > 0:
|
||||
cooldown -= 1
|
||||
burst_changed.emit(burst_ready, active, cooldown)
|
||||
|
||||
|
||||
func _set_rhythm_scale(scale: float) -> void:
|
||||
var rhythm := get_tree().root.get_node_or_null("RhythmManager")
|
||||
if rhythm != null:
|
||||
rhythm.set("judgement_scale", scale)
|
||||
Reference in New Issue
Block a user