diff options
Diffstat (limited to 'src/openvic-simulation/history/Bookmark.cpp')
-rw-r--r-- | src/openvic-simulation/history/Bookmark.cpp | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp index b758867..ee7b494 100644 --- a/src/openvic-simulation/history/Bookmark.cpp +++ b/src/openvic-simulation/history/Bookmark.cpp @@ -23,27 +23,30 @@ bool BookmarkManager::add_bookmark( } bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) { - const bool ret = expect_dictionary([this](std::string_view key, ast::NodeCPtr value) -> bool { - if (key != "bookmark") { - Logger::error("Invalid bookmark declaration ", key); - return false; + const bool ret = expect_dictionary_reserve_length( + bookmarks, + [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(name, description, date, initial_camera_x, initial_camera_y); + return ret; } - - 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(name, description, date, initial_camera_x, initial_camera_y); - return ret; - })(root); + )(root); lock_bookmarks(); return ret; |