spaceship/tests/_capture_points_preview.gd
Loïc Wisniewski 5b2dd77e47 Draw capture points behind fleet vessels (#50)
CapturePoint.gd left z_index at its default 0, the same layer Ship
draws on, so a ship parked inside a ring was partly swallowed by the
ring fill - exactly where the player most needs to see their own
vessels. Set z_index = -1, matching the convention every other world
object already follows (Planet, Rock, Building, Hauler, Transporter,
VesselDelivery).

Verified with a ship placed directly on a capture point in the
preview screenshot, and asserted in test_capture_points.gd.
2026-08-15 22:47:44 +02:00

57 lines
2.4 KiB
GDScript

extends Node2D
# Preloaded by path rather than an `is CapturePoint` check - this preview
# runs through screenshot.sh, which (unlike run_tests.sh) does not run an
# import pass first, so the global class_name cache may not be warm yet.
const CAPTURE_POINT_SCRIPT = preload("res://CapturePoint.gd")
func _ready() -> void:
GameState.planet_name = "Kepler's Rest"
GameState.planet_id = "chunk:3:7"
GameState.planet_definition_id = "rocky"
GameState.surviving_ship_count = 3
GameState.rocks = 128
var surface: Node = load("res://PlanetSurface.tscn").instantiate()
surface.get_node("SurfaceController").fade_duration = 0.0
add_child(surface)
# Zoomed out so all three ~220-radius capture rings fit the frame with
# margin, regardless of wherever the real setup's points happen to sit.
surface.get_node("Camera2D").zoom = Vector2(0.55, 0.55)
var host: Node = surface.get_node("SurfaceFeatures/PlanetSetupHost")
var points: Array = []
for child in host.get_children():
if child.get_script() == CAPTURE_POINT_SCRIPT:
points.append(child)
# Lay the three points out in a compact, clearly-separated triangle for
# the screenshot, rather than the real (far-flung) authored positions.
# Point 0 sits at the origin - exactly where the fleet spawns - so the
# screenshot also proves the #50 z_index fix: the ring must not occlude
# the ships parked on top of it.
var layout: Array = [Vector2(0, 0), Vector2(-300, 150), Vector2(300, -200)]
for i in range(mini(points.size(), layout.size())):
points[i].position = layout[i]
# Show all three states at once: captured, mid-fill, and blocked. Each
# point's own _process() would otherwise immediately recompute state
# from the real (empty, this far from any ship) fleet/enemy proximity
# and overwrite these on the very next frame, so freeze it after setting
# the display state - same technique as freezing enemy.speed for the
# gas bomber screenshot.
if points.size() >= 1:
points[0].mark_captured()
points[0].set_process(false)
GameState.mark_point_captured(GameState.planet_id, points[0].point_index)
if points.size() >= 2:
points[1].state = CAPTURE_POINT_SCRIPT.State.CAPTURING
points[1].progress = 0.55
points[1].queue_redraw()
points[1].set_process(false)
if points.size() >= 3:
points[2].state = CAPTURE_POINT_SCRIPT.State.BLOCKED
points[2].progress = 0.3
points[2].queue_redraw()
points[2].set_process(false)