From 4bc851544831e37b6173d0ad05806fd841e216fb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 4 Nov 2024 20:42:36 -0500 Subject: Re-attempt 10 times, some tweaks to OCR, pre-filter card pool --- cardset.cpp | 61 ++++++++++++++++++------------------------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) (limited to 'cardset.cpp') diff --git a/cardset.cpp b/cardset.cpp index 4003eed..8097834 100644 --- a/cardset.cpp +++ b/cardset.cpp @@ -14,53 +14,28 @@ cardset::cardset(std::string filename) { nlohmann::json cardsJson = nlohmann::json::parse(contents.str()); for (const auto& cardJson : cardsJson) { - if ( - // The object needs to be a card - cardJson["object"] == "card" && - // It needs to have a downloadable image - cardJson.count("image_uris") && - // Make sure we can support the card layout - (cardJson["layout"] == "normal" || cardJson["layout"] == "leveler" || - cardJson["layout"] == "saga") && - // Digital cards look slightly different so ignore them - !cardJson["digital"] && - // Only use english printings - cardJson["lang"] == "en" && - // Currently not supporting silver bordered cards - cardJson["border_color"] != "silver" && - // It is hard to read the name of a planeswalker - cardJson["type_line"].get().find("Planeswalker") == - std::string::npos && - // This cuts out checklists and special tokens - cardJson["type_line"] != "Card" && - // Amonkhet invocations are impossible - cardJson["set"] != "mp2" && - // Unknown Event is not a real thing huh - cardJson["set"] != "da1" && - // Ignore cards with the special legendary flare - (!cardJson.count("frame_effects") || - !cardJson["frame_effects"].count("legendary"))) { - card_frame frame; - - if (cardJson["frame"] == "2015") { - frame = card_frame::m2015; - } else if (cardJson["frame"] == "2003") { - frame = card_frame::modern; - } else { - continue; - } + // We're pre-processing the cardset now to reduce the work done here (but + // mostly the space taken by the data). + card_frame frame; + + if (cardJson["frame"] == "2015") { + frame = card_frame::m2015; + } else if (cardJson["frame"] == "2003") { + frame = card_frame::modern; + } else { + continue; + } - size_t cardId = cards_.size(); - cards_.emplace_back(cardId, cardJson["name"], - cardJson["image_uris"]["png"], frame, cardJson["id"]); + size_t cardId = cards_.size(); + cards_.emplace_back(cardId, cardJson["name"], cardJson["imageUri"], frame, + cardJson["id"], cardJson["artist"]); - std::string canon = hatkirby::lowercase(cardJson["name"]); + std::string canon = hatkirby::lowercase(cardJson["name"]); - for (int i = 0; i < canon.length(); i++) { - titles_.add(canon, {cardId, i}, i); + for (int i = 0; i < canon.length(); i++) { + titles_.add(canon, {cardId, i}, i); - chars_.insert(canon.at(i)); - } + chars_.insert(canon.at(i)); } } } -- cgit 1.4.1