Fix para los items que no caen
This commit is contained in:
1 parent
5012879591
commit
e1e29f02f1
9 files changed
+233
-65
No files matched your search
@@ -1,68 +1,99 @@
|
||||
extends SceneTree
|
||||
|
||||
## Godot integration smoke test. Run from the project root with:
|
||||
## godot --headless --path . --script res://tests/test_pickup_runtime.gd
|
||||
## It checks actual instantiation after enemy death, not merely text in a .tscn.
|
||||
## 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 := load("res://levels/level_01.tscn") as PackedScene
|
||||
var packed_level: PackedScene = load("res://levels/level_01.tscn") as PackedScene
|
||||
if packed_level == null:
|
||||
_fail("Could not load Level 01")
|
||||
_fail("No se pudo cargar level_01")
|
||||
return
|
||||
|
||||
var level := packed_level.instantiate()
|
||||
var level: Node2D = packed_level.instantiate() as Node2D
|
||||
root.add_child(level)
|
||||
current_scene = level
|
||||
await process_frame
|
||||
|
||||
var enemies := level.get_node("TestEnemies").get_children()
|
||||
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("Expected 17 test enemies, found %d" % enemies.size())
|
||||
_fail("Se esperaban 17 enemigos, hay %d" % enemies.size())
|
||||
return
|
||||
|
||||
var expected_ids: Dictionary = {}
|
||||
for enemy in enemies:
|
||||
var item: PickupData = enemy.get("guaranteed_drop") as PickupData
|
||||
if item == null:
|
||||
_fail("Missing guaranteed_drop on %s" % enemy.name)
|
||||
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[item.id] = true
|
||||
# Force a kill independently of enemy movement, AI and the camera.
|
||||
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)
|
||||
|
||||
# Deferred add_child runs during the idle step, after the physics callback.
|
||||
await create_timer(0.2).timeout
|
||||
var pickups := get_nodes_in_group("pickup")
|
||||
if pickups.size() != 17:
|
||||
_fail("Expected 17 spawned pickups, found %d" % pickups.size())
|
||||
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 spawned_ids: Dictionary = {}
|
||||
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 := node as Pickup
|
||||
if pickup == null or pickup.pickup_data == null:
|
||||
_fail("Spawned a pickup without PickupData")
|
||||
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 not pickup.visible or pickup.get_node("Sprite2D").texture == null:
|
||||
_fail("Pickup has no visible sprite: %s" % pickup.pickup_data.id)
|
||||
if pickup.get_node("Sprite2D").texture == null:
|
||||
_fail("Pickup sin icono: %s" % pickup.pickup_data.id)
|
||||
return
|
||||
if pickup.monitoring:
|
||||
_fail("Pickup collection activated before grace period: %s" % pickup.pickup_data.id)
|
||||
_fail("Pickup activo antes de los 0.75 s: %s" % pickup.pickup_data.id)
|
||||
return
|
||||
spawned_ids[pickup.pickup_data.id] = true
|
||||
if pickup.pickup_data.id != &"lab_control":
|
||||
actual_ids[pickup.pickup_data.id] = true
|
||||
|
||||
if spawned_ids.size() != expected_ids.size() or spawned_ids != expected_ids:
|
||||
_fail("Drops do not match the 17 assigned resources")
|
||||
if actual_ids != expected_ids:
|
||||
_fail("Los 17 drops no corresponden a las estaciones")
|
||||
return
|
||||
|
||||
print("OK: all 17 guaranteed drops spawned, visible and correctly assigned.")
|
||||
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("Pickup runtime test: " + message)
|
||||
push_error("Prueba runtime de pickups: " + message)
|
||||
quit(1)
|
||||
Reference in new issue
Block a user