ed_journals/modules/exploration/models/
codex_thargoid_entry.rs1use crate::exploration::shared::codex_regex::CODEX_REGEX;
2use crate::from_str_deserialize_impl;
3use serde::Serialize;
4use std::fmt::Display;
5use std::str::FromStr;
6use thiserror::Error;
7
8#[derive(Debug, Serialize, Clone, PartialEq, Eq, Hash)]
10#[cfg_attr(not(feature = "allow-unknown"), non_exhaustive)]
11pub enum CodexThargoidEntry {
12 LargeSpike,
13 Tower,
14 TowerLow,
15 TowerMedium,
16 TowerHigh,
17 TowerExtraHigh,
18 Coral,
19 CoralTree,
20 CoralRoot,
21
22 Canister,
23 Datascan,
24 Pod,
25 Transmitter,
26
27 UnknownArtifact,
28 UnknownProbe,
29 UnknownRelay,
30
31 Barnacles,
32 CausticGenerator,
33 Banshee,
34 Revenant,
35 Scavenger,
36
37 Scouts,
38 Marauder,
39 Berserker,
40 Regenerator,
41 Inciter,
42
43 Interceptors,
44 Basilisk,
45 Cyclops,
46 Glaive,
47 Scythe,
48 Hunter,
49 Medusa,
50 Hydra,
51 Orthrus,
52
53 WreckedInterceptor,
54 WreckedScout,
55
56 #[cfg(feature = "allow-unknown")]
57 #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
58 Unknown(String),
59}
60
61impl CodexThargoidEntry {
62 #[cfg(feature = "allow-unknown")]
64 #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
65 pub fn is_unknown(&self) -> bool {
66 matches!(self, CodexThargoidEntry::Unknown(_))
67 }
68}
69
70#[derive(Debug, Error)]
71pub enum CoxexThargoidError {
72 #[error("Failed to parse Thargoid codex entry: '{0}'")]
73 FailedToParse(String),
74
75 #[error("Unknown Thargoid entry: '{0}'")]
76 UnknownEntry(String),
77}
78
79impl FromStr for CodexThargoidEntry {
80 type Err = CoxexThargoidError;
81
82 fn from_str(s: &str) -> Result<Self, Self::Err> {
83 let Some(captures) = CODEX_REGEX.captures(s) else {
84 return Err(CoxexThargoidError::FailedToParse(s.to_string()));
85 };
86
87 let string: &str = &captures
88 .get(1)
89 .expect("Should have been captured already")
90 .as_str()
91 .to_ascii_lowercase();
92
93 Ok(match string {
94 "thargoid_large_spike" => CodexThargoidEntry::LargeSpike,
95 "thargoid_tower" => CodexThargoidEntry::Tower,
96 "thargoid_tower_low" => CodexThargoidEntry::TowerLow,
97 "thargoid_tower_med" => CodexThargoidEntry::TowerMedium,
98 "thargoid_tower__high" | "thargoid_tower_high" => CodexThargoidEntry::TowerHigh,
99 "thargoid_tower_extrahigh" => CodexThargoidEntry::TowerExtraHigh,
100 "thargoid_coral" => CodexThargoidEntry::Coral,
101 "thargoid_coral_tree" => CodexThargoidEntry::CoralTree,
102 "thargoid_coral_root" => CodexThargoidEntry::CoralRoot,
103
104 "tg_canister" => CodexThargoidEntry::Canister,
105 "tg_datascan" => CodexThargoidEntry::Datascan,
106 "tg_pod" => CodexThargoidEntry::Pod,
107 "tg_transmitter" => CodexThargoidEntry::Transmitter,
108
109 "unknownartifact" => CodexThargoidEntry::UnknownArtifact,
110 "unknownprobe" => CodexThargoidEntry::UnknownProbe,
111 "unknownrelay" => CodexThargoidEntry::UnknownRelay,
112
113 "caustic_generator" => CodexThargoidEntry::CausticGenerator,
114 "banshee" => CodexThargoidEntry::Banshee,
115 "barnacles" => CodexThargoidEntry::Barnacles,
116 "revenant" => CodexThargoidEntry::Revenant,
117 "scavenger" => CodexThargoidEntry::Scavenger,
118
119 "scouts" => CodexThargoidEntry::Scouts,
120 "marauder" => CodexThargoidEntry::Marauder,
121 "berserker" => CodexThargoidEntry::Berserker,
122 "regenerator" => CodexThargoidEntry::Regenerator,
123 "inciter" => CodexThargoidEntry::Inciter,
124
125 "interceptors" => CodexThargoidEntry::Interceptors,
126 "basilisk" => CodexThargoidEntry::Basilisk,
127 "cyclops" => CodexThargoidEntry::Cyclops,
128 "glaive" => CodexThargoidEntry::Glaive,
129 "scythe" => CodexThargoidEntry::Scythe,
130 "hunters" => CodexThargoidEntry::Hunter,
131 "medusa" => CodexThargoidEntry::Medusa,
132 "hydra" => CodexThargoidEntry::Hydra,
133 "orthrus" => CodexThargoidEntry::Orthrus,
134
135 "wrecked_interceptor" => CodexThargoidEntry::WreckedInterceptor,
136 "wrecked_scout" => CodexThargoidEntry::WreckedScout,
137
138 #[cfg(feature = "allow-unknown")]
139 _ => CodexThargoidEntry::Unknown(string.to_string()),
140
141 #[cfg(not(feature = "allow-unknown"))]
142 _ => return Err(CoxexThargoidError::UnknownEntry(string.to_string())),
143 })
144 }
145}
146
147from_str_deserialize_impl!(CodexThargoidEntry);
148
149impl Display for CodexThargoidEntry {
150 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
151 write!(
152 f,
153 "{}",
154 match self {
155 CodexThargoidEntry::LargeSpike => "Large Thargoid Spike",
156 CodexThargoidEntry::Tower => "Thargoid Tower",
157 CodexThargoidEntry::TowerLow => "Low Thargoid Tower",
158 CodexThargoidEntry::TowerMedium => "Medium Thargoid Tower",
159 CodexThargoidEntry::TowerHigh => "High Thargoid Tower",
160 CodexThargoidEntry::TowerExtraHigh => "Extra High Thargoid Tower",
161 CodexThargoidEntry::Coral => "Thargoid Coral",
162 CodexThargoidEntry::CoralTree => "Thargoid Coral Tree",
163 CodexThargoidEntry::CoralRoot => "Thargoid Coral Root",
164
165 CodexThargoidEntry::Canister => "Thargoid Canister",
166 CodexThargoidEntry::Datascan => "Thargoid Datascan",
167 CodexThargoidEntry::Pod => "Thargoid Pod",
168 CodexThargoidEntry::Transmitter => "Thargoid Transmitter",
169
170 CodexThargoidEntry::UnknownArtifact => "Unknown Artifact",
171 CodexThargoidEntry::UnknownProbe => "Unknown Probe",
172 CodexThargoidEntry::UnknownRelay => "Unknown Relay",
173
174 CodexThargoidEntry::CausticGenerator => "Caustic Generator",
175 CodexThargoidEntry::Banshee => "Banshee",
176 CodexThargoidEntry::Barnacles => "Barnacles",
177 CodexThargoidEntry::Revenant => "Revenant",
178 CodexThargoidEntry::Scavenger => "Scavenger",
179
180 CodexThargoidEntry::Scouts => "Scouts",
181 CodexThargoidEntry::Marauder => "Marauder",
182 CodexThargoidEntry::Berserker => "Berserker",
183 CodexThargoidEntry::Regenerator => "Regenerator",
184 CodexThargoidEntry::Inciter => "Inciter",
185
186 CodexThargoidEntry::Interceptors => "Interceptors",
187 CodexThargoidEntry::Basilisk => "Basilisk",
188 CodexThargoidEntry::Cyclops => "Cyclops",
189 CodexThargoidEntry::Glaive => "Glaive",
190 CodexThargoidEntry::Scythe => "Scythe",
191 CodexThargoidEntry::Hunter => "Hunter",
192 CodexThargoidEntry::Medusa => "Medusa",
193 CodexThargoidEntry::Hydra => "Hydra",
194 CodexThargoidEntry::Orthrus => "Orthrus",
195
196 CodexThargoidEntry::WreckedInterceptor => "Wrecked Interceptor",
197 CodexThargoidEntry::WreckedScout => "Wrecked Scout",
198
199 #[cfg(feature = "allow-unknown")]
200 CodexThargoidEntry::Unknown(unknown) =>
201 return write!(f, "Unknown codex entry: '{unknown}'"),
202 }
203 )
204 }
205}