#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) { // 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["imageUri"], frame, cardJson["id"], cardJson["artist"]); 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)); } } }