blob: 4003eedb963e5de6315c3a9f9b7b4cb1bda349a1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "cardset.h"
#include <hkutil/string.h>
#include <fstream>
#include <json.hpp>
#include <sstream>
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<std::string>().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));
}
}
}
}
|