Refactor rhythm action architecture
This commit is contained in:
@@ -27,6 +27,8 @@ signal action_judged(action_name: String, rating: Dictionary)
|
||||
func _ready() -> void:
|
||||
add_to_group("rhythm_conductor")
|
||||
sec_per_beat = 60.0 / bpm
|
||||
if is_inside_tree():
|
||||
_event_bus().connect("rhythm_action_requested", _on_rhythm_action_requested)
|
||||
if starts_on_ready:
|
||||
start()
|
||||
|
||||
@@ -72,11 +74,9 @@ func judge_action(action_name: String) -> Dictionary:
|
||||
var rating := get_current_rating()
|
||||
rating["action"] = action_name
|
||||
emit_signal("action_judged", action_name, rating)
|
||||
print("Rhythm %s: %s (%s ms)" % [
|
||||
action_name,
|
||||
str(rating.get("label", "miss")),
|
||||
_format_signed_ms(float(rating.get("diff", INF)))
|
||||
])
|
||||
var bus := _event_bus()
|
||||
bus.emit_signal("judgement_made", StringName(str(rating.get("label", "miss"))), float(rating.get("diff", INF)) * 1000.0)
|
||||
bus.emit_signal("action_judged", StringName(action_name), rating)
|
||||
return rating
|
||||
|
||||
|
||||
@@ -128,10 +128,25 @@ func _report_beat() -> void:
|
||||
current_measure = 1
|
||||
emit_signal("beat", song_position_in_beats)
|
||||
emit_signal("measure", current_measure)
|
||||
_event_bus().emit_signal("beat_ticked", song_position_in_beats)
|
||||
last_reported_beat = song_position_in_beats
|
||||
current_measure += 1
|
||||
|
||||
|
||||
func _on_rhythm_action_requested(action_name: StringName) -> void:
|
||||
judge_action(str(action_name))
|
||||
|
||||
|
||||
func _event_bus() -> Node:
|
||||
var root := get_tree().root
|
||||
var bus := root.get_node_or_null("EventBus")
|
||||
if bus == null:
|
||||
bus = load("res://autoload/event_bus.gd").new()
|
||||
bus.name = "EventBus"
|
||||
root.add_child(bus)
|
||||
return bus
|
||||
|
||||
|
||||
func _apply_beat_offset(time_seconds: float) -> float:
|
||||
return time_seconds + beat_offset
|
||||
|
||||
|
||||
Reference in New Issue
Block a user