42 lines
1.3 KiB
GDScript
42 lines
1.3 KiB
GDScript
extends SceneTree
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _init() -> void:
|
|
var conductor_script: Script = load("res://scenes/rhythm/rhythm_conductor.gd")
|
|
if conductor_script == null:
|
|
push_error("Could not load rhythm_conductor.gd")
|
|
quit(1)
|
|
return
|
|
var conductor: Node = conductor_script.new()
|
|
conductor.set("bpm", 120.0)
|
|
conductor.set("perfect_window", 0.060)
|
|
conductor.set("good_window", 0.120)
|
|
conductor.set("bad_window", 0.200)
|
|
conductor.set("beat_offset", 0.0)
|
|
conductor.call("_ready")
|
|
|
|
_expect_rating(conductor, 1.000, "perfect", "exact beat")
|
|
_expect_rating(conductor, 1.055, "perfect", "55ms from beat")
|
|
_expect_rating(conductor, 1.095, "good", "95ms from beat")
|
|
_expect_rating(conductor, 1.170, "bad", "170ms from beat")
|
|
_expect_rating(conductor, 1.240, "miss", "240ms from beat")
|
|
|
|
conductor.free()
|
|
|
|
if failures.is_empty():
|
|
print("PASS rhythm conductor")
|
|
quit(0)
|
|
else:
|
|
for failure: String in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _expect_rating(conductor: Node, time_seconds: float, expected: String, label: String) -> void:
|
|
var rating: Dictionary = conductor.call("get_rating_for_time", time_seconds)
|
|
var actual: String = str(rating.get("label", ""))
|
|
if actual != expected:
|
|
failures.append("%s: expected %s, got %s" % [label, expected, actual])
|