73 lines
2.5 KiB
GDScript
73 lines
2.5 KiB
GDScript
extends SceneTree
|
|
## Level-isolation test: when the shell loads the Bear's Den, none of the arena level's
|
|
## geometry — crucially its wall/floor colliders and audience — may survive into it.
|
|
## Guards the modular-level contract: switching levels swaps the whole module, it never
|
|
## hides old nodes (hidden colliders still collide). Run:
|
|
## godot --headless --script tests/level_switch_test.gd
|
|
|
|
var _pass := 0
|
|
var _fail := 0
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _ok(c: bool, m: String) -> void:
|
|
if c:
|
|
_pass += 1
|
|
print(" PASS: ", m)
|
|
else:
|
|
_fail += 1
|
|
print(" FAIL: ", m)
|
|
|
|
|
|
func _count_named(node: Node, wanted: String, acc: int = 0) -> int:
|
|
if node.name == wanted:
|
|
acc += 1
|
|
for child: Node in node.get_children():
|
|
acc = _count_named(child, wanted, acc)
|
|
return acc
|
|
|
|
|
|
func _count_type(node: Node, klass: String, acc: int = 0) -> int:
|
|
if node.is_class(klass):
|
|
acc += 1
|
|
for child: Node in node.get_children():
|
|
acc = _count_type(child, klass, acc)
|
|
return acc
|
|
|
|
|
|
func _run() -> void:
|
|
var run: Node = root.get_node("Run")
|
|
run.ensure_run()
|
|
# Force the shell to build the Bear's Den regardless of the generated map.
|
|
run.debug_level_override = run.get_level(&"bear")
|
|
|
|
var scene: Node = load("res://scene.tscn").instantiate()
|
|
root.add_child(scene)
|
|
current_scene = scene
|
|
# Let the shell instance the level and the spawner's deferred spawn run.
|
|
await create_timer(0.8).timeout
|
|
|
|
# Shell survives and hosts exactly one level module.
|
|
var level_root: Node = scene.get_node_or_null("LevelRoot")
|
|
_ok(level_root != null, "shell has a LevelRoot")
|
|
_ok(level_root != null and level_root.get_child_count() == 1, "exactly one level module loaded")
|
|
_ok(not get_nodes_in_group(&"player").is_empty(), "player (shell) present")
|
|
|
|
# The leak we are guarding against: no arena geometry may exist in the bear level.
|
|
_ok(_count_named(scene, "arena_placeholder_v01") == 0, "arena placeholder (+ its wall collider) gone")
|
|
_ok(_count_named(scene, "Arena2") == 0, "arena mesh 'Arena2' gone")
|
|
_ok(_count_named(scene, "PublikNode") == 0, "arena audience gone from bear level")
|
|
|
|
# The bear level brings its own geometry, one floor collider, and its boss.
|
|
_ok(_count_named(scene, "bear_level_arena") == 1, "bear arena mesh present")
|
|
_ok(_count_type(level_root, "StaticBody3D") >= 1, "bear level has its own floor collider")
|
|
|
|
await create_timer(0.4).timeout
|
|
_ok(not get_nodes_in_group(&"bear").is_empty(), "bear boss spawned in bear level")
|
|
|
|
print("Results: %d passed, %d failed" % [_pass, _fail])
|
|
quit(1 if _fail > 0 else 0)
|