diff options
author | Hop311 <Hop3114@gmail.com> | 2023-10-15 16:26:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-15 16:26:39 +0200 |
commit | 3249e21104bab6002676abe00450e7bd3f682303 (patch) | |
tree | c2a13a44d4c8553f6e87193f5f437052cf1d7067 /src/openvic-simulation/dataloader | |
parent | 17847e16e14ec52eb48a6fd0d9dc36ee93e457db (diff) | |
parent | d26f9c2fb5a9666822a0f702d76b764600a390d7 (diff) |
Merge pull request #52 from OpenVicProject/tgc-compat
TGC compatibility fixes + other cleanup
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.cpp | 31 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 18 |
4 files changed, 36 insertions, 25 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index b9d7496..72e3113 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -46,8 +46,8 @@ constexpr bool path_equals(std::string_view lhs, std::string_view rhs) { } template<typename LT, typename RT> -constexpr bool filename_equals(const LT& lhs, const RT& rhs) { - std::string_view left, right; +bool filename_equals(const LT& lhs, const RT& rhs) { + std::string left, right; if constexpr (std::same_as<LT, std::filesystem::path>) left = lhs.filename().string(); else left = lhs; @@ -314,7 +314,7 @@ fs::path Dataloader::search_for_game_path(fs::path hint_path) { return _cached_paths[hint_path] = _search_for_game_path(hint_path); } -bool Dataloader::set_roots(path_vector_t new_roots) { +bool Dataloader::set_roots(path_vector_t const& new_roots) { if (!roots.empty()) { Logger::error("Overriding existing dataloader roots!"); roots.clear(); @@ -700,7 +700,7 @@ static bool _load_localisation_file(Dataloader::localisation_callback_t callback return ret; } -bool Dataloader::load_localisation_files(localisation_callback_t callback, fs::path const& localisation_dir) { +bool Dataloader::load_localisation_files(localisation_callback_t callback, fs::path const& localisation_dir) const { return apply_to_files_in_dir(localisation_dir, ".csv", [callback](fs::path path) -> bool { return _load_localisation_file(callback, parse_csv(path).get_lines()); diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp index c4cd7c7..c268a94 100644 --- a/src/openvic-simulation/dataloader/Dataloader.hpp +++ b/src/openvic-simulation/dataloader/Dataloader.hpp @@ -54,7 +54,7 @@ namespace OpenVic { static fs::path search_for_game_path(fs::path hint_path = {}); /* In reverse-load order, so base defines first and final loaded mod last */ - bool set_roots(path_vector_t new_roots); + bool set_roots(path_vector_t const& new_roots); /* REQUIREMENTS: * DAT-24 @@ -76,7 +76,7 @@ namespace OpenVic { /* Args: key, locale, localisation */ using localisation_callback_t = NodeTools::callback_t<std::string_view, locale_t, std::string_view>; - bool load_localisation_files(localisation_callback_t callback, fs::path const& localisation_dir = "localisation"); + bool load_localisation_files(localisation_callback_t callback, fs::path const& localisation_dir = "localisation") const; private: struct fshash diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index 391ffb6..c2edb18 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -360,20 +360,25 @@ node_callback_t NodeTools::expect_dictionary_key_map(key_map_t key_map) { return expect_dictionary_key_map_and_length_and_default(std::move(key_map), default_length_callback, key_value_invalid_callback); } -node_callback_t NodeTools::name_list_callback(std::vector<std::string>& list) { - return expect_list_reserve_length( - list, - expect_identifier_or_string( - [&list](std::string_view str) -> bool { - if (!str.empty()) { - list.push_back(std::string { str }); - return true; +node_callback_t NodeTools::name_list_callback(callback_t<std::vector<std::string>&&> callback) { + return [callback](ast::NodeCPtr node) -> bool { + std::vector<std::string> list; + bool ret = expect_list_reserve_length( + list, + expect_identifier_or_string( + [&list](std::string_view str) -> bool { + if (!str.empty()) { + list.push_back(std::string { str }); + return true; + } + Logger::error("Empty identifier or string"); + return false; } - Logger::error("Empty identifier or string"); - return false; - } - ) - ); + ) + )(node); + ret &= callback(std::move(list)); + return ret; + }; } callback_t<std::string_view> NodeTools::assign_variable_callback_string(std::string& var) { diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 44ac271..e98a4b0 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -123,18 +123,24 @@ namespace OpenVic { key_value_callback_t dictionary_keys_callback(key_map_t& key_map, key_value_callback_t default_callback); bool check_key_map_counts(key_map_t& key_map); + constexpr bool add_key_map_entries(key_map_t& key_map) { return true; } + template<typename... Args> + bool add_key_map_entries(key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count, node_callback_t callback, Args... args) { + bool ret = add_key_map_entry(key_map, key, expected_count, callback); + ret &= add_key_map_entries(key_map, args...); + return ret; + } + node_callback_t expect_dictionary_key_map_and_length_and_default(key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback); node_callback_t expect_dictionary_key_map_and_length(key_map_t key_map, length_callback_t length_callback); node_callback_t expect_dictionary_key_map_and_default(key_map_t key_map, key_value_callback_t default_callback); node_callback_t expect_dictionary_key_map(key_map_t key_map); template<typename... Args> - node_callback_t expect_dictionary_key_map_and_length_and_default(key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback, - std::string_view key, dictionary_entry_t::expected_count_t expected_count, node_callback_t callback, - Args... args) { + node_callback_t expect_dictionary_key_map_and_length_and_default(key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback, Args... args) { // TODO - pass return value back up (part of big key_map_t rewrite?) - add_key_map_entry(key_map, key, expected_count, callback); - return expect_dictionary_key_map_and_length_and_default(std::move(key_map), length_callback, default_callback, args...); + add_key_map_entries(key_map, args...); + return expect_dictionary_key_map_and_length_and_default(std::move(key_map), length_callback, default_callback); } template<typename... Args> @@ -177,7 +183,7 @@ namespace OpenVic { return expect_list_reserve_length(t, expect_assign(callback)); } - node_callback_t name_list_callback(std::vector<std::string>& list); + node_callback_t name_list_callback(callback_t<std::vector<std::string>&&> callback); template<typename T> callback_t<std::string_view> expect_mapped_string(string_map_t<T> const& map, callback_t<T> callback) { |