aboutsummaryrefslogtreecommitdiff
path: root/oop2eindopdr/PokemonCard.cpp
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-24 13:37:21 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-24 13:37:21 +0100
commit2590dd61794f0e2fdf5dd0f1bbf7f71791df8d0c (patch)
tree2e8d63025b0c5bfd7ac38fa1e7bfef70322fd92e /oop2eindopdr/PokemonCard.cpp
parent95f1aca8b061e60f81f636349e0b9ff76a114bb0 (diff)
downloading and parsing swshp set works
Diffstat (limited to 'oop2eindopdr/PokemonCard.cpp')
-rw-r--r--oop2eindopdr/PokemonCard.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/oop2eindopdr/PokemonCard.cpp b/oop2eindopdr/PokemonCard.cpp
index 9c4b8a7..69a6e61 100644
--- a/oop2eindopdr/PokemonCard.cpp
+++ b/oop2eindopdr/PokemonCard.cpp
@@ -1,6 +1,7 @@
#include "PokemonCard.h"
#include <iostream>
+#include <fstream>
#include <sstream>
#include <iomanip>
@@ -18,7 +19,8 @@ std::ostream& operator << (std::ostream& output, const PokemonCard& card) {
}
PokemonCard::PokemonCard(CacheManager* cache_ref) {
-
+ set_cache(cache_ref);
+ if (this->cache_ref == nullptr) return;
}
PokemonCard::~PokemonCard() {
@@ -28,3 +30,40 @@ PokemonCard::~PokemonCard() {
void PokemonCard::fetch_market_value() {
}
+
+void PokemonCard::set_cache(CacheManager* cache_ref) {
+ this->cache_ref = cache_ref;
+}
+
+void PokemonCard::verify_files() {
+
+}
+
+void PokemonCard::download_files() {
+
+}
+
+void PokemonCard::raw_load_json(nlohmann::json raw_data) {
+ this->id = raw_data["id"].get<std::string>();
+ this->name = raw_data["name"].get<std::string>();
+ try {
+ this->hp = std::stoul(raw_data["hp"].get<std::string>());
+ } catch (nlohmann::json::type_error) {
+ this->hp = 0; // some NPCs/auxiliary cards have hp = null
+ }
+ this->value = 0.f; // fetch using fetch_market_value
+ for (nlohmann::json raw_attack : raw_data["attacks"])
+ this->attacks.push_back(raw_attack["name"]);
+}
+
+void PokemonCard::raw_load_cache(const char* cache_path) {
+ std::string info_json_location = cache_path;
+ info_json_location.append("/info.json");
+ this->verify_files();
+ std::fstream& info_json_file = *this->cache_ref->cache_get(info_json_location.c_str());
+ std::stringstream info_json_content;
+ info_json_content << info_json_file.rdbuf();
+
+ nlohmann::json raw_json = nlohmann::json::parse(info_json_content.str());
+ this->raw_load_json(raw_json);
+}