diff options
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 27 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.cpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 2 |
4 files changed, 20 insertions, 17 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 267ee40..2553b7e 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -34,7 +34,7 @@ using namespace OpenVic::NodeTools; using namespace ovdl; // Windows and Mac by default act like case insensitive filesystems -constexpr bool path_equals(std::string_view lhs, std::string_view rhs) { +static constexpr bool path_equals(std::string_view lhs, std::string_view rhs) { #if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) constexpr auto ichar_equals = [](unsigned char l, unsigned char r) { return std::tolower(l) == std::tolower(r); @@ -46,7 +46,7 @@ constexpr bool path_equals(std::string_view lhs, std::string_view rhs) { } template<typename LT, typename RT> -bool filename_equals(const LT& lhs, const RT& rhs) { +static 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(); @@ -59,7 +59,7 @@ bool filename_equals(const LT& lhs, const RT& rhs) { return path_equals(left, right); } -fs::path _search_for_game_path(fs::path hint_path = {}) { +static fs::path _search_for_game_path(fs::path hint_path = {}) { // Apparently max amount of steam libraries is 8, if incorrect please correct it to the correct max amount constexpr int max_amount_of_steam_libraries = 8; constexpr std::string_view Victoria_2_folder = "Victoria 2"; @@ -452,10 +452,10 @@ csv::Windows1252Parser Dataloader::parse_csv(fs::path const& path) { return _run_ovdl_parser<csv::Windows1252Parser, &_csv_parse>(path); } -bool Dataloader::_load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const { +bool Dataloader::_load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const { const bool ret = apply_to_files_in_dir(pop_type_directory, ".txt", - [&pop_manager](fs::path const& file) -> bool { - return pop_manager.load_pop_type_file(file.stem().string(), parse_defines(file).get_file_node()); + [&pop_manager, &unit_manager, &good_manager](fs::path const& file) -> bool { + return pop_manager.load_pop_type_file(file.stem().string(), unit_manager, good_manager, parse_defines(file).get_file_node()); } ); pop_manager.lock_pop_types(); @@ -632,7 +632,15 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load goods!"); ret = false; } - if (!_load_pop_types(game_manager.get_pop_manager(), pop_type_directory)) { + if (!_load_units(game_manager.get_military_manager().get_unit_manager(), + game_manager.get_economy_manager().get_good_manager(), units_directory)) { + Logger::error("Failed to load units!"); + ret = false; + } + if (!_load_pop_types(game_manager.get_pop_manager(), + game_manager.get_military_manager().get_unit_manager(), + game_manager.get_economy_manager().get_good_manager(), + pop_type_directory)) { Logger::error("Failed to load pop types!"); ret = false; } @@ -686,11 +694,6 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load map!"); ret = false; } - if (!_load_units(game_manager.get_military_manager().get_unit_manager(), - game_manager.get_economy_manager().get_good_manager(), units_directory)) { - Logger::error("Failed to load units!"); - ret = false; - } if (!game_manager.get_military_manager().get_leader_trait_manager().load_leader_traits_file(game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node())) { Logger::error("Failed to load leader traits!"); ret = false; diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp index 4d67501..7be86ad 100644 --- a/src/openvic-simulation/dataloader/Dataloader.hpp +++ b/src/openvic-simulation/dataloader/Dataloader.hpp @@ -23,7 +23,7 @@ namespace OpenVic { private: path_vector_t roots; - bool _load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const; + bool _load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const; bool _load_units(UnitManager& unit_manager, GoodManager const& good_manager, fs::path const& units_directory) const; bool _load_map_dir(GameManager& game_manager, fs::path const& map_directory) const; bool _load_countries(GameManager& game_manager, fs::path const& countries_file, ast::NodeCPtr root) const; diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index c2edb18..77eafcd 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -43,15 +43,15 @@ node_callback_t NodeTools::expect_string(callback_t<std::string_view> callback, return _expect_type<ast::StringNode>(_abstract_string_node_callback<ast::StringNode>(callback, allow_empty)); } -node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_view> callback) { - return [callback](ast::NodeCPtr node) -> bool { +node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_view> callback, bool allow_empty) { + return [callback, allow_empty](ast::NodeCPtr node) -> bool { if (node != nullptr) { ast::AbstractStringNode const* cast_node = node->cast_to<ast::IdentifierNode>(); if (cast_node == nullptr) { cast_node = node->cast_to<ast::StringNode>(); } if (cast_node != nullptr) { - return _abstract_string_node_callback<ast::AbstractStringNode>(callback, false)(*cast_node); + return _abstract_string_node_callback<ast::AbstractStringNode>(callback, allow_empty)(*cast_node); } Logger::error("Invalid node type ", node->get_type(), " when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static()); } else { diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index e98a4b0..42e7c5d 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -33,7 +33,7 @@ namespace OpenVic { node_callback_t expect_identifier(callback_t<std::string_view> callback); node_callback_t expect_string(callback_t<std::string_view> callback, bool allow_empty = true); - node_callback_t expect_identifier_or_string(callback_t<std::string_view> callback); + node_callback_t expect_identifier_or_string(callback_t<std::string_view> callback, bool allow_empty = false); node_callback_t expect_bool(callback_t<bool> callback); node_callback_t expect_int_bool(callback_t<bool> callback); |