diff options
author | zaaarf <zaaarf@proton.me> | 2023-09-22 16:14:22 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-09-22 16:14:22 +0200 |
commit | e91e2670abfd4976883c7a5d654d1f5469b4ac7a (patch) | |
tree | 6c79c05b35773972a2338adfeb395c4487f94087 /src/openvic-simulation/dataloader/Dataloader.cpp | |
parent | f68f60efec1b1bad7d0b33fedff82fbfb9d6ebaa (diff) |
feat: removed enum, passed goods manager
Diffstat (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index d0d9506..55dbf8a 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,19 @@ 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 +268,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 +300,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; |