From c4dc0891b0c6db07e26917c97b4e3fe19f005a21 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Sun, 18 Aug 2024 17:15:46 +0100 Subject: [PATCH] Implicitly infer systems in galaxy Resolves #34. @skip-notify --- CONTRIBUTING.md | 5 ++--- galaxy/galaxy.gd | 22 +++++++++++++--------- galaxy/main_galaxy.tres | 12 +----------- script/claude.py | 4 +--- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 452de254..3ffbbffb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,9 +14,8 @@ To introduce a new star system: 1. Create a [`StarSystem`](galaxy/star_system/star_system.gd) resource in [galaxy/star_system/star_systems/](galaxy/star_system/star_systems/), and fill in its properties, using the documentation shown in the editor as a guide. 2. For any star system you have listed as a `connection` of your _new_ system, you must also open up _their_ `StarSystem` resources, and add your new system as a `connection` of them, so they are connected bidirectionally. -3. Add your system to `main_galaxy.tres`, the main [`Galaxy`](galaxy/galaxy.gd) resource. This ensures that your new system will properly show up in the galaxy map. -4. Create a new scene in [galaxy/star_system/scenes/](galaxy/star_system/scenes/) with a root type of [`StarSystemInstance`](galaxy/star_system/star_system_instance.gd), and connect its `star_system` property back to the `StarSystem` resource you created in step 1. -5. Set the `scene_path` property of your `StarSystem` resource to the file path of the new scene. +3. Create a new scene in [galaxy/star_system/scenes/](galaxy/star_system/scenes/) with a root type of [`StarSystemInstance`](galaxy/star_system/star_system_instance.gd), and connect its `star_system` property back to the `StarSystem` resource you created in step 1. +4. Set the `scene_path` property of your `StarSystem` resource to the file path of the new scene. Your new scene file is now the canvas upon which to create your star system! You can add the following types of entities into your scene to populate the system. All of them can be moved around and rotated as you see fit. diff --git a/galaxy/galaxy.gd b/galaxy/galaxy.gd index d6ad1ee0..22847b04 100644 --- a/galaxy/galaxy.gd +++ b/galaxy/galaxy.gd @@ -5,25 +5,29 @@ class_name Galaxy ## ## Only one galaxy is playable at any given time, but testing or add-on content may want to swap out the default galaxy. -## A list of all systems in the galaxy. -@export var systems: Array[StarSystem] +## Dynamically loaded systems in the galaxy. +var systems: Array[StarSystem] = [] ## A list of all planets in the galaxy. var planets: Array = [] -func _init() -> void: - self._connect_backref.call_deferred() +## The directory where all star system resources are stored. +const _STAR_SYSTEMS_DIRECTORY = "res://galaxy/star_system/star_systems" - for system in self.systems: - self.planets.append_array(system.planets) +func _init() -> void: + var files := DirAccess.get_files_at(_STAR_SYSTEMS_DIRECTORY) + for file in files: + if not file.ends_with(".tres"): + continue -func _connect_backref() -> void: - for system in self.systems: + var system: StarSystem = load("%s/%s" % [_STAR_SYSTEMS_DIRECTORY, file]) system.galaxy = weakref(self) + self.systems.append(system) + self.planets.append_array(system.planets) ## Looks up a system by name. func get_system(name: StringName) -> StarSystem: - for system in systems: + for system in self.systems: if system.name == name: return system diff --git a/galaxy/main_galaxy.tres b/galaxy/main_galaxy.tres index fff460be..0501b936 100644 --- a/galaxy/main_galaxy.tres +++ b/galaxy/main_galaxy.tres @@ -1,16 +1,6 @@ -[gd_resource type="Resource" script_class="Galaxy" load_steps=11 format=3 uid="uid://bcva4l4cpt70c"] +[gd_resource type="Resource" script_class="Galaxy" load_steps=2 format=3 uid="uid://bcva4l4cpt70c"] [ext_resource type="Script" path="res://galaxy/galaxy.gd" id="1_bckai"] -[ext_resource type="Resource" uid="uid://cew4x137v08q" path="res://galaxy/star_system/star_systems/sol.tres" id="2_va8e4"] -[ext_resource type="Resource" uid="uid://cs1x8gyt6a7kw" path="res://galaxy/star_system/star_systems/alpha_centauri.tres" id="3_ulruw"] -[ext_resource type="Resource" uid="uid://shiglva7yxl0" path="res://galaxy/star_system/star_systems/barnard's_star.tres" id="4_jkjw5"] -[ext_resource type="Resource" uid="uid://di0bekcy5g0ya" path="res://galaxy/star_system/star_systems/wolf_359.tres" id="5_8a1bp"] -[ext_resource type="Resource" uid="uid://clcig3aieyop5" path="res://galaxy/star_system/star_systems/sirius.tres" id="6_jci7t"] -[ext_resource type="Resource" uid="uid://bowucldo27rjd" path="res://galaxy/star_system/star_systems/zephyria.tres" id="7_puhoc"] -[ext_resource type="Resource" uid="uid://cu1wn7ldbgeej" path="res://galaxy/star_system/star_systems/thalassa.tres" id="8_4yki3"] -[ext_resource type="Resource" uid="uid://ku5qjeo4jlkt" path="res://galaxy/star_system/star_systems/nova_lumina.tres" id="9_qqkio"] -[ext_resource type="Resource" uid="uid://nbm8is7uln37" path="res://galaxy/star_system/star_systems/helios.tres" id="10_fsj5o"] [resource] script = ExtResource("1_bckai") -systems = Array[Resource("res://galaxy/star_system/star_system.gd")]([ExtResource("2_va8e4"), ExtResource("3_ulruw"), ExtResource("4_jkjw5"), ExtResource("5_8a1bp"), ExtResource("6_jci7t"), ExtResource("7_puhoc"), ExtResource("8_4yki3"), ExtResource("9_qqkio"), ExtResource("10_fsj5o")]) diff --git a/script/claude.py b/script/claude.py index cc4214b0..240162ab 100755 --- a/script/claude.py +++ b/script/claude.py @@ -37,9 +37,7 @@ CONTEXT_PATHS = [ "actors/**/*.gd", "addons/market_editor/**/*.gd", - "galaxy/*.gd", - "galaxy/main_galaxy.tres", - "galaxy/star_system/**/*.gd", + "galaxy/**/*.gd", "galaxy/star_system/star_systems/*.tres", "mechanics/**/*.gd", "mechanics/**/*.tres",