spaceship/tests/_turret_vs_chaser_preview.gd

60 lines
1.8 KiB
GDScript3
Raw Permalink Normal View History

Turret vessel spawner enemy (#52) New EnemySpawnerComponent.gd (capability_id "spawner"): continuously instantiates another enemy type beside its host at a fixed interval, capped at max_alive concurrently, refilling as spawns die. Spawned enemies are parented under the SPAWNER'S OWN PARENT rather than the spawner itself, so they are siblings, not descendants - killing the spawner can't free them, and a surface-hosted spawner (under PlanetSetupHost) keeps its spawns under the same host instead of leaking them to a hardcoded path, the same hazard #44 already closed for pursuit/standoff/ranged-weapon components. TurretSpawnerEnemyDefinition.tres: stationary (speed 0, no pursuit or standoff component), max_hp 20 (~7x a chaser), a bulky octagon hull, and its own acid-green glow distinct from chaser/sniper/artillery. Registered in EnemyDefinitions.ORDER/DEFINITIONS - the map editor palette (#48) picks it up with no editor code change. Tests: new tests/test_turret_spawner_enemy.gd covers registration and real definition defaults, no spawns without a fleet, spawning capped at max_alive, a dead spawn's slot refilling, never moving, surviving 19 damage and dying on the 20th, and its spawns surviving its death with their pursuit component intact. Screenshot beside a chaser confirms the two read as visually distinct enemies. Full suite: 79/79. Repo notes for the next agent, confirmed empirically this session: - A node's set_process(false) call made before it has fully finished entering the tree doesn't reliably stick (already documented in tests/test_planet_atmosphere_transition.gd, and it bit this test too): BuildController._check_fleet_wipe() kept rebuilding a ship during an intended "empty fleet" test window even after disabling it in _initialize(). Do it in _process()'s first real tick instead, once _ready() cascades are confirmed complete. - Overriding an @export interval (like spawn_interval) on an already-running component does NOT reset its own in-progress countdown timer - only changes what it resets TO on its next expiry. If the countdown already started at the OLD value before your override lands, reset the timer variable itself too, or the first real interval after the override silently uses the stale value. - A capped spawner's freed-slot refill can land within a couple of frames once its interval is short - don't assert on an intermediate "just dropped by one" count that a fast interval can blow straight through before your next check runs. Assert the net effect instead (the specific killed instance is gone AND a replacement filled the slot) rather than an exact mid-transition snapshot. 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 09:43:44 +02:00
extends Node2D
# Preview, not a test - #52's "visually distinguishable from a chaser"
# acceptance criterion. Same setup shape as _sniper_vs_chaser_preview.gd -
# see that file's header note for why setup is deferred to the first
# _process() tick and the tree gets paused once everything is placed.
#
# bash tests/screenshot.sh res://tests/_turret_vs_chaser_preview.tscn /tmp/turret.png 20 720x1280
var main: Node
var setup_done: bool = false
func _ready() -> void:
GameState.buildings.clear()
GameState.extractors.clear()
GameState.transporters.clear()
#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
main = load("res://world/Main.tscn").instantiate()
Turret vessel spawner enemy (#52) New EnemySpawnerComponent.gd (capability_id "spawner"): continuously instantiates another enemy type beside its host at a fixed interval, capped at max_alive concurrently, refilling as spawns die. Spawned enemies are parented under the SPAWNER'S OWN PARENT rather than the spawner itself, so they are siblings, not descendants - killing the spawner can't free them, and a surface-hosted spawner (under PlanetSetupHost) keeps its spawns under the same host instead of leaking them to a hardcoded path, the same hazard #44 already closed for pursuit/standoff/ranged-weapon components. TurretSpawnerEnemyDefinition.tres: stationary (speed 0, no pursuit or standoff component), max_hp 20 (~7x a chaser), a bulky octagon hull, and its own acid-green glow distinct from chaser/sniper/artillery. Registered in EnemyDefinitions.ORDER/DEFINITIONS - the map editor palette (#48) picks it up with no editor code change. Tests: new tests/test_turret_spawner_enemy.gd covers registration and real definition defaults, no spawns without a fleet, spawning capped at max_alive, a dead spawn's slot refilling, never moving, surviving 19 damage and dying on the 20th, and its spawns surviving its death with their pursuit component intact. Screenshot beside a chaser confirms the two read as visually distinct enemies. Full suite: 79/79. Repo notes for the next agent, confirmed empirically this session: - A node's set_process(false) call made before it has fully finished entering the tree doesn't reliably stick (already documented in tests/test_planet_atmosphere_transition.gd, and it bit this test too): BuildController._check_fleet_wipe() kept rebuilding a ship during an intended "empty fleet" test window even after disabling it in _initialize(). Do it in _process()'s first real tick instead, once _ready() cascades are confirmed complete. - Overriding an @export interval (like spawn_interval) on an already-running component does NOT reset its own in-progress countdown timer - only changes what it resets TO on its next expiry. If the countdown already started at the OLD value before your override lands, reset the timer variable itself too, or the first real interval after the override silently uses the stale value. - A capped spawner's freed-slot refill can land within a couple of frames once its interval is short - don't assert on an intermediate "just dropped by one" count that a fast interval can blow straight through before your next check runs. Assert the net effect instead (the specific killed instance is gone AND a replacement filled the slot) rather than an exact mid-transition snapshot. 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 09:43:44 +02:00
add_child(main)
main.get_node("BackgroundLayer").visible = false
main.get_node("AsteroidField").visible = false
main.get_node("PlanetField").visible = false
main.get_node("BuildingField").visible = false
main.get_node("EnemySpawner").set_process(false)
main.get_node("AsteroidField").set_process(false)
func _process(_delta: float) -> void:
if setup_done:
return
setup_done = true
var fleet: Node = main.get_node("Fleet")
for ship in fleet.ships:
if is_instance_valid(ship):
ship.set_physics_process(false)
fleet.spawn_ships(0, Vector2.ZERO)
for ship in fleet.ships:
if is_instance_valid(ship):
ship.set_physics_process(false)
ship.queue_free()
fleet.ships.clear()
for projectile in get_tree().get_nodes_in_group("player_projectiles"):
projectile.queue_free()
#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 chaser: Node = load("res://enemies/Enemy.tscn").instantiate()
Turret vessel spawner enemy (#52) New EnemySpawnerComponent.gd (capability_id "spawner"): continuously instantiates another enemy type beside its host at a fixed interval, capped at max_alive concurrently, refilling as spawns die. Spawned enemies are parented under the SPAWNER'S OWN PARENT rather than the spawner itself, so they are siblings, not descendants - killing the spawner can't free them, and a surface-hosted spawner (under PlanetSetupHost) keeps its spawns under the same host instead of leaking them to a hardcoded path, the same hazard #44 already closed for pursuit/standoff/ranged-weapon components. TurretSpawnerEnemyDefinition.tres: stationary (speed 0, no pursuit or standoff component), max_hp 20 (~7x a chaser), a bulky octagon hull, and its own acid-green glow distinct from chaser/sniper/artillery. Registered in EnemyDefinitions.ORDER/DEFINITIONS - the map editor palette (#48) picks it up with no editor code change. Tests: new tests/test_turret_spawner_enemy.gd covers registration and real definition defaults, no spawns without a fleet, spawning capped at max_alive, a dead spawn's slot refilling, never moving, surviving 19 damage and dying on the 20th, and its spawns surviving its death with their pursuit component intact. Screenshot beside a chaser confirms the two read as visually distinct enemies. Full suite: 79/79. Repo notes for the next agent, confirmed empirically this session: - A node's set_process(false) call made before it has fully finished entering the tree doesn't reliably stick (already documented in tests/test_planet_atmosphere_transition.gd, and it bit this test too): BuildController._check_fleet_wipe() kept rebuilding a ship during an intended "empty fleet" test window even after disabling it in _initialize(). Do it in _process()'s first real tick instead, once _ready() cascades are confirmed complete. - Overriding an @export interval (like spawn_interval) on an already-running component does NOT reset its own in-progress countdown timer - only changes what it resets TO on its next expiry. If the countdown already started at the OLD value before your override lands, reset the timer variable itself too, or the first real interval after the override silently uses the stale value. - A capped spawner's freed-slot refill can land within a couple of frames once its interval is short - don't assert on an intermediate "just dropped by one" count that a fast interval can blow straight through before your next check runs. Assert the net effect instead (the specific killed instance is gone AND a replacement filled the slot) rather than an exact mid-transition snapshot. 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 09:43:44 +02:00
chaser.enemy_id = "chaser"
chaser.position = Vector2(-160, -80)
main.add_child(chaser)
chaser.speed = 0.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 turret: Node = load("res://enemies/Enemy.tscn").instantiate()
Turret vessel spawner enemy (#52) New EnemySpawnerComponent.gd (capability_id "spawner"): continuously instantiates another enemy type beside its host at a fixed interval, capped at max_alive concurrently, refilling as spawns die. Spawned enemies are parented under the SPAWNER'S OWN PARENT rather than the spawner itself, so they are siblings, not descendants - killing the spawner can't free them, and a surface-hosted spawner (under PlanetSetupHost) keeps its spawns under the same host instead of leaking them to a hardcoded path, the same hazard #44 already closed for pursuit/standoff/ranged-weapon components. TurretSpawnerEnemyDefinition.tres: stationary (speed 0, no pursuit or standoff component), max_hp 20 (~7x a chaser), a bulky octagon hull, and its own acid-green glow distinct from chaser/sniper/artillery. Registered in EnemyDefinitions.ORDER/DEFINITIONS - the map editor palette (#48) picks it up with no editor code change. Tests: new tests/test_turret_spawner_enemy.gd covers registration and real definition defaults, no spawns without a fleet, spawning capped at max_alive, a dead spawn's slot refilling, never moving, surviving 19 damage and dying on the 20th, and its spawns surviving its death with their pursuit component intact. Screenshot beside a chaser confirms the two read as visually distinct enemies. Full suite: 79/79. Repo notes for the next agent, confirmed empirically this session: - A node's set_process(false) call made before it has fully finished entering the tree doesn't reliably stick (already documented in tests/test_planet_atmosphere_transition.gd, and it bit this test too): BuildController._check_fleet_wipe() kept rebuilding a ship during an intended "empty fleet" test window even after disabling it in _initialize(). Do it in _process()'s first real tick instead, once _ready() cascades are confirmed complete. - Overriding an @export interval (like spawn_interval) on an already-running component does NOT reset its own in-progress countdown timer - only changes what it resets TO on its next expiry. If the countdown already started at the OLD value before your override lands, reset the timer variable itself too, or the first real interval after the override silently uses the stale value. - A capped spawner's freed-slot refill can land within a couple of frames once its interval is short - don't assert on an intermediate "just dropped by one" count that a fast interval can blow straight through before your next check runs. Assert the net effect instead (the specific killed instance is gone AND a replacement filled the slot) rather than an exact mid-transition snapshot. 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 09:43:44 +02:00
turret.enemy_id = "turret_spawner"
turret.position = Vector2(160, -80)
main.add_child(turret)
var camera: Camera2D = main.get_node("Camera2D")
camera.zoom = Vector2(1.4, 1.4)
get_tree().paused = true