90 lines
2.7 KiB
GDScript
90 lines
2.7 KiB
GDScript
extends SceneTree
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
_check_energy_bar_scene_has_editor_segments()
|
|
|
|
var scene: PackedScene = load("res://scenes/ui/main_ui.tscn")
|
|
if scene == null:
|
|
push_error("Could not load main_ui.tscn")
|
|
quit(1)
|
|
return
|
|
|
|
var ui := scene.instantiate()
|
|
root.add_child(ui)
|
|
await process_frame
|
|
|
|
_expect_node(ui, "RhythmTrack", "UI should include RhythmTrack")
|
|
_expect_node(ui, "ComboWindow", "UI should include ComboWindow")
|
|
_expect_node(ui, "StatusBars/HealthBar", "UI should include HealthBar")
|
|
_expect_node(ui, "StatusBars/EnergyBar", "UI should include EnergyBar")
|
|
_expect_node(ui, "StatusBars/ChargeBar", "UI should include ChargeBar")
|
|
|
|
var combo_window := ui.get_node("ComboWindow")
|
|
_expect_bool(combo_window.get_child_count() >= 4, true, "ComboWindowHud should build four visual slots")
|
|
|
|
var bus := _event_bus()
|
|
bus.emit_signal("player_health_changed", 42, 100)
|
|
bus.emit_signal("player_energy_changed", 3.0, 10.0)
|
|
bus.emit_signal("player_charge_changed", 0.8, 1.1, false, true)
|
|
bus.emit_signal("combo_updated", [&"A", &"SP"])
|
|
await process_frame
|
|
|
|
var health_bar := ui.get_node("StatusBars/HealthBar") as ProgressBar
|
|
var charge_bar := ui.get_node("StatusBars/ChargeBar") as ProgressBar
|
|
_expect_float(float(health_bar.value), 42.0, "HealthBar should follow EventBus health")
|
|
_expect_float(float(charge_bar.value), 0.8, "ChargeBar should follow EventBus charge")
|
|
|
|
ui.free()
|
|
_finish()
|
|
|
|
|
|
func _check_energy_bar_scene_has_editor_segments() -> void:
|
|
var scene: PackedScene = load("res://scenes/ui/energy_bar.tscn")
|
|
if scene == null:
|
|
failures.append("Could not load energy_bar.tscn")
|
|
return
|
|
var energy_bar := scene.instantiate()
|
|
_expect_bool(energy_bar.get_child_count() == 10, true, "EnergyBar scene should contain ten editor-visible segments before _ready")
|
|
energy_bar.free()
|
|
|
|
|
|
func _event_bus() -> Node:
|
|
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 _expect_node(node: Node, path: String, label: String) -> void:
|
|
if node.get_node_or_null(path) == null:
|
|
failures.append(label)
|
|
|
|
|
|
func _expect_bool(actual: bool, expected: bool, label: String) -> void:
|
|
if actual != expected:
|
|
failures.append("%s: expected %s, got %s" % [label, expected, actual])
|
|
|
|
|
|
func _expect_float(actual: float, expected: float, label: String) -> void:
|
|
if not is_equal_approx(actual, expected):
|
|
failures.append("%s: expected %.3f, got %.3f" % [label, expected, actual])
|
|
|
|
|
|
func _finish() -> void:
|
|
if failures.is_empty():
|
|
print("PASS combo hud")
|
|
quit(0)
|
|
else:
|
|
for failure: String in failures:
|
|
push_error(failure)
|
|
quit(1)
|