diff options
author | hop311 <hop3114@gmail.com> | 2024-07-24 01:05:45 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-07-24 01:05:45 +0200 |
commit | a9a88a481dbae11eddd6c2268014923a955e38c3 (patch) | |
tree | 997ac4ffbbc6e19f2ae606607223fba7ee64e688 | |
parent | d1f3a96b72dd06b5f97dd4643e5f016a02b42ea6 (diff) |
Load bookmark position as fvec2_t with height flippedbookmark-position
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/history/Bookmark.cpp | 23 | ||||
-rw-r--r-- | src/openvic-simulation/history/Bookmark.hpp | 11 |
4 files changed, 23 insertions, 19 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 2058ce5..77d0baa 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -1007,6 +1007,7 @@ bool Dataloader::load_defines(DefinitionManager& definition_manager) { ret = false; } if (!definition_manager.get_history_manager().get_bookmark_manager().load_bookmark_file( + definition_manager.get_map_definition().get_height(), parse_defines(lookup_file(bookmark_file)).get_file_node() )) { Logger::error("Failed to load bookmarks!"); diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 18faffb..7694e3b 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -590,6 +590,13 @@ namespace OpenVic { return callback(val); }; } + + template<typename T> + constexpr Callback<T> auto flip_height_callback(Callback<T> auto&& callback, T height) { + return [callback, height](T val) -> bool { + return callback(height - val); + }; + } } } diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp index d42bd69..d214260 100644 --- a/src/openvic-simulation/history/Bookmark.cpp +++ b/src/openvic-simulation/history/Bookmark.cpp @@ -15,26 +15,24 @@ Bookmark::Bookmark( 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 + fvec2_t new_initial_camera_position ) : HasIdentifier { std::to_string(new_index) }, HasIndex { new_index }, name { new_name }, description { new_description }, date { new_date }, - initial_camera_x { new_initial_camera_x }, - initial_camera_y { new_initial_camera_y } {} + initial_camera_position { new_initial_camera_position } {} bool BookmarkManager::add_bookmark( - std::string_view name, std::string_view description, Date date, uint32_t initial_camera_x, uint32_t initial_camera_y + std::string_view name, std::string_view description, Date date, fvec2_t initial_camera_position ) { - return bookmarks.add_item({ bookmarks.size(), name, description, date, initial_camera_x, initial_camera_y }); + return bookmarks.add_item({ bookmarks.size(), name, description, date, initial_camera_position }); } -bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) { +bool BookmarkManager::load_bookmark_file(fixed_point_t map_height, ast::NodeCPtr root) { const bool ret = expect_dictionary_reserve_length( bookmarks, - [this](std::string_view key, ast::NodeCPtr value) -> bool { + [this, map_height](std::string_view key, ast::NodeCPtr value) -> bool { if (key != "bookmark") { Logger::error("Invalid bookmark declaration ", key); return false; @@ -42,17 +40,18 @@ bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) { std::string_view name, description; Date date; - uint32_t initial_camera_x, initial_camera_y; + fvec2_t initial_camera_position; 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)) + "cameraX", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(initial_camera_position.x)), + "cameraY", ONE_EXACTLY, + expect_fixed_point(flip_height_callback(assign_variable_callback(initial_camera_position.y), map_height)) )(value); - ret &= add_bookmark(name, description, date, initial_camera_x, initial_camera_y); + ret &= add_bookmark(name, description, date, initial_camera_position); return ret; } )(root); diff --git a/src/openvic-simulation/history/Bookmark.hpp b/src/openvic-simulation/history/Bookmark.hpp index d945d41..b49cbe9 100644 --- a/src/openvic-simulation/history/Bookmark.hpp +++ b/src/openvic-simulation/history/Bookmark.hpp @@ -16,16 +16,14 @@ namespace OpenVic { std::string PROPERTY(name); std::string PROPERTY(description); const Date PROPERTY(date); - const uint32_t PROPERTY(initial_camera_x); - const uint32_t PROPERTY(initial_camera_y); + const fvec2_t PROPERTY(initial_camera_position); Bookmark( index_t new_index, 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 + fvec2_t new_initial_camera_position ); public: @@ -38,10 +36,9 @@ namespace OpenVic { public: bool add_bookmark( - std::string_view name, std::string_view description, Date date, uint32_t initial_camera_x, - uint32_t initial_camera_y + std::string_view name, std::string_view description, Date date, fvec2_t initial_camera_position ); - bool load_bookmark_file(ast::NodeCPtr root); + bool load_bookmark_file(fixed_point_t map_height, ast::NodeCPtr root); Date get_last_bookmark_date() const; }; |