From 76bc3b3677062c0c1a6b9fa08ff20d12e470159c Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 4 Nov 2024 02:19:09 -0500 Subject: Some old refactoring + some new refactoring --- cardset.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 cardset.cpp (limited to 'cardset.cpp') diff --git a/cardset.cpp b/cardset.cpp new file mode 100644 index 0000000..4003eed --- /dev/null +++ b/cardset.cpp @@ -0,0 +1,66 @@ +#include "cardset.h" + +#include + +#include +#include +#include + +cardset::cardset(std::string filename) { + std::ifstream in(filename, std::ios::in | std::ios::binary); + std::ostringstream contents; + contents << in.rdbuf(); + + 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; + } + + size_t cardId = cards_.size(); + cards_.emplace_back(cardId, cardJson["name"], + cardJson["image_uris"]["png"], frame, cardJson["id"]); + + std::string canon = hatkirby::lowercase(cardJson["name"]); + + for (int i = 0; i < canon.length(); i++) { + titles_.add(canon, {cardId, i}, i); + + chars_.insert(canon.at(i)); + } + } + } +} -- cgit 1.4.1