spaceship/surface/PlanetSetupHost.gd
Loïc Wisniewski 2f161621c3 #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

60 lines
2.1 KiB
GDScript

class_name PlanetSetupHost
extends Node2D
# Instantiates the contents of a PlanetSetup onto a landed surface: one
# CapturePoint per authored point - registering/restoring conquest progress
# through GameState so re-landing on a partly-taken planet keeps its
# progress - and one enemy per authored spawn.
const CAPTURE_POINT_SCENE: PackedScene = preload("res://surface/CapturePoint.tscn")
const ENEMY_SCENE: PackedScene = preload("res://enemies/Enemy.tscn")
var setup: Resource
func apply_setup(new_setup: Resource) -> void:
setup = new_setup
for child in get_children():
child.queue_free()
if setup == null:
return
GameState.register_capture_points(GameState.planet_id, setup.capture_points.size(),
GameState.planet_definition_id, int(setup.research_point_reward))
for i in range(setup.capture_points.size()):
_add_capture_point(i, setup.capture_points[i])
if _garrison_is_defeated():
return
for spawn in setup.enemy_spawns:
_add_enemy(spawn)
# A conquered planet stays conquered. Its garrison was destroyed to take it,
# so re-landing must not quietly restore it - the capture points already come
# back marked captured, and enemies standing on a planet the player owns read
# as the conquest having been undone.
#
# Guarded on there being capture points to take, not on the conquered flag
# alone: register_capture_points() treats a setup with none as vacuously
# conquered (see PlanetSurfaceController's note on unregistered planets), and
# a setup that authored enemies but no capture points is a garrison nobody
# can ever have beaten. Suppressing those would delete them on first sight.
func _garrison_is_defeated() -> bool:
return not setup.capture_points.is_empty() \
and GameState.is_planet_conquered(GameState.planet_id)
func _add_capture_point(index: int, at: Vector2) -> void:
var point: Node = CAPTURE_POINT_SCENE.instantiate()
point.point_index = index
point.position = at
add_child(point)
if GameState.is_point_captured(GameState.planet_id, index):
point.mark_captured()
func _add_enemy(spawn: Resource) -> void:
var enemy: Node = ENEMY_SCENE.instantiate()
enemy.enemy_id = spawn.enemy_id
enemy.position = spawn.position
add_child(enemy)