diff --git a/lib/src/models.rs b/lib/src/models.rs index b74d014..df31f00 100644 --- a/lib/src/models.rs +++ b/lib/src/models.rs @@ -101,11 +101,11 @@ pub struct CardBlack { #[derive(Debug, Serialize, Deserialize)] pub struct CardSet { /// Name of the pack - name: String, + pub name: String, /// Pack Description - description: Option, + pub description: Option, /// Whether or not this is an official card pack - official: bool, + pub official: bool, /// White card data pub white: Option>, /// Black card data diff --git a/server/src/main.rs b/server/src/main.rs index 0c5b989..071c838 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -16,6 +16,16 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; pub mod api; use crate::api::*; +/// Card Pack Meta +#[derive(Debug)] +pub struct CardPackMeta { + name: String, + description: Option, + pack: u8, + num_white: usize, + num_black: usize, +} + /// Parse json for card data fn load_cards_from_json(path: &str) -> Result> { let data: String = @@ -23,7 +33,58 @@ fn load_cards_from_json(path: &str) -> Result> { let jayson: Vec = serde_json::from_str(&data).with_context(|| format!("\"{path}\" is invalid json"))?; - Ok(jayson) + let mut official: Vec = vec![]; + let mut official_meta: Vec = vec![]; + + let mut unofficial: Vec = vec![]; + let mut unofficial_meta: Vec = vec![]; + + for set in jayson { + let mut num_white = 0; + let mut num_black = 0; + let mut pack: Option = Option::None; + + if let Some(white) = set.white { + num_white = white.len(); + if num_white > 0 { + pack = Some(white[0].pack) + } + } + if let Some(black) = set.black { + num_black = black.len(); + if num_black > 0 { + pack = Some(black[0].pack) + } + } + + let meta = CardPackMeta { + name: set.name, + description: set.description, + pack: pack.expect("No card pack number!"), + num_white, + num_black, + }; + + if set.official { + official_meta.push(meta); + } else { + unofficial_meta.push(meta); + } + } + + tracing::debug!("{} official", official.len()); + tracing::debug!("{} official meta", official_meta.len()); + tracing::debug!("{} unofficial", unofficial.len()); + tracing::debug!("{} unofficial meta", unofficial_meta.len()); + tracing::debug!("{:#?}", official_meta[0]); + tracing::debug!("{:#?}", unofficial_meta[0]); + + official.shrink_to_fit(); + official_meta.shrink_to_fit(); + unofficial.shrink_to_fit(); + unofficial_meta.shrink_to_fit(); + + Ok(official) } /// Parse name list