Added UUID

And fixed up the fact the promo types are optionally null/not there/empty/full
This commit is contained in:
2025-02-04 22:40:51 +00:00
parent 2dd4f3d696
commit f576fe6cc8
2 changed files with 26 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
use serde::{Deserialize};
use serde::Deserialize;
use uuid::Uuid;
// Info from here:
// https://scryfall.com/docs/api/cards
@@ -7,7 +8,7 @@ use serde::{Deserialize};
struct ScryfallCard {
// Core Card Fields
pub arena_id: Option<u64>,
pub id: String, // UUID - internal for Scryfall
pub id: Uuid,
pub lang: String,
pub mtgo: Option<u64>,
pub mtgo_foil_id: Option<u64>,
@@ -17,7 +18,7 @@ struct ScryfallCard {
pub cardmarket_id: Option<u64>,
pub object: String,
pub layout: String, // Perhaps some kind of enum of these: https://scryfall.com/docs/api/layouts?
pub oracle_id: Option<String>, // UUID
pub oracle_id: Option<Uuid>,
pub prints_search_uri: String, // URI
pub rulings_uri: String, // URI
pub scryfall_uri: String, // URI
@@ -62,7 +63,7 @@ struct ScryfallCard {
pub booster: bool,
#[serde(rename = "border_color")]
pub border_colour: BorderColour,
pub card_back_id: String, // UUID
pub card_back_id: Uuid,
pub collector_number: String,
pub content_warning: Option<bool>,
pub digital: bool,
@@ -76,7 +77,7 @@ struct ScryfallCard {
pub full_art: bool,
pub games: Vec<Game>,
pub highres_image: bool,
pub illustration_id: Option<String>, // UUID
pub illustration_id: Option<Uuid>,
pub image_status: ImageStatus,
pub image_uris: ImageURIs,
pub oversized: bool,
@@ -85,8 +86,8 @@ struct ScryfallCard {
pub printed_text: Option<String>,
pub printed_type_line: Option<String>,
pub promo: bool,
pub promo_types: Vec<String>, // TODO: Check what types exist - could be a enumeratable selection
pub purchase_uris: Option<Vec<bool>>, // FIXME
pub promo_types: Option<Vec<String>>, // TODO: Check what types exist - could be a enumeratable selection
//pub purchase_uris: Option<Vec<bool>>, // FIXME
pub rarity: Rarity,
// TODO - the rest (and the purachase URIs above)
}
@@ -96,7 +97,7 @@ struct ScryfallCard {
#[derive(Deserialize, Debug)]
struct ScryfallCardFaceObject {
pub artist: Option<String>,
pub artist_id: Option<String>, // UUID
pub artist_id: Option<Uuid>, // UUID
pub cmc: Option<f64>, // TODO: Make this a proper Decimal - see "Little Girl" card for example of cmc of 0.5
#[serde(rename = "color_identity")]
pub colour_identity: Vec<Colour>,
@@ -112,7 +113,7 @@ struct ScryfallCardFaceObject {
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct ScryfallRelatedCardObject {
pub id: String, // UUID
pub id: Uuid,
pub object: String, // Always "related_card"
pub component: String, // One of token, meld_part, meld_result, combo_piece
pub name: String,
@@ -370,4 +371,19 @@ mod tests {
let lg: ScryfallCard = serde_json::from_str(&fc).unwrap();
println!("{:#?}", lg);
}
#[test]
#[ignore]
fn try_deserialise_all_cards() {
// TODO Actually write this funtion.
// The idea will be to run over one of the Scryfall dumps of all the cards so I can be
// confident I've got things working.
// I noticed that Scryfall very helpfully provides their dumps with 1 card per line.
// So using something like the link below should hopefully mean I don't have to load in the
// whole 2+GB file all at once
// https://doc.rust-lang.org/std/io/trait.BufRead.html#method.lines
// I think that's what it should do at least. I bet it'll still take a while tho.
// If that doesn't work - I should try somehow use the serde from_reader function
// I don't 100% know how I'll use that though.
}
}