Skip to content

Commit

Permalink
Implicitly infer systems in galaxy
Browse files Browse the repository at this point in the history
Resolves #34.

@skip-notify
  • Loading branch information
jspahrsummers committed Aug 18, 2024
1 parent 69fb290 commit c4dc089
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
22 changes: 13 additions & 9 deletions galaxy/galaxy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 1 addition & 11 deletions galaxy/main_galaxy.tres
Original file line number Diff line number Diff line change
@@ -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")])
4 changes: 1 addition & 3 deletions script/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c4dc089

Please sign in to comment.