diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-24 21:21:23 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-24 21:21:23 +0100 |
commit | 21b9726e8a371c193ab326259d22dd4cd0b69898 (patch) | |
tree | 45d5eae3cd9fe3df123b1d2ff468927c352175a4 /oop2eindopdr | |
parent | 2a9f99562f17842341f5d7fc970ee1e3e30f6e25 (diff) |
fix index update + card from cache
Diffstat (limited to 'oop2eindopdr')
-rw-r--r-- | oop2eindopdr/Pokedex.cpp | 8 | ||||
-rw-r--r-- | oop2eindopdr/PokemonCard.cpp | 1 |
2 files changed, 5 insertions, 4 deletions
diff --git a/oop2eindopdr/Pokedex.cpp b/oop2eindopdr/Pokedex.cpp index ee66f4c..9418a41 100644 --- a/oop2eindopdr/Pokedex.cpp +++ b/oop2eindopdr/Pokedex.cpp @@ -44,15 +44,14 @@ void Pokedex::load_collection_local() { } void Pokedex::verify_collection() { - std::fstream* index = nullptr; - if (!cache->cache_exists("index")) index = cache->cache_get("index"); + std::fstream& index = *cache->cache_get("index"); for (PokemonCard* card : this->cards) { card->verify_files(); - if (index != nullptr) *index << card->id << "\n"; + index << card->id << "\n"; } - if (index != nullptr) index->close(); + index.close(); cache->update_cache(); } @@ -69,6 +68,7 @@ std::vector<PokemonCard*> Pokedex::search_cards_by_id_local(std::string query) { } std::vector<PokemonCard*> Pokedex::search_cards_by_id_remote(std::string query) { + std::cout << "couldn't find card in cache, trying api..." << std::endl; std::vector<PokemonCard*> api_cards = api->get_cards_by_query((std::string("name:\"") + query + "\" OR id:\"" + query + "\"").c_str()); std::vector<PokemonCard*> out; diff --git a/oop2eindopdr/PokemonCard.cpp b/oop2eindopdr/PokemonCard.cpp index 8ce18a8..51e7f59 100644 --- a/oop2eindopdr/PokemonCard.cpp +++ b/oop2eindopdr/PokemonCard.cpp @@ -80,6 +80,7 @@ void PokemonCard::raw_load_json(nlohmann::json raw_data) { } void PokemonCard::raw_load_cache(const char* cache_path) { + this->id = cache_path; this->verify_files(); std::fstream& info_json_file = *this->pokedex->cache->cache_get(std::string(cache_path) + "/info.json"); std::stringstream info_json_content; |