-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Continue working through failing logs
- Loading branch information
Showing
20 changed files
with
377 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.