aboutsummaryrefslogtreecommitdiff
path: root/oop2eindopdr
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-23 13:55:05 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-23 13:55:05 +0100
commit295ee857b9b46c27e80051700278e3075590d823 (patch)
tree276bbadb556312e8cf6981962ef1b341bb0d2010 /oop2eindopdr
parent9eb8aa6bab40bd58e70cb6124e462e1a3d47edb7 (diff)
WIP
Diffstat (limited to 'oop2eindopdr')
-rw-r--r--oop2eindopdr/CacheManager.cpp45
-rw-r--r--oop2eindopdr/CacheManager.h34
-rw-r--r--oop2eindopdr/DownloadManager.cpp0
-rw-r--r--oop2eindopdr/DownloadManager.h3
-rw-r--r--oop2eindopdr/Pokedex.h19
-rw-r--r--oop2eindopdr/PokemonCard.cpp30
-rw-r--r--oop2eindopdr/PokemonCard.h23
-rw-r--r--oop2eindopdr/PokemonTCGAPIClient.cpp0
-rw-r--r--oop2eindopdr/PokemonTCGAPIClient.h3
-rw-r--r--oop2eindopdr/ZipExport.cpp0
-rw-r--r--oop2eindopdr/ZipExport.h3
-rw-r--r--oop2eindopdr/main.cpp6
-rw-r--r--oop2eindopdr/main.h5
-rw-r--r--oop2eindopdr/makefile1
14 files changed, 172 insertions, 0 deletions
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 <filesystem>
+#include <fstream>
+#include <iostream>
+#include <ctime>
+
+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 <string>
+#include <vector>
+
+/** @brief cache storage manager */
+class CacheManager {
+private:
+ std::string cache_path; /** @brief currently opened cache location */
+ std::vector<std::fstream*> 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
--- /dev/null
+++ b/oop2eindopdr/DownloadManager.cpp
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 <string>
+#include <vector>
+
+#include "PokemonCard.h"
+
+class Pokedex {
+private:
+ std::vector<PokemonCard*> 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 <iostream>
+#include <sstream>
+#include <iomanip>
+
+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 <string>
+#include <vector>
+
+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<std::string> 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
--- /dev/null
+++ b/oop2eindopdr/PokemonTCGAPIClient.cpp
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
--- /dev/null
+++ b/oop2eindopdr/ZipExport.cpp
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 <cstdlib>
#include <iostream>
+#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)