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)