spaceship/tests/test_planet_spawning.gd
Loïc Wisniewski 85814ce88c Initial commit: SpaceshipTest, a top-down space RTS in Godot 4.7.1
A fleet of neon-outlined ships explores a procedurally generated, seeded
infinite world: tap/joystick steering, pinch zoom, formation pivoting,
planet landings, an ore economy with extractors and haulers, and player
built structures (mothership, ship crafter, command centre).

All art is hand-drawn with draw_* calls rather than textures, and the
backgrounds are camera-relative shaders so they stay precise at large
world coordinates.

Includes a 35-test headless suite (tests/run_tests.sh) plus screenshot
tooling that renders real frames through Xvfb and Mesa softpipe, since
--headless has no GPU.

Excluded from version control: .godot/ (import cache, and it holds
export credentials), builds/, android/build/ and packaged APKs - all
regenerable, and ~325 MB combined.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 18:41:58 +02:00

105 lines
2.9 KiB
GDScript

extends SceneTree
# Headless gameplay test: run with
# godot --headless -s res://tests/test_planet_spawning.gd
# Verifies PlanetField spawns a planet once the fleet enters a chunk where
# WorldGen says one belongs, and despawns it again once the fleet moves
# far enough away - mirrors test_asteroid_spawning.gd's lifecycle check.
var main_scene: Node
var fleet: Node
var planet_field: Node
var target_chunk: Vector2i
var spawned_planet: Node = null
var elapsed: float = 0.0
var stage: int = 0
var ok: bool = true
func _initialize() -> void:
var found: bool = false
for x in range(-15, 15):
for y in range(-15, 15):
var chunk: Vector2i = Vector2i(x, y)
if WorldGen.has_planet_at_chunk(chunk):
target_chunk = chunk
found = true
break
if found:
break
if not found:
print("FAIL: could not find any chunk with a planet to test with")
quit(1)
return
var packed: PackedScene = load("res://Main.tscn")
main_scene = packed.instantiate()
root.add_child(main_scene)
fleet = main_scene.get_node("Fleet")
planet_field = main_scene.get_node("PlanetField")
func _process(delta: float) -> bool:
elapsed += delta
match stage:
0:
var target_pos: Vector2 = WorldGen.chunk_origin(target_chunk) + Vector2.ONE * WorldGen.CHUNK_SIZE * 0.5
for ship in fleet.ships:
ship.position = target_pos
fleet.move_to(target_pos)
elapsed = 0.0
stage = 1
return false
1:
if elapsed < planet_field.check_interval + 0.1:
return false
_check_spawned()
elapsed = 0.0
stage = 2
return false
2:
var far_pos: Vector2 = WorldGen.chunk_origin(target_chunk) + Vector2(50000, 50000)
for ship in fleet.ships:
ship.position = far_pos
fleet.move_to(far_pos)
elapsed = 0.0
stage = 3
return false
3:
if elapsed < planet_field.check_interval + 0.1:
return false
_check_despawned()
return true
return false
func _check_spawned() -> void:
var has_chunk: bool = planet_field.populated_chunks.has(target_chunk)
if not has_chunk:
ok = false
print("FAIL: target_chunk %s not populated after check_interval" % target_chunk)
return
var planets: Array = planet_field.populated_chunks[target_chunk]
spawned_planet = planets[0] if planets.size() > 0 else null
var count_ok: bool = planets.size() == 1
var name_ok: bool = spawned_planet != null and spawned_planet.planet_name != ""
ok = ok and count_ok and name_ok
print("spawned_count=%d name_ok=%s planet_name=%s" % [planets.size(), name_ok, spawned_planet.planet_name if spawned_planet else "<none>"])
func _check_despawned() -> void:
var chunk_removed: bool = not planet_field.populated_chunks.has(target_chunk)
var freed: bool = spawned_planet == null or not is_instance_valid(spawned_planet)
ok = ok and chunk_removed and freed
print("chunk_removed=%s freed=%s" % [chunk_removed, freed])
if ok:
print("TEST_PLANET_SPAWNING: PASS")
quit(0)
else:
print("TEST_PLANET_SPAWNING: FAIL")
quit(1)