diff options
Diffstat (limited to 'oop2eindopdr/Pokedex.cpp')
-rw-r--r-- | oop2eindopdr/Pokedex.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/oop2eindopdr/Pokedex.cpp b/oop2eindopdr/Pokedex.cpp index c55469a..7cd2dc9 100644 --- a/oop2eindopdr/Pokedex.cpp +++ b/oop2eindopdr/Pokedex.cpp @@ -65,7 +65,7 @@ std::string Pokedex::lower(std::string input) { return out; } -std::vector<PokemonCard*> Pokedex::search_cards_by_id_local(std::string query) { +std::vector<PokemonCard*> Pokedex::search_cards_local(std::string query) { std::vector<PokemonCard*> out(this->cards.size()); // https://cplusplus.com/reference/algorithm/copy_if/ @@ -78,7 +78,7 @@ std::vector<PokemonCard*> Pokedex::search_cards_by_id_local(std::string query) { return out; } -std::vector<PokemonCard*> Pokedex::search_cards_by_id_remote(std::string query) { +std::vector<PokemonCard*> Pokedex::search_cards_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; @@ -99,10 +99,16 @@ std::vector<PokemonCard*> Pokedex::search_cards_by_id_remote(std::string query) return out; } -std::vector<PokemonCard*> Pokedex::search_cards_by_id(std::string query) { - std::vector<PokemonCard*> out = search_cards_by_id_local(query); - if (out.size() == 0) out = search_cards_by_id_remote(query); +std::vector<PokemonCard*> Pokedex::search_cards(std::string query) { + std::vector<PokemonCard*> out = search_cards_local(query); + if (out.size() == 0) out = search_cards_remote(query); return out; } +PokemonCard* Pokedex::get_card_by_id(std::string id) { + for (PokemonCard* card : this->cards) + if (card->id == id) return card; + return nullptr; +} + |