From 295ee857b9b46c27e80051700278e3075590d823 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 23 Dec 2022 13:55:05 +0100 Subject: WIP --- oop2eindopdr/CacheManager.cpp | 45 ++++++++++++++++++++++++++++++++++++ oop2eindopdr/CacheManager.h | 34 +++++++++++++++++++++++++++ oop2eindopdr/DownloadManager.cpp | 0 oop2eindopdr/DownloadManager.h | 3 +++ oop2eindopdr/Pokedex.h | 19 +++++++++++++++ oop2eindopdr/PokemonCard.cpp | 30 ++++++++++++++++++++++++ oop2eindopdr/PokemonCard.h | 23 ++++++++++++++++++ oop2eindopdr/PokemonTCGAPIClient.cpp | 0 oop2eindopdr/PokemonTCGAPIClient.h | 3 +++ oop2eindopdr/ZipExport.cpp | 0 oop2eindopdr/ZipExport.h | 3 +++ oop2eindopdr/main.cpp | 6 +++++ oop2eindopdr/main.h | 5 ++++ oop2eindopdr/makefile | 1 + 14 files changed, 172 insertions(+) create mode 100644 oop2eindopdr/CacheManager.cpp create mode 100644 oop2eindopdr/CacheManager.h create mode 100644 oop2eindopdr/DownloadManager.cpp create mode 100644 oop2eindopdr/DownloadManager.h create mode 100644 oop2eindopdr/Pokedex.h create mode 100644 oop2eindopdr/PokemonCard.cpp create mode 100644 oop2eindopdr/PokemonCard.h create mode 100644 oop2eindopdr/PokemonTCGAPIClient.cpp create mode 100644 oop2eindopdr/PokemonTCGAPIClient.h create mode 100644 oop2eindopdr/ZipExport.cpp create mode 100644 oop2eindopdr/ZipExport.h create mode 100644 oop2eindopdr/main.h (limited to 'oop2eindopdr') diff --git a/oop2eindopdr/CacheManager.cpp b/oop2eindopdr/CacheManager.cpp new file mode 100644 index 0000000..7de435e --- /dev/null +++ b/oop2eindopdr/CacheManager.cpp @@ -0,0 +1,45 @@ +#include "CacheManager.h" + +#include +#include +#include +#include + +CacheManager::CacheManager(const char* cache_path) : CacheManager(std::string(cache_path)) { } +CacheManager::CacheManager(std::string cache_path) { + this->cache_path = cache_path; + this->verify_cache(); +} + +CacheManager::~CacheManager() { + for (std::fstream* file : this->files) { + if (file != nullptr) { + file->close(); + delete file; + file = nullptr; + } + } +} + +void CacheManager::verify_cache() { + if (!std::filesystem::is_directory(this->cache_path)) this->init_cache(); + this->update_cache(); +} + +void CacheManager::init_cache() { + std::filesystem::create_directory(this->cache_path); + this->update_cache(); +} + +void CacheManager::update_cache() { + std::fstream& date = *cache_get("date"); + this->age = std::time(nullptr); + date << this->age; +} + +std::fstream* CacheManager::cache_get(const char* filename) { + std::fstream* file = new std::fstream(filename, std::ios::out | std::ios::in); + this->files.push_back(file); + return file; +} + diff --git a/oop2eindopdr/CacheManager.h b/oop2eindopdr/CacheManager.h new file mode 100644 index 0000000..484871b --- /dev/null +++ b/oop2eindopdr/CacheManager.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include + +/** @brief cache storage manager */ +class CacheManager { +private: + std::string cache_path; /** @brief currently opened cache location */ + std::vector files; +public: + /** @brief initialize CacheManager class at `cache_path` */ + CacheManager(const char* cache_path); + CacheManager(std::string cache_path); + /** @brief close cache */ + virtual ~CacheManager(); + /** @brief create cache folder structure */ + virtual void init_cache(); + /** @brief update cache date */ + virtual void update_cache(); + /** + * @brief check cache file structure + * + * automatically updates chache if stale and/or creates cache when + * non-existant + */ + virtual void verify_cache(); + + /** @brief get fstream for file in cache or create file */ + virtual std::fstream* cache_get(const char* filename); + + uint64_t age; /** @brief currently opened cache update unix timestamp */ +}; + diff --git a/oop2eindopdr/DownloadManager.cpp b/oop2eindopdr/DownloadManager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/oop2eindopdr/DownloadManager.h b/oop2eindopdr/DownloadManager.h new file mode 100644 index 0000000..45dcbb0 --- /dev/null +++ b/oop2eindopdr/DownloadManager.h @@ -0,0 +1,3 @@ +#pragma once + + diff --git a/oop2eindopdr/Pokedex.h b/oop2eindopdr/Pokedex.h new file mode 100644 index 0000000..abe8bef --- /dev/null +++ b/oop2eindopdr/Pokedex.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +#include "PokemonCard.h" + +class Pokedex { +private: + std::vector cards; + virtual void add_cards(); + +public: + Pokedex(); + virtual ~Pokedex(); + + /** @brief search cards that contain `query` in id field */ + virtual PokemonCard* search_card_by_id(std::string query); +}; diff --git a/oop2eindopdr/PokemonCard.cpp b/oop2eindopdr/PokemonCard.cpp new file mode 100644 index 0000000..3d20eff --- /dev/null +++ b/oop2eindopdr/PokemonCard.cpp @@ -0,0 +1,30 @@ +#include "PokemonCard.h" + +#include +#include +#include + +using std::endl; + +std::ostream& operator << (std::ostream& output, const PokemonCard& card) { + output << "name: " << card.name << " (" << card.id << ")" << endl; + output << "HP: " << std::fixed << std::setprecision(2) << card.hp << endl; + output << "market value: " << card.value << endl; + output << "attacks: " << endl; + for (std::string attack : card.attacks) + output << "\t" << attack << endl; + + return output; +} + +PokemonCard::PokemonCard() { + +} + +PokemonCard::~PokemonCard() { + +} + +void PokemonCard::fetch_market_value() { + +} diff --git a/oop2eindopdr/PokemonCard.h b/oop2eindopdr/PokemonCard.h new file mode 100644 index 0000000..1037ffd --- /dev/null +++ b/oop2eindopdr/PokemonCard.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class PokemonCard { +public: + PokemonCard(); + 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; /** @brief pokemon max health points */ + double value; /** @brief pokemon card current market value */ + std::vector attacks; /** @brief list of possible attacks */ + + /** @brief use API to fetch `this->hp` */ + virtual void fetch_market_value(); +}; + diff --git a/oop2eindopdr/PokemonTCGAPIClient.cpp b/oop2eindopdr/PokemonTCGAPIClient.cpp new file mode 100644 index 0000000..e69de29 diff --git a/oop2eindopdr/PokemonTCGAPIClient.h b/oop2eindopdr/PokemonTCGAPIClient.h new file mode 100644 index 0000000..45dcbb0 --- /dev/null +++ b/oop2eindopdr/PokemonTCGAPIClient.h @@ -0,0 +1,3 @@ +#pragma once + + diff --git a/oop2eindopdr/ZipExport.cpp b/oop2eindopdr/ZipExport.cpp new file mode 100644 index 0000000..e69de29 diff --git a/oop2eindopdr/ZipExport.h b/oop2eindopdr/ZipExport.h new file mode 100644 index 0000000..45dcbb0 --- /dev/null +++ b/oop2eindopdr/ZipExport.h @@ -0,0 +1,3 @@ +#pragma once + + diff --git a/oop2eindopdr/main.cpp b/oop2eindopdr/main.cpp index 5eb8beb..c042ffe 100644 --- a/oop2eindopdr/main.cpp +++ b/oop2eindopdr/main.cpp @@ -1,9 +1,15 @@ #include #include +#include "main.h" +#include "Pokedex.h" +#include "PokemonCard.h" + using std::endl; using std::cout; +Pokedex* g_pokedex = nullptr; + int interactive_mode() { std::string gert; bool user_exit = false; diff --git a/oop2eindopdr/main.h b/oop2eindopdr/main.h new file mode 100644 index 0000000..0263d62 --- /dev/null +++ b/oop2eindopdr/main.h @@ -0,0 +1,5 @@ +#pragma once + +#include "Pokedex.h" + +extern Pokedex* g_pokedex; diff --git a/oop2eindopdr/makefile b/oop2eindopdr/makefile index a4235d4..e0992ef 100644 --- a/oop2eindopdr/makefile +++ b/oop2eindopdr/makefile @@ -4,6 +4,7 @@ RM = rm -f TARGET = main OUTPUT_ZIP = Eindopdracht_2180996.zip +CFLAGS += -std=c++17 LFLAGS += -lstdc++ SRCS := $(wildcard *.cpp) -- cgit v1.2.3