WIP checkpoint: PC2: Build a basic playable test level scene
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
extends SceneTree
|
||||
## Headless smoke test for the PC2 test level scene.
|
||||
##
|
||||
## Run with:
|
||||
## godot --headless --path . --script res://scripts/smoke_test_test_level.gd
|
||||
##
|
||||
## Loads the test level scene, asserts:
|
||||
## (a) it loads without error,
|
||||
## (b) it contains a Marker3D named "PlayerSpawn",
|
||||
## (c) PlayerSpawn is positioned >= 1.0 m above the ground top surface.
|
||||
## Exits 0 on success, 1 on failure.
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
_run()
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var level_path: String = "res://scenes/worlds/test_level.tscn"
|
||||
|
||||
# Load the scene file
|
||||
var level_resource: PackedScene = load(level_path)
|
||||
if level_resource == null:
|
||||
printerr("SMOKE RESULT: FAIL — could not load ", level_path)
|
||||
quit(1)
|
||||
return
|
||||
|
||||
print("SMOKE: test_level.tscn loaded successfully")
|
||||
|
||||
# Instantiate the scene root
|
||||
var level_instance: Node3D = level_resource.instantiate() as Node3D
|
||||
if level_instance == null:
|
||||
printerr("SMOKE RESULT: FAIL — could not instantiate ", level_path)
|
||||
quit(1)
|
||||
return
|
||||
|
||||
# Add to tree so find_child works
|
||||
add_child(level_instance)
|
||||
await process_frame
|
||||
|
||||
# (b) Find the PlayerSpawn marker
|
||||
var spawn_marker: Node3D = level_instance.find_child("PlayerSpawn", true, false) as Node3D
|
||||
if spawn_marker == null:
|
||||
printerr("SMOKE RESULT: FAIL — no Marker3D named 'PlayerSpawn' found in test level")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
|
||||
print("SMOKE: found PlayerSpawn at ", spawn_marker.global_position)
|
||||
|
||||
# (c) Verify PlayerSpawn is >= 1.0 m above ground top
|
||||
# The ground top surface is at y = 0 (Ground StaticBody3D centered at y = -0.5
|
||||
# with height 1.0, so top face is at y = 0).
|
||||
var spawn_y: float = spawn_marker.global_position.y
|
||||
if spawn_y < 1.0:
|
||||
printerr("SMOKE RESULT: FAIL — PlayerSpawn y = ", spawn_y,
|
||||
" is below the required minimum of 1.0 m above ground top (y=0)")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
|
||||
print("SMOKE: PlayerSpawn y = ", spawn_y, " >= 1.0 m — PASS")
|
||||
|
||||
# Additional check: verify Ground StaticBody3D exists
|
||||
var ground: StaticBody3D = level_instance.find_child("Ground", true, false) as StaticBody3D
|
||||
if ground == null:
|
||||
printerr("SMOKE RESULT: FAIL — no StaticBody3D named 'Ground' found")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
|
||||
print("SMOKE: found Ground StaticBody3D")
|
||||
|
||||
# Verify Ground top face is at y = 0
|
||||
var ground_shape: CollisionShape3D = ground.find_child("CollisionShape3D", true, false) as CollisionShape3D
|
||||
if ground_shape != null and ground_shape.shape is BoxShape3D:
|
||||
var box_shape: BoxShape3D = ground_shape.shape as BoxShape3D
|
||||
var ground_top: float = ground.global_position.y + box_shape.size.y / 2.0
|
||||
if abs(ground_top - 0.0) > 0.01:
|
||||
printerr("SMOKE RESULT: FAIL — Ground top face at y = ", ground_top, " expected ~0.0")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
print("SMOKE: Ground top face at y = ", ground_top, " — PASS")
|
||||
|
||||
# Verify props exist (3-5 StaticBody3D children under Props node)
|
||||
var props_node: Node3D = level_instance.find_child("Props", true, false) as Node3D
|
||||
if props_node != null:
|
||||
var prop_count: int = 0
|
||||
for child in props_node.get_children():
|
||||
if child is StaticBody3D:
|
||||
prop_count += 1
|
||||
if prop_count < 3:
|
||||
printerr("SMOKE RESULT: FAIL — only ", prop_count, " props found, need >= 3")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
print("SMOKE: found ", prop_count, " props — PASS")
|
||||
else:
|
||||
printerr("SMOKE RESULT: FAIL — no 'Props' Node3D found")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
|
||||
# Verify lighting exists
|
||||
var sun: DirectionalLight3D = level_instance.find_child("Sun", true, false) as DirectionalLight3D
|
||||
if sun == null:
|
||||
printerr("SMOKE RESULT: FAIL — no DirectionalLight3D named 'Sun' found")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
print("SMOKE: found Sun DirectionalLight3D")
|
||||
|
||||
var env: WorldEnvironment = level_instance.find_child("Environment", true, false) as WorldEnvironment
|
||||
if env == null:
|
||||
printerr("SMOKE RESULT: FAIL — no WorldEnvironment named 'Environment' found")
|
||||
level_instance.queue_free()
|
||||
quit(1)
|
||||
return
|
||||
print("SMOKE: found WorldEnvironment")
|
||||
|
||||
# All checks passed
|
||||
print("SMOKE RESULT: PASS")
|
||||
level_instance.queue_free()
|
||||
quit(0)
|
||||
Reference in New Issue
Block a user