#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)); } } } }