Files
Fighting_Rthythm_game/tests/test_combo_hud.gd
2026-07-02 05:11:24 -07:00

88 lines
3.2 KiB
GDScript

extends SceneTree
var failures: Array[String] = []
func _init() -> void:
var scene: PackedScene = load("res://scenes/main/main.tscn")
if scene == null:
push_error("Could not load main.tscn")
quit(1)
return
var main: Node = scene.instantiate()
get_root().add_child(main)
var player: Node = main.get_node_or_null("Player")
if player == null:
failures.append("Missing Player")
elif not player.has_signal("combo_window_cleared"):
failures.append("Player should expose combo_window_cleared")
if not main.has_method("_play_combo_clear_animation"):
failures.append("Main should implement _play_combo_clear_animation")
if not main.has_method("_on_energy_changed"):
failures.append("Main should implement _on_energy_changed")
if not main.has_method("_on_health_changed"):
failures.append("Main should implement _on_health_changed")
if not main.has_method("_on_charge_changed"):
failures.append("Main should implement _on_charge_changed")
var status_bars: Node = main.get_node_or_null("RhythmFeedback/StatusBars")
if status_bars == null:
failures.append("Missing StatusBars")
else:
var health_bar := status_bars.get_node_or_null("HealthBar")
if health_bar == null:
failures.append("Missing HealthBar")
elif not health_bar is ProgressBar:
failures.append("HealthBar should be a ProgressBar")
var energy_bar := status_bars.get_node_or_null("EnergyBar")
if energy_bar == null:
failures.append("Missing EnergyBar")
else:
for index: int in range(10):
var segment := energy_bar.get_node_or_null("Segment%d" % index)
if segment == null:
failures.append("Missing energy segment %d" % index)
elif not segment is Panel:
failures.append("Energy segment %d should be a Panel" % index)
var charge_bar := status_bars.get_node_or_null("ChargeBar")
if charge_bar == null:
failures.append("Missing ChargeBar")
elif not charge_bar is ProgressBar:
failures.append("ChargeBar should be a ProgressBar")
elif main.has_method("_on_charge_changed") and main.has_method("_update_charge_bar_flash"):
main.set("charge_bar", charge_bar)
main.call("_on_charge_changed", 1.1, 1.1, true, true)
main.call("_update_charge_bar_flash", 0.13)
var flashing_alpha: float = charge_bar.modulate.a
main.call("_on_charge_changed", 1.1, 1.1, true, true)
if is_equal_approx(charge_bar.modulate.a, 1.0):
failures.append("Ready charge updates should not reset ChargeBar flash alpha")
if not is_equal_approx(charge_bar.modulate.a, flashing_alpha):
failures.append("Ready charge updates should preserve ChargeBar flash alpha")
var combo_window: Node = main.get_node_or_null("RhythmFeedback/ComboWindow")
if combo_window == null:
failures.append("Missing ComboWindow")
else:
for index: int in range(4):
var slot := combo_window.get_node_or_null("Slot%d" % index)
if slot == null:
failures.append("Missing visual slot %d" % index)
continue
if not slot is PanelContainer:
failures.append("Slot%d should be a PanelContainer" % index)
if slot.get_node_or_null("Key") == null:
failures.append("Slot%d should contain Key label" % index)
main.free()
if failures.is_empty():
print("PASS combo hud")
quit(0)
else:
for failure: String in failures:
push_error(failure)
quit(1)