card pack meta
This commit is contained in:
parent
ecf9302ef5
commit
cf7b5367f8
2 changed files with 65 additions and 4 deletions
|
@ -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<String>,
|
||||
pub description: Option<String>,
|
||||
/// Whether or not this is an official card pack
|
||||
official: bool,
|
||||
pub official: bool,
|
||||
/// White card data
|
||||
pub white: Option<Vec<CardWhite>>,
|
||||
/// Black card data
|
||||
|
|
|
@ -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<String>,
|
||||
pack: u8,
|
||||
num_white: usize,
|
||||
num_black: usize,
|
||||
}
|
||||
|
||||
/// Parse json for card data
|
||||
fn load_cards_from_json(path: &str) -> Result<Vec<CardSet>> {
|
||||
let data: String =
|
||||
|
@ -23,7 +33,58 @@ fn load_cards_from_json(path: &str) -> Result<Vec<CardSet>> {
|
|||
let jayson: Vec<CardSet> =
|
||||
serde_json::from_str(&data).with_context(|| format!("\"{path}\" is invalid json"))?;
|
||||
|
||||
Ok(jayson)
|
||||
let mut official: Vec<CardSet> = vec![];
|
||||
let mut official_meta: Vec<CardPackMeta> = vec![];
|
||||
|
||||
let mut unofficial: Vec<CardSet> = vec![];
|
||||
let mut unofficial_meta: Vec<CardPackMeta> = vec![];
|
||||
|
||||
for set in jayson {
|
||||
let mut num_white = 0;
|
||||
let mut num_black = 0;
|
||||
let mut pack: Option<u8> = 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
|
||||
|
|
Loading…
Add table
Reference in a new issue