spaceship/PlanetSetupHost.gd
2026-08-16 20:14:29 +02:00

43 lines
1.3 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://CapturePoint.tscn")
const ENEMY_SCENE: PackedScene = preload("res://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)
for i in range(setup.capture_points.size()):
_add_capture_point(i, setup.capture_points[i])
for spawn in setup.enemy_spawns:
_add_enemy(spawn)
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)