aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/Bookmark.cpp95
-rw-r--r--src/openvic-simulation/history/Bookmark.hpp53
-rw-r--r--src/openvic-simulation/history/HistoryManager.hpp18
3 files changed, 166 insertions, 0 deletions
diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp
new file mode 100644
index 0000000..7ab96b4
--- /dev/null
+++ b/src/openvic-simulation/history/Bookmark.cpp
@@ -0,0 +1,95 @@
+#include "Bookmark.hpp"
+
+#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
+
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+
+#include "types/Date.hpp"
+#include "types/IdentifierRegistry.hpp"
+#include "utility/Logger.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+Bookmark::Bookmark(
+ std::string_view new_identifier,
+ std::string_view new_name,
+ std::string_view new_description,
+ Date new_date,
+ uint32_t new_initial_camera_x,
+ uint32_t new_initial_camera_y
+)
+ : HasIdentifier { new_identifier },
+ name { new_name },
+ description { new_description },
+ date { new_date },
+ initial_camera_x { new_initial_camera_x },
+ initial_camera_y { new_initial_camera_y } {
+}
+
+std::string_view Bookmark::get_name() const {
+ return name;
+}
+
+std::string_view Bookmark::get_description() const {
+ return description;
+}
+
+Date const& Bookmark::get_date() const {
+ return date;
+}
+
+uint32_t Bookmark::get_initial_camera_x() const {
+ return initial_camera_x;
+}
+
+uint32_t Bookmark::get_initial_camera_y() const {
+ return initial_camera_y;
+}
+
+BookmarkManager::BookmarkManager() : bookmarks { "bookmarks" } {}
+
+bool BookmarkManager::add_bookmark(
+ std::string_view identifier,
+ std::string_view name,
+ std::string_view description,
+ Date date,
+ uint32_t initial_camera_x,
+ uint32_t initial_camera_y
+) {
+ if (identifier.empty()) {
+ Logger::error("Invalid bookmark identifier - empty!");
+ return false;
+ }
+
+ return bookmarks.add_item({ identifier, name, description, date, initial_camera_x, initial_camera_y });
+}
+
+bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) {
+ bool ret = expect_dictionary(
+ [this](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key != "bookmark") {
+ Logger::error("Invalid bookmark declaration ", key);
+ return false;
+ }
+
+ std::string_view name, description;
+ Date date;
+ uint32_t initial_camera_x, initial_camera_y;
+
+ bool ret = expect_dictionary_keys(
+ "name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
+ "desc", ONE_EXACTLY, expect_string(assign_variable_callback(description)),
+ "date", ONE_EXACTLY, expect_date(assign_variable_callback(date)),
+ "cameraX", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_x)),
+ "cameraY", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_y))
+ )(value);
+
+ ret &= add_bookmark(date.to_string(), name, description, date, initial_camera_x, initial_camera_y);
+ return ret;
+ }
+ )(root);
+ lock_bookmarks();
+
+ return ret;
+} \ No newline at end of file
diff --git a/src/openvic-simulation/history/Bookmark.hpp b/src/openvic-simulation/history/Bookmark.hpp
new file mode 100644
index 0000000..ec230ca
--- /dev/null
+++ b/src/openvic-simulation/history/Bookmark.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <cstdint>
+
+#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
+
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+
+namespace OpenVic {
+ struct BookmarkManager;
+
+ struct Bookmark : HasIdentifier {
+ friend struct BookmarkManager;
+
+ private:
+ const std::string name;
+ const std::string description;
+ const Date date;
+ const uint32_t initial_camera_x;
+ const uint32_t initial_camera_y;
+
+ Bookmark(
+ std::string_view new_identifier,
+ std::string_view new_name,
+ std::string_view new_description,
+ Date new_date,
+ uint32_t new_initial_camera_x,
+ uint32_t new_initial_camera_y
+ );
+
+ public:
+ Bookmark(Bookmark&&) = default;
+
+ std::string_view get_name() const;
+ std::string_view get_description() const;
+ Date const& get_date() const;
+ uint32_t get_initial_camera_x() const;
+ uint32_t get_initial_camera_y() const;
+ };
+
+ struct BookmarkManager {
+ private:
+ IdentifierRegistry<Bookmark> bookmarks;
+
+ public:
+ BookmarkManager();
+
+ bool add_bookmark(std::string_view identifier, std::string_view name, std::string_view description, Date date, uint32_t initial_camera_x, uint32_t initial_camera_y);
+ IDENTIFIER_REGISTRY_ACCESSORS(bookmark);
+
+ bool load_bookmark_file(ast::NodeCPtr root);
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/history/HistoryManager.hpp b/src/openvic-simulation/history/HistoryManager.hpp
new file mode 100644
index 0000000..bec5359
--- /dev/null
+++ b/src/openvic-simulation/history/HistoryManager.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "openvic-simulation/history/Bookmark.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+
+namespace OpenVic {
+ struct HistoryManager {
+ private:
+ BookmarkManager bookmark_manager;
+
+ public:
+ REF_GETTERS(bookmark_manager)
+
+ inline bool load_bookmark_file(ast::NodeCPtr root) {
+ return bookmark_manager.load_bookmark_file(root);
+ }
+ };
+}