Initial project sync
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
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", &"D", &"W", &"S"])
|
||||
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")
|
||||
|
||||
var labels := _combo_slot_texts(combo_window)
|
||||
_expect_array(labels, ["A", "D", "W", "S"], "ComboWindowHud should render the four directional/action symbols")
|
||||
bus.emit_signal("combo_updated", [&"SP", &"Ø"])
|
||||
await process_frame
|
||||
labels = _combo_slot_texts(combo_window)
|
||||
_expect_array(labels, ["sp", "∅", "∅", "∅"], "ComboWindowHud should normalize space and miss placeholders without judgement grades")
|
||||
|
||||
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 is ProgressBar, true, "EnergyBar should match the reference ProgressBar implementation")
|
||||
_expect_bool(energy_bar.get_child_count() == 0, true, "Reference EnergyBar should not build editor-visible segment children")
|
||||
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 _combo_slot_texts(combo_window: Node) -> Array[String]:
|
||||
var texts: Array[String] = []
|
||||
for child: Node in combo_window.get_children():
|
||||
var panel := child as PanelContainer
|
||||
if panel == null or panel.get_child_count() == 0:
|
||||
continue
|
||||
var label := panel.get_child(0) as Label
|
||||
if label != null:
|
||||
texts.append(label.text)
|
||||
return texts
|
||||
|
||||
|
||||
func _expect_array(actual: Array, expected: Array, label: String) -> void:
|
||||
if actual != expected:
|
||||
failures.append("%s: expected %s, got %s" % [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)
|
||||
Reference in New Issue
Block a user