1use num_enum::{IntoPrimitive, TryFromPrimitive};
2use serde::{Deserialize, Serialize};
3use std::str::FromStr;
4
5#[repr(i16)]
6#[derive(
7 Serialize, Deserialize, Copy, Clone, Eq, Debug, PartialEq, Hash, TryFromPrimitive, IntoPrimitive,
8)]
9#[cfg_attr(
10 feature = "strum",
11 derive(strum::Display, strum::EnumIter, strum::VariantNames, strum::FromRepr)
12)]
13pub enum Loadout {
14 Unknown = 0,
15 NCInfiltrator = 1,
16 NCLightAssault = 3,
17 NCMedic = 4,
18 NCEngineer = 5,
19 NCHeavyAssault = 6,
20 NCMAX = 7,
21 TRInfiltrator = 8,
22 TRLightAssault = 10,
23 TRMedic = 11,
24 TREngineer = 12,
25 TRHeavyAssault = 13,
26 TRMAX = 14,
27 VSInfiltrator = 15,
28 VSLightAssault = 17,
29 VSMedic = 18,
30 VSEngineer = 19,
31 VSHeavyAssault = 20,
32 VSMAX = 21,
33 NSInfiltrator = 28,
34 NSLightAssault = 29,
35 NSMedic = 30,
36 NSEngineer = 31,
37 NSHeavyAssault = 32,
38 NSMAX = 45,
39}
40
41impl Loadout {
42 pub fn get_faction(&self) -> Faction {
43 match self {
44 Loadout::Unknown => Faction::Unknown,
45 Loadout::NCInfiltrator => Faction::NC,
46 Loadout::NCLightAssault => Faction::NC,
47 Loadout::NCMedic => Faction::NC,
48 Loadout::NCEngineer => Faction::NC,
49 Loadout::NCHeavyAssault => Faction::NC,
50 Loadout::NCMAX => Faction::NC,
51 Loadout::TRInfiltrator => Faction::TR,
52 Loadout::TRLightAssault => Faction::TR,
53 Loadout::TRMedic => Faction::TR,
54 Loadout::TREngineer => Faction::TR,
55 Loadout::TRHeavyAssault => Faction::TR,
56 Loadout::TRMAX => Faction::TR,
57 Loadout::VSInfiltrator => Faction::VS,
58 Loadout::VSLightAssault => Faction::VS,
59 Loadout::VSMedic => Faction::VS,
60 Loadout::VSEngineer => Faction::VS,
61 Loadout::VSHeavyAssault => Faction::VS,
62 Loadout::VSMAX => Faction::VS,
63 Loadout::NSInfiltrator => Faction::NS,
64 Loadout::NSLightAssault => Faction::NS,
65 Loadout::NSMedic => Faction::NS,
66 Loadout::NSEngineer => Faction::NS,
67 Loadout::NSHeavyAssault => Faction::NS,
68 Loadout::NSMAX => Faction::NS,
69 }
70 }
71}
72
73impl FromStr for Loadout {
74 type Err = anyhow::Error;
75
76 fn from_str(s: &str) -> Result<Self, Self::Err> {
77 let id = i16::from_str(s)?;
78 let loadout = Self::try_from(id)?;
79
80 Ok(loadout)
81 }
82}
83
84#[repr(i16)]
85#[derive(
86 Serialize, Deserialize, Copy, Clone, Eq, Debug, PartialEq, Hash, TryFromPrimitive, IntoPrimitive,
87)]
88#[cfg_attr(
89 feature = "strum",
90 derive(strum::Display, strum::EnumIter, strum::VariantNames, strum::FromRepr)
91)]
92pub enum Faction {
93 Unknown = 0,
94 VS = 1,
95 NC = 2,
96 TR = 3,
97 NS = 4,
98}
99
100impl FromStr for Faction {
101 type Err = anyhow::Error;
102
103 fn from_str(s: &str) -> Result<Self, Self::Err> {
104 let id = i16::from_str(s)?;
105 let faction = Self::try_from(id)?;
106
107 Ok(faction)
108 }
109}
110
111#[repr(i16)]
112#[derive(
113 Serialize, Deserialize, Copy, Clone, Eq, Debug, PartialEq, Hash, TryFromPrimitive, IntoPrimitive,
114)]
115#[cfg_attr(
116 feature = "strum",
117 derive(strum::Display, strum::EnumIter, strum::VariantNames, strum::FromRepr)
118)]
119pub enum WorldID {
120 Jaeger = 19,
121 Briggs = 25,
122 Miller = 10,
123 Cobalt = 13,
124 Connery = 1,
125 Emerald = 17,
126 Soltech = 40,
127}
128
129impl FromStr for WorldID {
130 type Err = anyhow::Error;
131
132 fn from_str(s: &str) -> Result<Self, Self::Err> {
133 let id = i16::from_str(s)?;
134 let world = Self::try_from(id)?;
135
136 Ok(world)
137 }
138}
139
140#[cfg(not(feature = "strum"))]
141impl std::fmt::Display for WorldID {
142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
143 match self {
144 WorldID::Jaeger => write!(f, "Jaeger"),
145 WorldID::Briggs => write!(f, "Briggs"),
146 WorldID::Miller => write!(f, "Miller"),
147 WorldID::Cobalt => write!(f, "Cobalt"),
148 WorldID::Connery => write!(f, "Connery"),
149 WorldID::Emerald => write!(f, "Emerald"),
150 WorldID::Soltech => write!(f, "Soltech"),
151 }
152 }
153}