spaceship/PlanetSurfaceController.gd
Loïc Wisniewski c4e2ee7178 Add capture points and the planet conquest loop (#43)
CapturePoint tracks neutral/blocked/capturing/captured state by polling
proximity each frame (a ship in capture_radius, no enemy within
enemy_clear_radius), draining gradually rather than resetting when
interrupted, and calling GameState.mark_point_captured() on completion.
PlanetSetupHost now instantiates the real CapturePoint scene per
authored point (restoring already-captured state immediately on
re-landing) and spawns each setup's authored enemies, replacing the
placeholder markers from #42. CaptureLabel is a small self-polling HUD
(same convention as ResourceCounter) showing "CAPTURED n/m" or
"CONQUERED" with a one-shot fade on completion, themed per surface
profile alongside the existing bank/fleet captions.

test_planet_atmosphere_transition.gd's "no enemies on a landed
surface" assumption no longer holds now that setups can place guard
enemies by design - narrowed the check to what it actually needs to
prove: no space-side EnemySpawner/AsteroidField node leaks across the
scene swap.

Part of the #40 conquest-mechanic breakdown.
2026-08-15 21:22:10 +02:00

82 lines
3.5 KiB
GDScript

extends Node2D
const SURFACE_PROFILES = preload("res://PlanetSurfaceProfiles.gd")
const PLANET_DEFINITIONS = preload("res://PlanetDefinitions.gd")
const PLANET_SETUPS = preload("res://PlanetSetups.gd")
const SETUP_HOST_SCENE: PackedScene = preload("res://PlanetSetupHost.tscn")
# Bootstraps the surviving fleet, including each vessel type, on this scene's
# own startup (from GameState, since this is a fresh scene tree - nothing here
# carries over automatically) and handles the always-available exit prompt that
# fades back out to Main.tscn, restoring the fleet at wherever it left
# space from.
@export var fade_duration: float = 0.4
@onready var fleet: Node2D = get_node("../Fleet")
@onready var camera: Camera2D = get_node("../Camera2D")
@onready var planet_name_label: Label = get_node("../UI/PlanetNameLabel")
@onready var exit_button: IconButton = get_node("../UI/ExitButton")
@onready var fade_rect: ColorRect = get_node("../FadeOverlay/FadeRect")
@onready var background: ColorRect = get_node("../BackgroundLayer/LunarBackground")
@onready var feature_host: Node2D = get_node("../SurfaceFeatures")
var transitioning: bool = false
func _ready() -> void:
var planet_definition: Resource = PLANET_DEFINITIONS.get_definition(GameState.planet_definition_id)
_compose_surface(SURFACE_PROFILES.get_profile(planet_definition.surface_profile_id))
fleet.spawn_ships(GameState.surviving_ship_count, Vector2.ZERO,
GameState.surviving_vessel_types)
camera.position = Vector2.ZERO
camera.zoom = Vector2(GameState.return_camera_zoom, GameState.return_camera_zoom)
planet_name_label.text = GameState.planet_name
exit_button.pressed.connect(_on_exit_pressed)
fade_rect.color.a = 1.0
var tween: Tween = create_tween()
tween.tween_property(fade_rect, "color:a", 0.0, fade_duration)
func _compose_surface(profile: Resource) -> void:
var atmosphere: ShaderMaterial = background.material
atmosphere.set_shader_parameter("base_color", profile.base_color)
atmosphere.set_shader_parameter("crater_color", profile.crater_color)
atmosphere.set_shader_parameter("highlight_color", profile.highlight_color)
for caption_path in ["../UI/BankCaption", "../UI/FleetCaption", "../UI/CaptureLabel"]:
var caption: Label = get_node(caption_path)
caption.add_theme_color_override("font_color", profile.caption_color)
caption.add_theme_color_override("font_outline_color", profile.caption_outline_color)
if profile.features_scene != null:
var features: Node = profile.features_scene.instantiate()
feature_host.add_child(features)
var setup: Resource = PLANET_SETUPS.setup_for_planet(GameState.planet_id, profile.profile_id)
if setup != null:
# Untyped on purpose: a static PlanetSetupHost annotation here would
# need the global class_name cache to already know about it, which
# is only true after an editor/import pass has run (see #31/#35's
# load-order notes) - a plain Node reference plus duck-typed
# apply_setup() sidesteps that entirely, same as BuildingDefinitions
# and VesselDefinitions already do for their own resource types.
var setup_host: Node = SETUP_HOST_SCENE.instantiate()
feature_host.add_child(setup_host)
setup_host.apply_setup(setup)
func _on_exit_pressed() -> void:
if transitioning:
return
transitioning = true
GameState.surviving_ship_count = fleet.ships.size()
GameState.surviving_vessel_types = fleet.vessel_types()
var tween: Tween = create_tween()
tween.tween_property(fade_rect, "color:a", 1.0, fade_duration)
tween.tween_callback(_return_to_space)
func _return_to_space() -> void:
get_tree().change_scene_to_file("res://Main.tscn")