diff options
author | zaaarf <me@zaaarf.foo> | 2023-12-10 13:35:25 +0100 |
---|---|---|
committer | zaaarf <me@zaaarf.foo> | 2023-12-10 23:19:43 +0100 |
commit | 85155e033e9b03d71752626137a75f6418a5786c (patch) | |
tree | 986b02c46996447780975f389b9b99d01a5fc600 /src/openvic-simulation/dataloader | |
parent | 34fbe27857d77d6f193d6d1848b953a4596cedd2 (diff) |
feat: implemented pop history loading
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 33 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.hpp | 1 |
2 files changed, 20 insertions, 14 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index f49ae2d..382c7aa 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -1,5 +1,6 @@ #include "Dataloader.hpp" +#include <filesystem> #include <openvic-dataloader/csv/Parser.hpp> #include <openvic-dataloader/detail/CallbackOStream.hpp> #include <openvic-dataloader/v2script/Parser.hpp> @@ -498,6 +499,25 @@ bool Dataloader::_load_history(GameManager& game_manager, bool unused_history_fi ); } ); + + /* Pop History */ + static constexpr std::string_view pop_history_directory = "history/pops"; + for (fs::path root : roots) { + fs::path concat = root / pop_history_directory; + for (fs::path dir : fs::directory_iterator(concat)) { + const Date date = Date::from_string(dir.filename().string()); + ret &= apply_to_files( + lookup_basic_indentifier_prefixed_files_in_dir_recursive(dir.string(), ".txt"), + [this, &game_manager, &date](fs::path const& file) -> bool { + const std::string filename = file.stem().string(); + return game_manager.get_history_manager().get_province_manager().load_pop_history_file( + game_manager, date, parse_defines(file).get_file_node() + ); + } + ); + } + } + game_manager.get_history_manager().get_province_manager().lock_province_histories(game_manager.get_map(), false); static constexpr std::string_view diplomacy_history_directory = "history/diplomacy"; @@ -837,19 +857,6 @@ bool Dataloader::load_defines(GameManager& game_manager) const { return ret; } -bool Dataloader::load_pop_history(GameManager& game_manager, std::string_view path) const { - return apply_to_files( - lookup_files_in_dir(path, ".txt"), - [&game_manager](fs::path const& file) -> bool { - return game_manager.get_map().expect_province_dictionary( - [&game_manager](Province& province, ast::NodeCPtr value) -> bool { - return province.load_pop_list(game_manager.get_pop_manager(), value); - } - )(parse_defines(file).get_file_node()); - } - ); -} - static bool _load_localisation_file(Dataloader::localisation_callback_t callback, std::vector<csv::LineObject> const& lines) { bool ret = true; for (csv::LineObject const& line : lines) { diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp index 78021b3..7f5d0aa 100644 --- a/src/openvic-simulation/dataloader/Dataloader.hpp +++ b/src/openvic-simulation/dataloader/Dataloader.hpp @@ -95,7 +95,6 @@ namespace OpenVic { bool apply_to_files(path_vector_t const& files, NodeTools::callback_t<fs::path const&> callback) const; bool load_defines(GameManager& game_manager) const; - bool load_pop_history(GameManager& game_manager, std::string_view path) const; enum locale_t : size_t { English, French, German, Polish, Spanish, Italian, Swedish, |