diff options
author | zaaarf <80046572+zaaarf@users.noreply.github.com> | 2023-09-23 13:51:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-23 13:51:09 +0200 |
commit | 13aff4b4eacecf565a2c9ff948f02cda1eac1903 (patch) | |
tree | 89307290fb810ddf0908c1a48c12dac945b2e0fa /src/openvic-simulation/dataloader/Dataloader.cpp | |
parent | 4550acf29bd3ce4ff9b9d14788de21d96a5ef90a (diff) | |
parent | 7720c6e1bcae39187ee75c2e084a9d4f6bd961fe (diff) |
Merge pull request #22 from OpenVicProject/dataloading-military
Dataloading for military (Unit, LandUnity, NavalUnit)
Diffstat (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index d0d9506..7cd955d 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -1,4 +1,5 @@ #include "Dataloader.hpp" +#include <filesystem> #include <openvic-dataloader/csv/Parser.hpp> #include <openvic-dataloader/detail/CallbackOStream.hpp> @@ -6,6 +7,7 @@ #include "openvic-simulation/GameManager.hpp" #include "openvic-simulation/utility/Logger.hpp" +#include "units/Unit.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -150,13 +152,20 @@ bool Dataloader::_load_pop_types(PopManager& pop_manager, fs::path const& pop_ty return pop_manager.load_pop_type_file(file.stem().string(), _parse_defines(file).get_file_node()); } ); - if (!ret) { - Logger::error("Failed to load pop types!"); - } pop_manager.lock_pop_types(); return ret; } +bool Dataloader::_load_units(UnitManager& unit_manager, fs::path const& units_directory) const { + const bool ret = apply_to_files_in_dir(units_directory, ".txt", + [&unit_manager](fs::path const& file) -> bool { + return unit_manager.load_unit_file(_parse_defines(file).get_file_node()); + } + ); + unit_manager.lock_units(); + return ret; +} + bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const { Map& map = game_manager.map; @@ -260,6 +269,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const { static const fs::path ideology_file = "common/ideologies.txt"; static const fs::path issues_file = "common/issues.txt"; static const fs::path map_directory = "map"; + static const fs::path units_directory = "units"; bool ret = true; @@ -291,6 +301,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load issues!"); ret = false; } + if (!_load_units(game_manager.unit_manager, units_directory)) { + Logger::error("Failed to load units!"); + ret = false; + } if (!_load_map_dir(game_manager, map_directory)) { Logger::error("Failed to load map!"); ret = false; |