1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::internal::*;
use crate::prelude::*;
pub mod celestial_body;
pub mod celestial_disk;
pub mod contents;
mod display;
pub mod generator;
pub mod neighborhood;
pub mod orbital_point;
pub mod star;
pub mod types;
#[derive(Clone, PartialEq, PartialOrd, Debug, SmartDefault, Serialize, Deserialize)]
pub struct StarSystem {
/// That star's name.
#[default("default")]
pub name: Rc<str>,
/// The id of the [OrbitalPoint] at the center of the system.
pub center_id: u32,
/// The id of the [OrbitalPoint] containing the main star of the system.
pub main_star_id: u32,
/// The list of [OrbitalPoint]s that can be found in the system.
pub all_objects: Vec<OrbitalPoint>,
/// What are the pecularities of this system.
pub special_traits: Vec<SystemPeculiarity>,
}
impl StarSystem {
/// Creates a new star system with the given array of [OrbitalPoint], and the id of the system's main star.
pub fn new(
name: Rc<str>,
center_id: u32,
main_star_id: u32,
all_objects: Vec<OrbitalPoint>,
special_traits: Vec<SystemPeculiarity>,
) -> Self {
Self {
name,
center_id,
main_star_id,
all_objects,
special_traits,
}
}
/// Returns a reference to the [OrbitalPoint] at the center of the system. It can either be a [Star] or the barycentre of a binary pair.
pub fn get_center(&self) -> &OrbitalPoint {
self.get_point(self.center_id)
.expect("There should always be a center point.")
}
/// Returns a mutable reference to the [OrbitalPoint] at the center of the system. It can either be a [Star] or the barycentre
/// of a binary pair.
pub fn get_center_mut(&mut self) -> &mut OrbitalPoint {
self.get_point_mut(self.center_id)
.expect("There should always be a center point.")
}
/// Returns a reference to the [OrbitalPoint] containing the main [Star] of the system.
pub fn get_main_star(&self) -> &OrbitalPoint {
self.get_point(self.main_star_id)
.expect("There should always be a main star.")
}
/// Returns a mutable reference to the [OrbitalPoint] containing the main [Star] of the system.
pub fn get_main_star_mut(&mut self) -> &mut OrbitalPoint {
self.get_point_mut(self.main_star_id)
.expect("There should always be a main star.")
}
/// Returns an [Option] that might contain a reference to the object with the given id.
pub fn get_point(&self, id: u32) -> Option<&OrbitalPoint> {
self.all_objects.iter().find(|p| p.id == id)
}
/// Returns an [Option] that might contain a mutable reference to the object with the given id.
pub fn get_point_mut(&mut self, id: u32) -> Option<&mut OrbitalPoint> {
self.all_objects.iter_mut().find(|p| p.id == id)
}
}