spaceship/tests/test_asteroid_ship_collision.gd

72 lines
2.2 KiB
GDScript3
Raw Normal View History

extends SceneTree
# Headless gameplay test: run with
# godot --headless -s res://tests/test_asteroid_ship_collision.gd
# Verifies that a ship touching an asteroid destroys BOTH the ship (removed
# from the fleet) and the asteroid itself (mutual destruction), each
# spawning its own coherent explosion VFX: light-burst blue for the ship,
# debris brown for the asteroid.
const CHECK_DELAY: float = 0.05
var main_scene: Node
var fleet: Node
var target_ship: Node
var asteroid: Node2D
var elapsed: float = 0.0
var stage: int = 0
func _initialize() -> void:
#84: move 215 root files into a folder hierarchy Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
var packed: PackedScene = load("res://world/Main.tscn")
main_scene = packed.instantiate()
root.add_child(main_scene)
fleet = main_scene.get_node("Fleet")
func _process(delta: float) -> bool:
elapsed += delta
match stage:
0:
# Wait one tick so Fleet._ready() has run and fleet.ships is
# populated before we grab a ship reference.
target_ship = fleet.ships[0]
#84: move 215 root files into a folder hierarchy Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
var asteroid_scene: PackedScene = load("res://world/Asteroid.tscn")
asteroid = asteroid_scene.instantiate()
asteroid.position = target_ship.position
asteroid.velocity = Vector2.ZERO
main_scene.add_child(asteroid)
stage = 1
elapsed = 0.0
return false
1:
if elapsed < CHECK_DELAY:
return false
_check_results()
return true
return false
func _check_results() -> void:
var ship_destroyed: bool = not is_instance_valid(target_ship)
var ship_removed_from_fleet: bool = fleet.ships.find(target_ship) == -1
var asteroid_destroyed: bool = not is_instance_valid(asteroid)
var ship_vfx_ok: bool = false
var asteroid_vfx_ok: bool = false
for child in root.get_children():
if child is ShipExplosionVFX:
ship_vfx_ok = true
elif child is AsteroidExplosionVFX:
asteroid_vfx_ok = true
print("ship_destroyed=%s ship_removed_from_fleet=%s asteroid_destroyed=%s ship_vfx_ok=%s asteroid_vfx_ok=%s" % [
ship_destroyed, ship_removed_from_fleet, asteroid_destroyed, ship_vfx_ok, asteroid_vfx_ok
])
if ship_destroyed and ship_removed_from_fleet and asteroid_destroyed and ship_vfx_ok and asteroid_vfx_ok:
print("TEST_ASTEROID_SHIP_COLLISION: PASS")
quit(0)
else:
print("TEST_ASTEROID_SHIP_COLLISION: FAIL")
quit(1)