Files
mortal-maze-the-game/tests/test_pickup_runtime.gd
T

100 lines
3.4 KiB
GDScript

extends SceneTree
## Full Godot integration test. Requires the real engine and imported SVGs.
## Run: godot --headless --path . --script res://tests/test_pickup_runtime.gd
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var packed_level: PackedScene = load("res://levels/level_01.tscn") as PackedScene
if packed_level == null:
_fail("No se pudo cargar level_01")
return
var level: Node2D = packed_level.instantiate() as Node2D
root.add_child(level)
current_scene = level
await process_frame
var status: Label = level.get_node("TestHUD/Overlay/Status") as Label
if not status.text.contains("LAB DROPS v2"):
_fail("No se esta ejecutando level_01.gd")
return
# The pre-placed control pickup must work even without any enemy death.
var control: Pickup = level.get_node("ControlPickup") as Pickup
if control == null or control.pickup_data == null or control.pickup_data.id != &"lab_control":
_fail("El pickup de control no se instancio")
return
if not control.visible or control.get_node("Sprite2D").texture == null:
_fail("El pickup de control no tiene icono visible")
return
var enemies: Array[Node] = level.get_node("TestEnemies").get_children()
if enemies.size() != 17:
_fail("Se esperaban 17 enemigos, hay %d" % enemies.size())
return
var expected_ids: Dictionary = {}
for enemy in enemies:
var data: PickupData = enemy.get("guaranteed_drop") as PickupData
if data == null or not bool(enemy.get("drops_handled_by_level")):
_fail("Configuracion de drop incorrecta: %s" % enemy.name)
return
expected_ids[data.id] = true
# Simulate a missed signal for station 01. The polling of is_dead must
# still register its KO and create the guaranteed drop.
var lab_callback: Callable = Callable(level, "_on_station_enemy_died")
enemies[0].disconnect(&"died", lab_callback)
for enemy in enemies:
enemy.call("take_damage", int(enemy.get("max_health")), Vector2.ZERO)
await create_timer(0.25).timeout
if level.defeated_enemies != 17 or level.spawned_drops != 17:
_fail("KO/drops incorrectos: %d KOs, %d drops" % [level.defeated_enemies, level.spawned_drops])
return
if level.death_signals != 16:
_fail("Se esperaban 16 senales despues de desconectar una, hay %d" % level.death_signals)
return
var pickups: Array[Node] = get_nodes_in_group("pickup")
if pickups.size() != 18:
_fail("Se esperaban 17 drops mas el control, hay %d" % pickups.size())
return
var actual_ids: Dictionary = {}
for node in pickups:
var pickup: Pickup = node as Pickup
if pickup == null or pickup.pickup_data == null or not pickup.visible:
_fail("Hay un pickup invalido o invisible")
return
if pickup.get_node("Sprite2D").texture == null:
_fail("Pickup sin icono: %s" % pickup.pickup_data.id)
return
if pickup.monitoring:
_fail("Pickup activo antes de los 0.75 s: %s" % pickup.pickup_data.id)
return
if pickup.pickup_data.id != &"lab_control":
actual_ids[pickup.pickup_data.id] = true
if actual_ids != expected_ids:
_fail("Los 17 drops no corresponden a las estaciones")
return
await create_timer(0.2).timeout
if get_nodes_in_group("pickup").size() != 18:
_fail("Se duplicaron o perdieron drops al procesar frames adicionales")
return
print("OK LAB DROPS v2: 17 KOs, 17 recompensas distintas, 1 control, 1 senal desconectada")
quit(0)
func _fail(message: String) -> void:
push_error("Prueba runtime de pickups: " + message)
quit(1)