blob: 1bbd3c771b3b62dd8531928fe3879d88611b149a (
plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#pragma once
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
#include <thread>
class Pokedex;
/** @brief single pokemon card */
class PokemonCard {
private:
/** @brief raw API card data */
nlohmann::json raw_data;
/** @brief load card data from json data (see named constructor) */
virtual void raw_load_json(nlohmann::json raw_data);
/** @brief load card data from cache (see named constructor) */
virtual void raw_load_cache(const char* cache_path);
/** @brief pokedex reference (for API access in ::fetch_market_value) */
Pokedex* pokedex = nullptr;
/** @brief add cache path before filename */
virtual std::string prefix_cache_path(const char* filename);
/** @brief thread that creates `complete` file when both images are downloaded */
std::thread* image_download_thread = nullptr;
/** @brief image API url */
std::string url_card_normal = "";
/** @brief image API url */
std::string url_card_hires = "";
public:
PokemonCard(Pokedex* pokedex = nullptr);
virtual ~PokemonCard();
/** @brief string stream output (for printing card) */
friend std::ostream& operator << (std::ostream& output, const PokemonCard& card);
std::string id = ""; /** @brief pokemon id (with set prefix) */
std::string name = ""; /** @brief pokemon name */
unsigned hp = 0; /** @brief pokemon max health points */
double value = 0.f; /** @brief pokemon card current market value */
std::vector<std::string> attacks = {}; /** @brief list of possible attacks */
/** @brief get short card identifier: "Name (ID)" */
virtual std::string short_identifier();
/** @brief use API to fetch `this->hp` */
virtual void fetch_market_value();
/** @brief check if all files are downloaded */
virtual void verify_files();
/** @brief download images */
virtual void download_files();
struct from_json; // named constructors (defined below)
struct from_cache;
/** @brief set cache */
virtual void set_pokedex(Pokedex* pokedex);
/** @brief get (relative) path to card image */
virtual std::string image_location();
/** @brief get (relative) path to hires card image */
virtual std::string image_location_hires();
};
struct PokemonCard::from_json : public PokemonCard {
from_json(nlohmann::json json_data) : PokemonCard() {
PokemonCard::raw_load_json(json_data);
}
};
struct PokemonCard::from_cache : public PokemonCard {
from_cache(Pokedex* pokedex, std::string cache_path) : PokemonCard(pokedex) {
PokemonCard::raw_load_cache(cache_path.c_str());
}
};
|