Skip to content

Commit

Permalink
🚧 Continue working through failing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rster2002 committed May 16, 2024
1 parent 3b71a6b commit 60c92a1
Show file tree
Hide file tree
Showing 20 changed files with 377 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/modules/logs/content/log_event_content/bounty_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum BountyEvent {
#[serde(rename_all = "PascalCase")]
pub struct BountyEventNormal {
pub rewards: Vec<BountyEventNormalReward>,
pub pilot_name: String,
pub pilot_name: Option<String>,

#[serde(rename = "PilotName_Localised")]
pub pilot_name_localized: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct MissionRedirectedEvent {
#[serde(rename = "MissionID")]
pub mission_id: u64,
pub name: MissionType,
pub localised_name: String,
pub localised_name: Option<String>,
pub new_destination_station: String,
pub new_destination_system: String,
pub old_destination_station: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct ScreenshotEvent {
pub filename: String,
pub width: u16,
pub height: u16,
pub system: String,
pub system: Option<String>,
pub body: Option<String>,
pub latitude: Option<f32>,
pub longitude: Option<f32>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use serde::{Serialize, Deserialize};
use crate::models::odyssey::suit_mod::SuitMod;
use crate::models::odyssey::suit_slot::SuitSlot;
use crate::models::odyssey::weapon::Weapon;
use crate::models::odyssey::weapon_mod::WeaponMod;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
Expand All @@ -11,39 +15,25 @@ pub struct SwitchSuitLoadoutEvent {

#[serde(rename = "SuitName_Localised")]
pub suit_name_localized: String,
pub suit_mods: Vec<SwitchSuitLoadoutEventMod>,
pub suit_mods: Vec<SuitMod>,

#[serde(rename = "LoadoutID")]
pub loadout_id: u64,
pub loadout_name: String,
pub modules: Vec<SwitchSuitLoadoutEventModule>,
}

// TODO not sure what this should contain
// TODO this might be the same as in suit_loadout_event
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct SwitchSuitLoadoutEventMod {}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct SwitchSuitLoadoutEventModule {
// TODO look if this can be an enum
pub slot_name: String,
pub slot_name: SuitSlot,

#[serde(rename = "SuitModuleID")]
pub suit_module_id: u64,

// TODO look if this can be an enum
pub module_name: String,
pub module_name: Weapon,

#[serde(rename = "ModuleName_Localised")]
pub module_name_localized: String,
pub class: u8,
pub weapon_mods: Vec<SwitchSuitLoadoutEventModuleWeaponMod>,
pub weapon_mods: Vec<WeaponMod>,
}

// TODO I'm not yet sure what this should contain
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct SwitchSuitLoadoutEventModuleWeaponMod {}
2 changes: 1 addition & 1 deletion src/modules/models/materials/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub enum Material {
#[serde(alias = "scanarchives")]
UnidentifiedScanArchives,

#[serde(alias = "scandatabanks")]
#[serde(alias = "scandatabanks", alias = "ScanDatabanks")]
ClassifiedScanDatabanks,

#[serde(alias = "EncodedScanData", alias = "encodedscandata")]
Expand Down
6 changes: 5 additions & 1 deletion src/modules/models/odyssey/citizen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ pub enum Citizen {
)]
Scout,

#[serde(rename = "closesuitai_class1", alias = "closesuitai_class3")]
#[serde(
rename = "closesuitai_class1",
alias = "closesuitai_class2",
alias = "closesuitai_class3",
)]
Striker,

// TODO this is a guess
Expand Down
18 changes: 12 additions & 6 deletions src/modules/models/odyssey/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Item {
"chemicalpatents" => Item::ChemicalPatents,
"chemicalweapondata" => Item::ChemicalWeaponData,
"classicentertainment" => Item::ClassicEntertainment,
"clinicaltrialrecords" => Item::ClinicalTrialRecords,
"medicaltrialrecords" => Item::ClinicalTrialRecords,
"cocktailrecipes" => Item::CocktailRecipes,
"combattrainingmaterial" => Item::CombatTrainingMaterial,
"combatantperformance" => Item::CombatantPerformance,
Expand Down Expand Up @@ -332,7 +332,7 @@ impl Item {
"spectralanalysisdata" => Item::SpectralAnalysisData,
"spyware" => Item::Spyware,
"stellaractivitylogs" => Item::StellarActivityLogs,
"surveillancelogs" => Item::SurveillanceLogs,
"surveilleancelogs" => Item::SurveillanceLogs,
"tacticalplans" => Item::TacticalPlans,
"taxrecords" => Item::TaxRecords,
"topographicalsurveys" => Item::TopographicalSurveys,
Expand Down Expand Up @@ -699,10 +699,16 @@ mod tests {

#[test]
fn item_test_cases_are_parsed_correctly() {
let test_cases = [(
"$EnhancedInterrogationRecordings_Name;",
Item::EnhancedInterrogationRecordings,
)];
let test_cases = [
(
"$EnhancedInterrogationRecordings_Name;",
Item::EnhancedInterrogationRecordings,
),
(
"$WeaponSchematic_Name;",
Item::WeaponSchematic,
),
];

for (case, expected) in test_cases {
let result = Item::from_str(case);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/models/odyssey/suit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum SuitError {
}

lazy_static! {
static ref SUIT_REGEX: Regex = Regex::new(r#"^(\w+?)(_class(\d))?$"#).unwrap();
static ref SUIT_REGEX: Regex = Regex::new(r#"^(\w+?)(_[cC]lass(\d))?$"#).unwrap();
}

impl FromStr for Suit {
Expand Down
30 changes: 26 additions & 4 deletions src/modules/models/odyssey/suit_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@ use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub enum SuitMod {
#[serde(alias = "suit_reducedtoolbatteryconsumption")]
#[serde(rename = "suit_reducedtoolbatteryconsumption")]
ReducedToolBatteryConsumption,

#[serde(alias = "suit_increasedbatterycapacity")]
IncreasedBatteryCapacity,
#[serde(rename = "suit_increasedbatterycapacity")]
ImprovedBatteryCapacity,

#[serde(alias = "suit_increasedsprintduration")]
#[serde(rename = "suit_increasedsprintduration")]
IncreasedSprintDuration,

CombatMovementSpeed,
ImprovedJumpAssist,
IncreasedAirReserves,
NightVision,

#[serde(rename = "suit_improvedradar")]
EnhancedTracking,

#[serde(rename = "suit_backpackcapacity")]
ExtraBackpackCapacity,
AddedMeleeDamage,
DamageResistance,

#[serde(rename = "suit_increasedammoreserves")]
ExtraAmmoCapacity,

#[serde(rename = "suit_increasedshieldregen")]
FasterShieldRegen,

#[serde(rename = "suit_quieterfootsteps")]
QuieterFootsteps,
}
25 changes: 25 additions & 0 deletions src/modules/models/ship/ship_module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::fmt::{Display, Formatter};

use serde::{Serialize, Deserialize};
use crate::models::ship::ship_module::ship_bobble::ShipBobble;
use crate::models::ship::ship_module::ship_engine_color::ShipEngineColor;
use crate::models::ship::ship_module::ship_kit_module::ShipKitModule;
use crate::models::ship::ship_module::ship_string_lights::ShipStringLights;
use crate::models::ship::ship_module::ship_weapon_color::ShipWeaponColor;

use crate::modules::models::ship::ship_module::ship_decal::ShipDecal;
use crate::modules::models::ship::ship_module::ship_nameplate::ShipNameplate;
Expand All @@ -20,6 +24,10 @@ pub mod ship_nameplate;
pub mod ship_paint_job;
pub mod ship_voicepack;
pub mod ship_engine_color;
mod ship_kit_module;
mod ship_bobble;
mod ship_weapon_color;
mod ship_string_lights;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum ShipModule {
Expand Down Expand Up @@ -51,6 +59,7 @@ pub enum ShipModule {
#[serde(untagged)]
Cockpit(ShipCockpitModule),

// Cosmetic
#[serde(untagged)]
PaintJob(ShipPaintJob),

Expand All @@ -66,6 +75,18 @@ pub enum ShipModule {
#[serde(untagged)]
EngineColor(ShipEngineColor),

#[serde(untagged)]
WeaponColor(ShipWeaponColor),

#[serde(untagged)]
ShipKitModule(ShipKitModule),

#[serde(untagged)]
Bobble(ShipBobble),

#[serde(untagged)]
StringLights(ShipStringLights),

#[cfg(not(feature = "strict"))]
#[serde(untagged)]
Unknown(String),
Expand All @@ -86,6 +107,10 @@ impl Display for ShipModule {
ShipModule::VoicePack(_) => write!(f, "Voicepack"),
ShipModule::Nameplate(_) => write!(f, "Nameplate"),
ShipModule::EngineColor(_) => write!(f, "Engine Color"),
ShipModule::WeaponColor(_) => write!(f, "Weapon Color"),
ShipModule::Bobble(_) => write!(f, "Bobble"),
ShipModule::StringLights(_) => write!(f, "String Lights"),
ShipModule::ShipKitModule(module) => write!(f, "Skip kit module: {}", module.name),

#[cfg(not(feature = "strict"))]
ShipModule::Unknown(unknown) => write!(f, "Unknown module: {}", unknown),
Expand Down
41 changes: 41 additions & 0 deletions src/modules/models/ship/ship_module/ship_bobble.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::str::FromStr;
use lazy_static::lazy_static;
use regex::Regex;
use serde::Serialize;
use thiserror::Error;
use crate::from_str_deserialize_impl;

#[derive(Debug, Serialize, Clone, PartialEq)]
pub struct ShipBobble {
pub name: String,
}

#[derive(Debug, Error)]
pub enum ShipBobbleError {
#[error("Failed to parse bobble: '{0}'")]
FailedToParse(String),
}

lazy_static! {
static ref BOBBLE_REGEX: Regex = Regex::new(r#"^bobble_(\w+)$"#).unwrap();
}

impl FromStr for ShipBobble {
type Err = ShipBobbleError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let Some(captures) = BOBBLE_REGEX.captures(s) else {
return Err(ShipBobbleError::FailedToParse(s.to_string()));
};

Ok(ShipBobble {
name: captures
.get(1)
.expect("Should have been captured already")
.as_str()
.to_string(),
})
}
}

from_str_deserialize_impl!(ShipBobble);
16 changes: 13 additions & 3 deletions src/modules/models/ship/ship_module/ship_engine_color.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::str::FromStr;
use lazy_static::lazy_static;
use regex::Regex;
use serde::Serialize;
use thiserror::Error;
use crate::from_str_deserialize_impl;
Expand All @@ -14,16 +16,24 @@ pub enum ShipEngineColorError {
FailedToParse(String),
}

lazy_static! {
static ref ENGINE_COLOR_REGEX: Regex = Regex::new(r#"^enginecustomisation_(\w+)$"#).unwrap();
}

impl FromStr for ShipEngineColor {
type Err = ShipEngineColorError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if !s.starts_with("enginecustomisation_") {
let Some(captures) = ENGINE_COLOR_REGEX.captures(s) else {
return Err(ShipEngineColorError::FailedToParse(s.to_string()));
}
};

Ok(ShipEngineColor {
name: s.to_string(),
name: captures
.get(1)
.expect("Should have been captured already")
.as_str()
.to_string(),
})
}
}
Expand Down
64 changes: 64 additions & 0 deletions src/modules/models/ship/ship_module/ship_kit_module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::num::ParseIntError;
use std::str::FromStr;
use lazy_static::lazy_static;
use regex::Regex;
use serde::Serialize;
use thiserror::Error;
use crate::from_str_deserialize_impl;
use crate::models::ship::ship_type::ShipType;

#[derive(Debug, Serialize, Clone, PartialEq)]
pub struct ShipKitModule {
pub ship: ShipType,
pub kit_nr: u8,
pub name: String,
}

#[derive(Debug, Error)]
pub enum ShipKitModuleError {
#[error("Failed to parse ship kit number: {0}")]
FailedToParseShipKitNr(#[from] ParseIntError),

#[error("Failed to parse skip type for ship kit: {0}")]
FailedToParseShipType(#[from] serde_json::Error),

#[error("Failed to parse ship kit module: '{0}'")]
FailedToParse(String),
}

lazy_static! {
static ref SHIP_KIT_MODULE_REGEX: Regex = Regex::new(r#"^([a-z0-9_]+?)_shipkit(\d)(\w+)$"#).unwrap();
}

impl FromStr for ShipKitModule {
type Err = ShipKitModuleError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let Some(captures) = SHIP_KIT_MODULE_REGEX.captures(s) else {
return Err(ShipKitModuleError::FailedToParse(s.to_string()));
};

let ship = captures.get(1)
.expect("Should have been captured already")
.as_str()
.parse()?;

let kit_nr = captures.get(2)
.expect("Should have been captured already")
.as_str()
.parse()?;

let name = captures.get(3)
.expect("Should have been captured already")
.as_str()
.to_string();

Ok(ShipKitModule {
ship,
kit_nr,
name,
})
}
}

from_str_deserialize_impl!(ShipKitModule);
Loading

0 comments on commit 60c92a1

Please sign in to comment.