aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/CMakeLists.txt3
-rw-r--r--src/crepe/api/SaveManager.cpp20
-rw-r--r--src/crepe/api/SaveManager.h48
-rw-r--r--src/crepe/api/SaveManager.hpp4
4 files changed, 75 insertions, 0 deletions
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index 0bb1263..97bc6b1 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -11,6 +11,7 @@ target_sources(crepe PUBLIC
Texture.cpp
AssetManager.cpp
Sprite.cpp
+ SaveManager.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
@@ -28,4 +29,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Texture.h
AssetManager.h
AssetManager.hpp
+ SaveManager.h
+ SaveManager.hpp
)
diff --git a/src/crepe/api/SaveManager.cpp b/src/crepe/api/SaveManager.cpp
new file mode 100644
index 0000000..83ff0fa
--- /dev/null
+++ b/src/crepe/api/SaveManager.cpp
@@ -0,0 +1,20 @@
+#include "../DB.h"
+#include "util/log.h"
+
+#include "SaveManager.h"
+
+using namespace std;
+using namespace crepe;
+using namespace crepe::api;
+
+SaveManager::SaveManager() {
+ dbg_trace();
+ this->db = make_unique<DB>("./save.crepe.db");
+}
+
+SaveManager & SaveManager::get_instance() {
+ dbg_trace();
+ static SaveManager instance;
+ return instance;
+}
+
diff --git a/src/crepe/api/SaveManager.h b/src/crepe/api/SaveManager.h
new file mode 100644
index 0000000..110735d
--- /dev/null
+++ b/src/crepe/api/SaveManager.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include <memory>
+
+#include "../ValueBroker.h"
+
+namespace crepe {
+class DB;
+}
+
+namespace crepe::api {
+
+class SaveManager {
+public:
+ //! Get a reference to a value and initialize it with a value if it does not yet exist
+ template <typename T>
+ ValueBroker<T> & get(const char * key, const T & default_value);
+
+ //! Get a reference to a value
+ template <typename T>
+ ValueBroker<T> & get(const char * key);
+
+ //! Set a value directly
+ template <typename T>
+ void set(const char * key, const T & value);
+
+ //! Check if the save file has a value for this \c key
+ bool has(const char * key);
+
+private:
+ SaveManager();
+ virtual ~SaveManager() = default;
+
+public:
+ // singleton
+ static SaveManager & get_instance();
+ SaveManager(const SaveManager &) = delete;
+ SaveManager(SaveManager &&) = delete;
+ SaveManager & operator = (const SaveManager &) = delete;
+ SaveManager & operator = (SaveManager &&) = delete;
+
+private:
+ std::unique_ptr<DB> db = nullptr;
+};
+
+}
+
+#include "SaveManager.hpp"
diff --git a/src/crepe/api/SaveManager.hpp b/src/crepe/api/SaveManager.hpp
new file mode 100644
index 0000000..44f58ed
--- /dev/null
+++ b/src/crepe/api/SaveManager.hpp
@@ -0,0 +1,4 @@
+#pragma once
+
+#include "SaveManager.h"
+