summary refs log tree commit diff stats
path: root/cardset.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cardset.cpp')
-rw-r--r--cardset.cpp61
1 files changed, 18 insertions, 43 deletions
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) {
14 nlohmann::json cardsJson = nlohmann::json::parse(contents.str()); 14 nlohmann::json cardsJson = nlohmann::json::parse(contents.str());
15 15
16 for (const auto& cardJson : cardsJson) { 16 for (const auto& cardJson : cardsJson) {
17 if ( 17 // We're pre-processing the cardset now to reduce the work done here (but
18 // The object needs to be a card 18 // mostly the space taken by the data).
19 cardJson["object"] == "card" && 19 card_frame frame;
20 // It needs to have a downloadable image 20
21 cardJson.count("image_uris") && 21 if (cardJson["frame"] == "2015") {
22 // Make sure we can support the card layout 22 frame = card_frame::m2015;
23 (cardJson["layout"] == "normal" || cardJson["layout"] == "leveler" || 23 } else if (cardJson["frame"] == "2003") {
24 cardJson["layout"] == "saga") && 24 frame = card_frame::modern;
25 // Digital cards look slightly different so ignore them 25 } else {
26 !cardJson["digital"] && 26 continue;
27 // Only use english printings 27 }
28 cardJson["lang"] == "en" &&
29 // Currently not supporting silver bordered cards
30 cardJson["border_color"] != "silver" &&
31 // It is hard to read the name of a planeswalker
32 cardJson["type_line"].get<std::string>().find("Planeswalker") ==
33 std::string::npos &&
34 // This cuts out checklists and special tokens
35 cardJson["type_line"] != "Card" &&
36 // Amonkhet invocations are impossible
37 cardJson["set"] != "mp2" &&
38 // Unknown Event is not a real thing huh
39 cardJson["set"] != "da1" &&
40 // Ignore cards with the special legendary flare
41 (!cardJson.count("frame_effects") ||
42 !cardJson["frame_effects"].count("legendary"))) {
43 card_frame frame;
44
45 if (cardJson["frame"] == "2015") {
46 frame = card_frame::m2015;
47 } else if (cardJson["frame"] == "2003") {
48 frame = card_frame::modern;
49 } else {
50 continue;
51 }
52 28
53 size_t cardId = cards_.size(); 29 size_t cardId = cards_.size();
54 cards_.emplace_back(cardId, cardJson["name"], 30 cards_.emplace_back(cardId, cardJson["name"], cardJson["imageUri"], frame,
55 cardJson["image_uris"]["png"], frame, cardJson["id"]); 31 cardJson["id"], cardJson["artist"]);
56 32
57 std::string canon = hatkirby::lowercase(cardJson["name"]); 33 std::string canon = hatkirby::lowercase(cardJson["name"]);
58 34
59 for (int i = 0; i < canon.length(); i++) { 35 for (int i = 0; i < canon.length(); i++) {
60 titles_.add(canon, {cardId, i}, i); 36 titles_.add(canon, {cardId, i}, i);
61 37
62 chars_.insert(canon.at(i)); 38 chars_.insert(canon.at(i));
63 }
64 } 39 }
65 } 40 }
66} 41}