Skip to content

Commit

Permalink
Docstrings for all the galaxy map stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 1, 2024
1 parent 5184211 commit 9f880d3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
13 changes: 12 additions & 1 deletion galaxy/galaxy_map/galaxy_map.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
extends Node3D

## Presents the in-game galaxy map, showing all star systems.

@export var hyperspace_controller: HyperspaceController

## The galaxy to display.
@export var galaxy: Galaxy

## A scene used to represent star system nodes in the map.
@export var galaxy_map_system: PackedScene

## A scene used to represent hyperlane connections (edges) between star system nodes in the map.
@export var galaxy_map_hyperlane: PackedScene
@export var hyperspace_controller: HyperspaceController

## The camera observing the 3D galaxy.
@export var camera: GalaxyMapCamera

## Maps from each [member StarSystem.name] to the [GalaxyMapSystem] used to represent it.
var _system_nodes: Dictionary = {}

func _ready() -> void:
Expand Down
24 changes: 23 additions & 1 deletion galaxy/galaxy_map/galaxy_map_camera.gd
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
extends Camera3D
class_name GalaxyMapCamera

## A movable camera used to view the 3D galaxy map.
##
## The user can zoom the camera, and rotate around a sphere centered on a particular point (e.g., a star system).

## The point that the camera should be focused on.
##
## No matter how it is zoomed or rotated, the camera will keep the center of its frustum pointed at this position.
@export var center: Vector3:
get:
return self._center
set(value):
self._center = value
self._update_camera_position()

## The radius of the sphere along which the camera should move, when rotated.
##
## Increasing this value zooms out the camera, while decreasing it zooms in.
@export var radius: float = 10.0

## The minimum radius the camera is allowed to zoom in to.
@export var min_radius: float = 5.0

## The maximum radius the camera is allowed to zoom out to.
@export var max_radius: float = 20.0

## How much relative mouse motion should translate into camera rotation.
@export var mouse_sensitivity: float = 0.005
@export var zoom_sensitivity: float = 0.5

## How much the camera should zoom in and out, per step, when using a scroll wheel.
@export var zoom_sensitivity: float = 1

var _center: Vector3 = Vector3.ZERO

## How far left or right the camera has rotated around the center point.
var _theta: float = 0.0

## How far up or down the camera is tilted.
var _phi: float = PI / 4 # start at 45 degree inclination

func _ready():
Expand Down
22 changes: 22 additions & 0 deletions galaxy/galaxy_map/galaxy_map_hyperlane.gd
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
extends StaticBody3D
class_name GalaxyMapHyperlane

## Represents a hyperspace connection between two star systems (an edge) in the galaxy map.
##
## Although it is not apparent visually, this is a [i]unidirectional[/i] connection. Star systems will generally have bidirectional connections, so the galaxy map will actually superimpose two [GalaxyMapHyperlane]s on top of one another, one for each direction. In future, if unidirectional connections become a useful game mechanic, we may want to create a visual distinction between each direction of hyperlane.

## The position of the origin system, in galaxy space.
@export var starting_position: Vector3

## The position of the destination system, in galaxy space.
@export var ending_position: Vector3

## The mesh controlling this hyperlane's appearance.
##
## This is expected to have a [CylinderMesh] attached.
@export var mesh: MeshInstance3D

## The shape defining the clickable region of this hyperlane.
##
## This is expected to have a [CylinderShape3D] attached.
@export var collision_shape: CollisionShape3D

## When visible, renders the name of this edge, which can be helpful to identify if specific connections are not rendered correctly.
@export var debugging_label: Label3D

## The radius of the [GalaxySystemNode]s that will appear at either end of this edge.
##
## This is used to ensure that the hyperlane's collider (for object picking) does not obstruct the nodes' own colliders.
@export var node_radius: float

## Fires when this hyperlane is clicked.
signal clicked(hyperlane: GalaxyMapHyperlane)

func _ready() -> void:
Expand Down
9 changes: 9 additions & 0 deletions galaxy/galaxy_map/galaxy_map_system.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
extends StaticBody3D
class_name GalaxyMapSystem

## Represents a single star system (a node) in the galaxy map.

## Renders the name of the star system for the player to read.
@export var name_label: Label3D

## The mesh controlling this system node's appearance.
@export var mesh: MeshInstance3D

## When [member current] is true, this material overrides the [member mesh]'s material.
@export var current_node_material: Material

## Whether the system represented by this node is the player's current system.
@export var current: bool:
get:
return self._current
set(value):
self._current = value
self.mesh.material_override = self.current_node_material if value else null

## Fires when this system node is clicked.
signal clicked(system: GalaxyMapSystem)

var _current: bool = false
Expand Down
2 changes: 1 addition & 1 deletion game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ size = Vector2i(1000, 1000)
render_target_update_mode = 0

[node name="GalaxyMap" parent="HUD/GalaxyMapWindow/SubViewportContainer/SubViewport" node_paths=PackedStringArray("hyperspace_controller") instance=ExtResource("28_oyaod")]
galaxy = ExtResource("3_j76v0")
hyperspace_controller = NodePath("../../../../../HyperspaceController")
galaxy = ExtResource("3_j76v0")

[connection signal="jump_destination_changed" from="HyperspaceController" to="HUD/Sidebar/JumpDestinationName" method="_on_jump_destination_changed"]
[connection signal="jump_destination_loaded" from="HyperspaceController" to="Player" method="_on_jump_destination_loaded"]
Expand Down

0 comments on commit 9f880d3

Please sign in to comment.