diff options
Diffstat (limited to 'cardset.cpp')
-rw-r--r-- | cardset.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cardset.cpp b/cardset.cpp new file mode 100644 index 0000000..4003eed --- /dev/null +++ b/cardset.cpp | |||
@@ -0,0 +1,66 @@ | |||
1 | #include "cardset.h" | ||
2 | |||
3 | #include <hkutil/string.h> | ||
4 | |||
5 | #include <fstream> | ||
6 | #include <json.hpp> | ||
7 | #include <sstream> | ||
8 | |||
9 | cardset::cardset(std::string filename) { | ||
10 | std::ifstream in(filename, std::ios::in | std::ios::binary); | ||
11 | std::ostringstream contents; | ||
12 | contents << in.rdbuf(); | ||
13 | |||
14 | nlohmann::json cardsJson = nlohmann::json::parse(contents.str()); | ||
15 | |||
16 | for (const auto& cardJson : cardsJson) { | ||
17 | if ( | ||
18 | // The object needs to be a card | ||
19 | cardJson["object"] == "card" && | ||
20 | // It needs to have a downloadable image | ||
21 | cardJson.count("image_uris") && | ||
22 | // Make sure we can support the card layout | ||
23 | (cardJson["layout"] == "normal" || cardJson["layout"] == "leveler" || | ||
24 | cardJson["layout"] == "saga") && | ||
25 | // Digital cards look slightly different so ignore them | ||
26 | !cardJson["digital"] && | ||
27 | // Only use english printings | ||
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 | |||
53 | size_t cardId = cards_.size(); | ||
54 | cards_.emplace_back(cardId, cardJson["name"], | ||
55 | cardJson["image_uris"]["png"], frame, cardJson["id"]); | ||
56 | |||
57 | std::string canon = hatkirby::lowercase(cardJson["name"]); | ||
58 | |||
59 | for (int i = 0; i < canon.length(); i++) { | ||
60 | titles_.add(canon, {cardId, i}, i); | ||
61 | |||
62 | chars_.insert(canon.at(i)); | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | } | ||