69 lines
2.2 KiB
GDScript
69 lines
2.2 KiB
GDScript
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.
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
var packed_level := load("res://levels/level_01.tscn") as PackedScene
|
|
if packed_level == null:
|
|
_fail("Could not load Level 01")
|
|
return
|
|
|
|
var level := packed_level.instantiate()
|
|
root.add_child(level)
|
|
current_scene = level
|
|
await process_frame
|
|
|
|
var enemies := level.get_node("TestEnemies").get_children()
|
|
if enemies.size() != 17:
|
|
_fail("Expected 17 test enemies, found %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)
|
|
return
|
|
expected_ids[item.id] = true
|
|
# Force a kill independently of enemy movement, AI and the camera.
|
|
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())
|
|
return
|
|
|
|
var spawned_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")
|
|
return
|
|
if not pickup.visible or pickup.get_node("Sprite2D").texture == null:
|
|
_fail("Pickup has no visible sprite: %s" % pickup.pickup_data.id)
|
|
return
|
|
if pickup.monitoring:
|
|
_fail("Pickup collection activated before grace period: %s" % pickup.pickup_data.id)
|
|
return
|
|
spawned_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")
|
|
return
|
|
|
|
print("OK: all 17 guaranteed drops spawned, visible and correctly assigned.")
|
|
quit(0)
|
|
|
|
|
|
func _fail(message: String) -> void:
|
|
push_error("Pickup runtime test: " + message)
|
|
quit(1)
|