diff options
Diffstat (limited to 'oop2eindopdr')
-rw-r--r-- | oop2eindopdr/CacheManager.cpp | 3 | ||||
-rw-r--r-- | oop2eindopdr/CacheManager.h | 5 | ||||
-rw-r--r-- | oop2eindopdr/Pokedex.cpp | 26 | ||||
-rw-r--r-- | oop2eindopdr/Pokedex.h | 15 | ||||
-rw-r--r-- | oop2eindopdr/PokemonCard.h | 8 | ||||
-rw-r--r-- | oop2eindopdr/main.cpp | 46 |
6 files changed, 85 insertions, 18 deletions
diff --git a/oop2eindopdr/CacheManager.cpp b/oop2eindopdr/CacheManager.cpp index 5cc1121..6fffa2c 100644 --- a/oop2eindopdr/CacheManager.cpp +++ b/oop2eindopdr/CacheManager.cpp @@ -43,3 +43,6 @@ std::fstream* CacheManager::cache_get(const char* filename) { return file; } +bool CacheManager::cache_exists(const char* filename) { + return true; +} diff --git a/oop2eindopdr/CacheManager.h b/oop2eindopdr/CacheManager.h index 484871b..9587e24 100644 --- a/oop2eindopdr/CacheManager.h +++ b/oop2eindopdr/CacheManager.h @@ -28,7 +28,10 @@ public: /** @brief get fstream for file in cache or create file */ virtual std::fstream* cache_get(const char* filename); + /** @brief check if file exists in cache */ + virtual bool cache_exists(const char* filename); - uint64_t age; /** @brief currently opened cache update unix timestamp */ + /** @brief currently opened cache update unix timestamp */ + uint64_t age; }; diff --git a/oop2eindopdr/Pokedex.cpp b/oop2eindopdr/Pokedex.cpp new file mode 100644 index 0000000..67bc2dc --- /dev/null +++ b/oop2eindopdr/Pokedex.cpp @@ -0,0 +1,26 @@ +#include "Pokedex.h" + +Pokedex::Pokedex() { + +} + +Pokedex::~Pokedex() { + +} + +void Pokedex::load_collection_remote() { + +} + +void Pokedex::load_collection_local() { + +} + +void Pokedex::verify_collection() { + +} + +std::vector<PokemonCard*> Pokedex::search_cards_by_id(std::string query) { + return {}; +} + diff --git a/oop2eindopdr/Pokedex.h b/oop2eindopdr/Pokedex.h index a91b560..91a0315 100644 --- a/oop2eindopdr/Pokedex.h +++ b/oop2eindopdr/Pokedex.h @@ -9,16 +9,19 @@ class Pokedex { private: std::vector<PokemonCard*> cards; - virtual void add_cards(); + + /** @brief download card collection using API client */ + virtual void load_collection_remote(); + /** @brief load cards from cache */ + virtual void load_collection_local(); + + /** @brief verify all cards in collection */ + virtual void verify_collection(); public: Pokedex(); virtual ~Pokedex(); - virtual void download_collection(); - virtual void load_collection(); - virtual void verify_collection(); - /** @brief search cards that contain `query` in id field */ - virtual PokemonCard* search_card_by_id(std::string query); + virtual std::vector<PokemonCard*> search_cards_by_id(std::string query); }; diff --git a/oop2eindopdr/PokemonCard.h b/oop2eindopdr/PokemonCard.h index c89df9c..1b9721a 100644 --- a/oop2eindopdr/PokemonCard.h +++ b/oop2eindopdr/PokemonCard.h @@ -24,5 +24,13 @@ public: /** @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(); + + static PokemonCard* from_json(nlohmann::json raw_data); + static PokemonCard* from_cache(const char* card_path); }; diff --git a/oop2eindopdr/main.cpp b/oop2eindopdr/main.cpp index 62afcac..0ebc185 100644 --- a/oop2eindopdr/main.cpp +++ b/oop2eindopdr/main.cpp @@ -7,32 +7,56 @@ using std::endl; using std::cout; +using std::cin; Pokedex* g_pokedex = nullptr; int interactive_mode() { - std::string gert; - bool user_exit = false; - while (!user_exit) { - cout << "interactive mode" << endl; - std::cin >> gert; + cout << "entering interactive mode..." << endl; + + std::string search_query; + + for(;;) { + cout << "card id?: "; + if (!std::getline(cin, search_query)) break; + + std::vector<PokemonCard*> cards = g_pokedex->search_cards_by_id(search_query); + size_t card_count = cards.size(); + + if (card_count == 0) { + cout << "no cards found" << endl; + } else if (card_count == 1) { + cout << "found card:" << endl << *cards[0]; + } else { + cout << "found cards:" << endl; + for (PokemonCard* card : cards) + cout << *card << endl; + } } return EXIT_SUCCESS; } int export_mode(int argc, char** argv) { - cout << "export mode! let's convert " << std::string(argv[1]) << " to " << std::string(argv[2]) << endl; + std::string csv_file = argv[1]; + std::string zip_file = argc == 3 ? argv[2] : ""; + while (zip_file.size() == 0) { // make sure target file is given + cout << "zip file location?: "; + if (!std::getline(cin, zip_file)) break; + } + + cout << "export mode! let's convert " << csv_file << " to " << zip_file << endl; return EXIT_SUCCESS; } int main(int argc, char** argv) { - PokemonTCGAPIClient api_client_test; - std::vector<std::string> sets = api_client_test.get_sets(); - for (auto s : sets) - cout << s << endl; + // PokemonTCGAPIClient api_client_test; + // std::vector<std::string> sets = api_client_test.get_sets(); + // for (auto s : sets) + // cout << s << endl; - return EXIT_SUCCESS; + // return EXIT_SUCCESS; + g_pokedex = new Pokedex(); if (argc == 1) { // no arguments specified return interactive_mode(); |