Skip to main content

ed_journals/modules/exploration/models/
codex_anomaly_entry.rs

1use crate::exploration::shared::codex_regex::CODEX_REGEX;
2use serde::{Deserialize, Serialize};
3use std::fmt::{Display, Formatter};
4use std::str::FromStr;
5use thiserror::Error;
6
7/// Codex entries related to anomalies.
8#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
9#[cfg_attr(not(feature = "allow-unknown"), non_exhaustive)]
10pub enum CodexAnomalyEntry {
11    LagrangeClouds,
12
13    BlueGasClouds,
14    StormingBlueGasClouds,
15    ChargedGasClouds,
16    GreenGasClouds,
17    StormingGreenGasClouds,
18    LightGasClouds,
19    GasClouds,
20    OrangeGasClouds,
21    StormingOrangeGasClouds,
22    PinkGasClouds,
23    StormingPinkGasClouds,
24    RedGasClouds,
25    StormingRedGasClouds,
26    StandardGasClouds,
27    YellowGasClouds,
28    StormingYellowGasClouds,
29
30    MetallicStructures,
31
32    Mollusc1V1,
33    Mollusc1V2,
34    Mollusc1V3,
35    Mollusc1V4,
36    Mollusc1V5,
37    Mollusc1V6,
38    Mollusc3V1,
39    Mollusc3V2,
40    Mollusc3V3,
41    Mollusc3V4,
42    Mollusc3V6,
43
44    PlateStructures,
45
46    SilicateStructures,
47
48    #[cfg(feature = "allow-unknown")]
49    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
50    Unknown(String),
51}
52
53impl CodexAnomalyEntry {
54    /// Whether the current variant is unknown.
55    #[cfg(feature = "allow-unknown")]
56    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
57    pub fn is_unknown(&self) -> bool {
58        matches!(self, CodexAnomalyEntry::Unknown(_))
59    }
60}
61
62#[derive(Debug, Error)]
63pub enum CodexAnomalyError {
64    #[error("Failed to parse codex anomaly entry: '{0}'")]
65    FailedToParse(String),
66
67    #[error("Unknown codex anomaly entry: '{0}'")]
68    UnknownEntry(String),
69}
70
71impl FromStr for CodexAnomalyEntry {
72    type Err = CodexAnomalyError;
73
74    fn from_str(s: &str) -> Result<Self, Self::Err> {
75        let Some(captures) = CODEX_REGEX.captures(s) else {
76            return Err(CodexAnomalyError::FailedToParse(s.to_string()));
77        };
78
79        let string: &str = &captures
80            .get(1)
81            .expect("Should have been captured already")
82            .as_str()
83            .to_ascii_lowercase();
84
85        Ok(match string {
86            "clouds" => CodexAnomalyEntry::LagrangeClouds,
87            "gas_clds_blue" => CodexAnomalyEntry::BlueGasClouds,
88            "gas_clds_blue_storm" => CodexAnomalyEntry::StormingBlueGasClouds,
89            "gas_clds_charged" => CodexAnomalyEntry::ChargedGasClouds,
90            "gas_clds_green" => CodexAnomalyEntry::GreenGasClouds,
91            "gas_clds_green_storm" => CodexAnomalyEntry::StormingGreenGasClouds,
92            "gas_clds_light" => CodexAnomalyEntry::LightGasClouds,
93            "gas_clds" => CodexAnomalyEntry::GasClouds,
94            "gas_clds_orange" => CodexAnomalyEntry::OrangeGasClouds,
95            "gas_clds_orange_storm" => CodexAnomalyEntry::StormingOrangeGasClouds,
96            "gas_clds_pink" => CodexAnomalyEntry::PinkGasClouds,
97            "gas_clds_pink_storm" => CodexAnomalyEntry::StormingPinkGasClouds,
98            "gas_clds_red" => CodexAnomalyEntry::RedGasClouds,
99            "gas_clds_red_storm" => CodexAnomalyEntry::StormingRedGasClouds,
100            "gas_clds_standard" => CodexAnomalyEntry::StandardGasClouds,
101            "gas_clds_yellow" => CodexAnomalyEntry::YellowGasClouds,
102            "gas_clds_yellow_storm" => CodexAnomalyEntry::StormingYellowGasClouds,
103
104            "metalic_structures" => CodexAnomalyEntry::MetallicStructures,
105
106            "mollusc1_v1" => CodexAnomalyEntry::Mollusc1V1,
107            "mollusc1_v2" => CodexAnomalyEntry::Mollusc1V2,
108            "mollusc1_v3" => CodexAnomalyEntry::Mollusc1V3,
109            "mollusc1_v4" => CodexAnomalyEntry::Mollusc1V4,
110            "mollusc1_v5" => CodexAnomalyEntry::Mollusc1V5,
111            "mollusc1_v6" => CodexAnomalyEntry::Mollusc1V6,
112            "mollusc3_v1" => CodexAnomalyEntry::Mollusc3V1,
113            "mollusc3_v2" => CodexAnomalyEntry::Mollusc3V2,
114            "mollusc3_v3" => CodexAnomalyEntry::Mollusc3V3,
115            "mollusc3_v4" => CodexAnomalyEntry::Mollusc3V4,
116            "mollusc3_v6" => CodexAnomalyEntry::Mollusc3V6,
117
118            "plate_structures" => CodexAnomalyEntry::PlateStructures,
119
120            "silicate_structures" => CodexAnomalyEntry::SilicateStructures,
121
122            #[cfg(feature = "allow-unknown")]
123            _ => CodexAnomalyEntry::Unknown(string.to_string()),
124
125            #[cfg(not(feature = "allow-unknown"))]
126            _ => return Err(CodexAnomalyError::UnknownEntry(string.to_string())),
127        })
128    }
129}
130
131impl Display for CodexAnomalyEntry {
132    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
133        write!(
134            f,
135            "{}",
136            match self {
137                CodexAnomalyEntry::LagrangeClouds => "Lagrange Clouds",
138                CodexAnomalyEntry::BlueGasClouds => "Blue Gas Clouds",
139                CodexAnomalyEntry::StormingBlueGasClouds => "Storming Blue Gas Clouds",
140                CodexAnomalyEntry::ChargedGasClouds => "Charged Gas Clouds",
141                CodexAnomalyEntry::GreenGasClouds => "Green Gas Clouds",
142                CodexAnomalyEntry::StormingGreenGasClouds => "Storming Green Gas Clouds",
143                CodexAnomalyEntry::LightGasClouds => "Light Gas Clouds",
144                CodexAnomalyEntry::GasClouds => "Gas Clouds",
145                CodexAnomalyEntry::OrangeGasClouds => "Orange Gas Clouds",
146                CodexAnomalyEntry::StormingOrangeGasClouds => "Storming Orange Gas Clouds",
147                CodexAnomalyEntry::PinkGasClouds => "Pink Gas Clouds",
148                CodexAnomalyEntry::StormingPinkGasClouds => "Storming Pink Gas Clouds",
149                CodexAnomalyEntry::RedGasClouds => "Red Gas Clouds",
150                CodexAnomalyEntry::StormingRedGasClouds => "Storming Red Gas Clouds",
151                CodexAnomalyEntry::StandardGasClouds => "Standing Gas Clouds",
152                CodexAnomalyEntry::YellowGasClouds => "Yellow Gas Clouds",
153                CodexAnomalyEntry::StormingYellowGasClouds => "Storming Yellow Gas Clouds",
154
155                CodexAnomalyEntry::MetallicStructures => "Metallic Structures",
156
157                CodexAnomalyEntry::Mollusc1V1 => "Mollusc 1 V1",
158                CodexAnomalyEntry::Mollusc1V2 => "Mollusc 1 V2",
159                CodexAnomalyEntry::Mollusc1V3 => "Mollusc 1 V3",
160                CodexAnomalyEntry::Mollusc1V4 => "Mollusc 1 V4",
161                CodexAnomalyEntry::Mollusc1V5 => "Mollusc 1 V5",
162                CodexAnomalyEntry::Mollusc1V6 => "Mollusc 1 V6",
163                CodexAnomalyEntry::Mollusc3V1 => "Mollusc 3 V1",
164                CodexAnomalyEntry::Mollusc3V2 => "Mollusc 3 V2",
165                CodexAnomalyEntry::Mollusc3V3 => "Mollusc 3 V3",
166                CodexAnomalyEntry::Mollusc3V4 => "Mollusc 3 V4",
167                CodexAnomalyEntry::Mollusc3V6 => "Mollusc 3 V6",
168
169                CodexAnomalyEntry::PlateStructures => "Plate Structures",
170
171                CodexAnomalyEntry::SilicateStructures => "Silicate Structures",
172
173                #[cfg(feature = "allow-unknown")]
174                CodexAnomalyEntry::Unknown(unknown) =>
175                    return write!(f, "Unknown anomaly codex entry: {unknown}"),
176                // CodexAnomalyEntry::ETypeAnomalies => "E Type Anomalies",
177                // CodexAnomalyEntry::KTypeAnomalies => "K Type Anomalies",
178                // CodexAnomalyEntry::LTypeAnomalies => "L Type Anomalies",
179                // CodexAnomalyEntry::PTypeAnomalies => "P Type Anomalies",
180                // CodexAnomalyEntry::QTypeAnomalies => "Q Type Anomalies",
181                // CodexAnomalyEntry::TTypeAnomalies => "T Type Anomalies",
182            }
183        )
184    }
185}