Files
millimeters-of-aluminum/scripts/singletons/game_manager.gd

50 lines
1.5 KiB
GDScript

# GameManager.gd
extends Node
# This variable will hold the reference to the currently active star system.
var current_star_system : StarSystemGenerator = null
var ships_in_system : Array[OrbitalBody2D]
# Any scene that generates a star system will call this function to register itself.
func register_star_system(system_node):
current_star_system = system_node
print("GameManager: Star system registered.")
func register_ship(ship: Node2D):
if not ships_in_system.has(ship):
ships_in_system.append(ship)
# A helper function for easily accessing the system's data.
func get_system_data():
if current_star_system:
return current_star_system.get_system_data()
return null
func get_system_bodies() -> Array[CelestialBody]:
if current_star_system:
return current_star_system.get_all_bodies()
return []
func get_all_trackable_bodies() -> Array:
var all_bodies: Array = []
if current_star_system:
# First, get all the celestial bodies (planets, moons, etc.)
var system_data = current_star_system.get_system_data()
if system_data:
all_bodies.append_array(system_data.all_bodies())
# Next, add all registered ships to the list.
all_bodies.append_array(ships_in_system)
return all_bodies
# Traverses up the scene tree to find the first parent that is a Spaceship.
func _find_parent_ship(node: Node) -> Spaceship:
var current_node = node.get_parent()
while is_instance_valid(current_node):
if current_node is Spaceship:
return current_node
current_node = current_node.get_parent()
return null # Return null if no spaceship parent was found