ed_journals/modules/ship/models/
blueprint.rs

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};

/// Engineering blueprint that can be applied to certain ship modules.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum Blueprint {
    // Armor
    #[serde(rename = "Armour_Explosive")]
    ArmorBlastResistant,

    #[serde(rename = "Armour_HeavyDuty")]
    ArmorHeavyDuty,

    #[serde(rename = "Armour_Kinetic")]
    ArmorKineticResistant,

    #[serde(rename = "Armour_Advanced")]
    ArmorLightweight,

    #[serde(rename = "Armour_Thermic")]
    ArmorThermalResistant,

    // FSD Interdictor
    #[serde(rename = "FSDinterdictor_Expanded")]
    FSDInterdictorExpandedCaptureArc,

    #[serde(rename = "FSDinterdictor_LongRange")]
    FSDInterdictorLongRange,

    // Frame shift drive
    #[serde(rename = "FSD_LongRange")]
    FrameShiftDriveLongRange,

    #[serde(rename = "FSD_FastBoot")]
    FrameShiftDriveFasterBootSequence,

    #[serde(rename = "FSD_Shielded")]
    FrameShiftDriveShielded,

    // Hull reinforcement
    #[serde(rename = "HullReinforcement_Explosive")]
    HullReinforcementBlastResistant,

    #[serde(rename = "HullReinforcement_HeavyDuty")]
    HullReinforcementHeavyDuty,

    #[serde(rename = "HullReinforcement_Kinetic")]
    HullReinforcementKineticResistant,

    #[serde(rename = "HullReinforcement_Advanced")]
    HullReinforcementLightweight,

    #[serde(rename = "HullReinforcement_Thermic")]
    HullReinforcementThermalResistant,

    // Misc
    #[serde(rename = "Misc_LightWeight")]
    MiscLightweight,

    #[serde(rename = "Misc_Reinforced")]
    MiscReinforced,

    #[serde(rename = "Misc_Shielded")]
    MiscShielded,

    // Power distributor
    #[serde(rename = "PowerDistributor_HighFrequency")]
    PowerDistributorChargeEnhanced,

    #[serde(rename = "PowerDistributor_PriorityEngines")]
    PowerDistributorEngineFocussed,

    #[serde(rename = "PowerDistributor_HighCapacity")]
    PowerDistributorHighCapacity,

    #[serde(rename = "PowerDistributor_PriorityEngines")]
    PowerDistributorPrioritizeEngines,

    #[serde(rename = "PowerDistributor_PriorityWeapons")]
    PowerDistributorPrioritizeWeapons,

    #[serde(rename = "PowerDistributor_PrioritySystems")]
    PowerDistributorPrioritizeSystems,

    #[serde(rename = "PowerDistributor_Shielded")]
    PowerDistributorShielded,

    // Powerplant
    #[serde(rename = "PowerPlant_Stealth")]
    PowerPlantLowEmissions,

    #[serde(rename = "PowerPlant_Boosted")]
    PowerPlantOvercharged,

    #[serde(rename = "PowerPlant_Armoured")]
    PowerPlantArmored,

    // Sensors
    #[serde(rename = "Sensor_FastScan")]
    SensorsFastScan,

    #[serde(rename = "Sensor_LongRange")]
    SensorsLongRange,

    #[serde(rename = "Sensor_WideAngle")]
    SensorsWideAngle,

    #[serde(rename = "Sensor_LightWeight")]
    SensorsLightweight,

    #[serde(rename = "Sensor_Expanded")]
    SensorsExpandedRadius,

    // Shield booster
    #[serde(rename = "ShieldBooster_Explosive")]
    ShieldBoosterBlastResistant,

    #[serde(rename = "ShieldBooster_Resistive")]
    ShieldBoosterResistanceAugmented,

    #[serde(rename = "ShieldBooster_HeavyDuty")]
    ShieldBoosterHeavyDuty,

    #[serde(rename = "ShieldBooster_Kinetic")]
    ShieldBoosterKineticResistant,

    #[serde(rename = "ShieldBooster_Thermic")]
    ShieldBoosterThermalResistant,

    // Shield cell bank
    #[serde(rename = "ShieldCellBank_Rapid")]
    ShieldCellBankRapidCharge,

    #[serde(rename = "ShieldCellBank_Specialised")]
    ShieldCellBankSpecialized,

    // Shield generator
    #[serde(rename = "ShieldGenerator_Reinforced")]
    ShieldGeneratorReinforced,

    #[serde(rename = "ShieldGenerator_Kinetic")]
    ShieldGeneratorKineticResistant,

    #[serde(rename = "ShieldGenerator_Thermic")]
    ShieldGeneratorThermalResistant,

    #[serde(rename = "ShieldGenerator_Optimised")]
    ShieldGeneratorEnhancedLowPower,

    // Thrusters
    #[serde(rename = "Engine_Dirty")]
    ThrustersDirtyTuning,

    #[serde(rename = "Engine_Tuned")]
    ThrustersCleanTuning,

    #[serde(rename = "Engine_Reinforced")]
    ThrustersStrengthened,

    // Weapons
    #[serde(rename = "Weapon_LightWeight")]
    WeaponLightweight,

    #[serde(rename = "Weapon_Sturdy")]
    WeaponSturdy,

    #[serde(rename = "Weapon_Overcharged")]
    WeaponOvercharged,

    #[serde(rename = "Weapon_HighCapacity")]
    WeaponHighCapacity,

    #[serde(rename = "Weapon_DoubleShot")]
    WeaponDoubleShot,

    #[serde(rename = "Weapon_Efficient")]
    WeaponEfficient,

    #[serde(rename = "Weapon_Focused")]
    WeaponFocussed,

    #[serde(rename = "Weapon_LongRange")]
    WeaponLongRange,

    #[serde(rename = "Weapon_ShortRange")]
    WeaponShortRange,

    #[serde(rename = "Weapon_RapidFire")]
    WeaponRapidFire,

    // Capacity
    #[serde(rename = "Misc_HeatSinkCapacity")]
    HeatSinkCapacity,

    #[serde(rename = "Misc_PointDefenseCapacity")]
    PointDefenceCapacity,

    #[serde(rename = "Misc_ChaffCapacity")]
    ChaffCapacity,

    #[cfg(feature = "allow-unknown")]
    #[cfg_attr(docsrs, doc(cfg(feature = "allow-unknown")))]
    #[serde(untagged)]
    Unknown(String),
}

impl Display for Blueprint {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Blueprint::ArmorBlastResistant => "Blast Resistant",
                Blueprint::ArmorHeavyDuty => "Heavy Duty",
                Blueprint::ArmorKineticResistant => "Kinetic Resistant",
                Blueprint::ArmorLightweight => "Lightweight",
                Blueprint::ArmorThermalResistant => "Thermal Resistant",
                Blueprint::ChaffCapacity => "Ammo capacity",
                Blueprint::FSDInterdictorExpandedCaptureArc => "Expanded Capture Arc",
                Blueprint::FSDInterdictorLongRange => "Long Range",
                Blueprint::FrameShiftDriveFasterBootSequence => "Faster Boot Sequence",
                Blueprint::FrameShiftDriveLongRange => "Long Range",
                Blueprint::FrameShiftDriveShielded => "Shielded",
                Blueprint::HeatSinkCapacity => "Ammo capacity",
                Blueprint::HullReinforcementBlastResistant => "Blast Resistant",
                Blueprint::HullReinforcementHeavyDuty => "Heavy Duty",
                Blueprint::HullReinforcementKineticResistant => "Kinetic Resistant",
                Blueprint::HullReinforcementLightweight => "Lightweight",
                Blueprint::HullReinforcementThermalResistant => "Thermal Resistant",
                Blueprint::MiscLightweight => "Lightweight",
                Blueprint::MiscReinforced => "Reinforced",
                Blueprint::MiscShielded => "Shielded",
                Blueprint::PointDefenceCapacity => "Ammo capacity",
                Blueprint::PowerDistributorChargeEnhanced => "Charge Enhanced",
                Blueprint::PowerDistributorEngineFocussed => "Engine Focussed",
                Blueprint::PowerDistributorHighCapacity => "High Capacity",
                Blueprint::PowerDistributorPrioritizeEngines => "Prioritize Engines",
                Blueprint::PowerDistributorPrioritizeSystems => "Prioritize Systems",
                Blueprint::PowerDistributorPrioritizeWeapons => "Prioritize Weapons",
                Blueprint::PowerDistributorShielded => "Shielded",
                Blueprint::PowerPlantArmored => "Armored",
                Blueprint::PowerPlantLowEmissions => "Low Emissions",
                Blueprint::PowerPlantOvercharged => "Overcharged",
                Blueprint::SensorsFastScan => "Fast Scan",
                Blueprint::SensorsLightweight => "Lightweight",
                Blueprint::SensorsLongRange => "Long Range",
                Blueprint::SensorsWideAngle => "Wide Angle",
                Blueprint::SensorsExpandedRadius => "Wide Angle",
                Blueprint::ShieldBoosterBlastResistant => "Expanded Radius",
                Blueprint::ShieldBoosterHeavyDuty => "Heavy Duty",
                Blueprint::ShieldBoosterKineticResistant => "Kinetic Resistant",
                Blueprint::ShieldBoosterResistanceAugmented => "Resistance Augmented",
                Blueprint::ShieldBoosterThermalResistant => "Thermal Resistant",
                Blueprint::ShieldCellBankRapidCharge => "Rapid Charge",
                Blueprint::ShieldCellBankSpecialized => "Specialized",
                Blueprint::ShieldGeneratorEnhancedLowPower => "Enhanced, Low Power",
                Blueprint::ShieldGeneratorKineticResistant => "Kinetic Resistant",
                Blueprint::ShieldGeneratorReinforced => "Reinforced",
                Blueprint::ShieldGeneratorThermalResistant => "Thermal Resistant",
                Blueprint::ThrustersCleanTuning => "Clean Tuning",
                Blueprint::ThrustersDirtyTuning => "Dirty Tuning",
                Blueprint::ThrustersStrengthened => "Strengthened",
                Blueprint::WeaponDoubleShot => "Double Shot",
                Blueprint::WeaponEfficient => "Efficient",
                Blueprint::WeaponFocussed => "Focussed",
                Blueprint::WeaponHighCapacity => "High Capacity",
                Blueprint::WeaponLightweight => "Lightweight",
                Blueprint::WeaponLongRange => "Long Range",
                Blueprint::WeaponOvercharged => "Overcharge",
                Blueprint::WeaponRapidFire => "Rapid Fire",
                Blueprint::WeaponShortRange => "Short Range",
                Blueprint::WeaponSturdy => "Sturdy",

                #[cfg(feature = "allow-unknown")]
                Blueprint::Unknown(unknown) => return write!(f, "Unknown blueprint: {}", unknown),
            }
        )
    }
}

#[cfg(test)]
mod tests {
    use crate::ship::Blueprint;
    use serde_json::Value;

    #[test]
    fn all_blueprint_test_cases_are_parsed_correctly() {
        let contents = include_str!("zz_blueprint_test_cases.txt");
        let lines = contents.lines();

        for line in lines {
            dbg!(&line);
            let result = serde_json::from_value::<Blueprint>(Value::String(line.to_string()));

            assert!(result.is_ok());
        }
    }
}