diff options
author | Hop311 <Hop3114@gmail.com> | 2023-10-17 00:16:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-17 00:16:31 +0200 |
commit | 67bf9236857069090a5f7e00e05c5a3d912c80a7 (patch) | |
tree | 7bc21c92c4de6bf550875fc3fa0bbb5f06bc8283 /src/openvic-simulation/dataloader/Dataloader.cpp | |
parent | 7184795262f1fc01a4d4f9adf6b7d4c140423ffa (diff) | |
parent | 2a2e8b6e5c4657aeeb4f7af3ce90684d9a55d555 (diff) |
Merge pull request #49 from OpenVicProject/add/country-loading
Add Country Loading
Diffstat (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 0c60524..2553b7e 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -472,6 +472,28 @@ bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_ return ret; } +bool Dataloader::_load_countries(GameManager& game_manager, fs::path const& countries_file, ast::NodeCPtr root) const { + bool is_dynamic = false; + + bool ret = expect_dictionary( + [this, &game_manager, &is_dynamic, &countries_file](std::string_view key, ast::NodeCPtr value) -> bool { + if (key == "dynamic_tags") { + return expect_bool(assign_variable_callback(is_dynamic))(value); + } + + std::string_view data_path; + + if (!expect_string(assign_variable_callback(data_path))(value)) { + return false; + } + + return game_manager.get_country_manager().load_country_data_file(game_manager, key, is_dynamic, Dataloader::parse_defines(lookup_file(countries_file.parent_path() / data_path)).get_file_node()); + } + )(root); + game_manager.get_country_manager().lock_countries(); + return ret; +} + bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const { Map& map = game_manager.get_map(); @@ -597,6 +619,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const { static const fs::path production_types_file = "common/production_types.txt"; static const fs::path religion_file = "common/religion.txt"; static const fs::path leader_traits_file = "common/traits.txt"; + static const fs::path countries_file = "common/countries.txt"; bool ret = true; @@ -651,6 +674,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load issues!"); ret = false; } + if (!_load_countries(game_manager, countries_file, parse_defines(lookup_file(countries_file)).get_file_node())) { + Logger::error("Failed to load countries!"); + ret = false; + } if (!game_manager.get_economy_manager().load_production_types_file( game_manager.get_pop_manager(), parse_defines(lookup_file(production_types_file)).get_file_node())) { |