aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-28 11:39:08 +0200
committer hop311 <hop3114@gmail.com>2023-10-29 20:42:47 +0100
commit164264b047921dbe1567d2af183e1cffb200a8cb (patch)
tree21c3c81f65ac3259db4808ebe9fd32a94ca993af /src/openvic-simulation/dataloader
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
Astyle formatting (with manual cleanup)
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp238
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp25
-rw-r--r--src/openvic-simulation/dataloader/Dataloader_Windows.hpp47
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp44
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp50
5 files changed, 244 insertions, 160 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index ad35056..7a904ed 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -51,16 +51,18 @@ concept is_filename = std::same_as<T, std::filesystem::path> || std::convertible
static bool filename_equals(const is_filename auto& lhs, const is_filename auto& rhs) {
auto left = [&lhs] {
- if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>)
+ if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>) {
return lhs.filename().string();
- else
+ } else {
return lhs;
+ }
}();
auto right = [&rhs] {
- if constexpr (std::same_as<std::decay_t<decltype(rhs)>, std::filesystem::path>)
+ if constexpr (std::same_as<std::decay_t<decltype(rhs)>, std::filesystem::path>) {
return rhs.filename().string();
- else
+ } else {
return rhs;
+ }
}();
return path_equals(left, right);
}
@@ -79,17 +81,20 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
// Don't waste time trying to search for Victoria 2 when supplied a valid looking Victoria 2 game directory
if (filename_equals(Victoria_2_folder, hint_path)) {
- if (fs::is_regular_file(hint_path / v2_game_exe, error_code))
+ if (fs::is_regular_file(hint_path / v2_game_exe, error_code)) {
return hint_path;
+ }
}
const bool hint_path_was_empty = hint_path.empty();
if (hint_path_was_empty) {
#if defined(_WIN32)
- static const fs::path registry_path = Windows::ReadRegValue<char>(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Paradox Interactive\\Victoria 2", "path");
+ static const fs::path registry_path = Windows::ReadRegValue<char>(HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\WOW6432Node\\Paradox Interactive\\Victoria 2", "path");
- if (!registry_path.empty())
+ if (!registry_path.empty()) {
return registry_path;
+ }
#pragma warning(push)
#pragma warning(disable : 4996)
@@ -104,14 +109,14 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
}
}
#pragma warning(pop)
-// Cannot support Android
-// Only FreeBSD currently unofficially supports emulating Linux
+ // Cannot support Android
+ // Only FreeBSD currently unofficially supports emulating Linux
#elif (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__)
static const fs::path home = std::getenv("HOME");
hint_path = home / ".steam" / "steam";
- if (fs::is_symlink(hint_path, error_code))
+ if (fs::is_symlink(hint_path, error_code)) {
hint_path = fs::read_symlink(hint_path, error_code);
- else if (!fs::is_directory(hint_path, error_code)) {
+ } else if (!fs::is_directory(hint_path, error_code)) {
hint_path = home / ".local" / "share" / "Steam";
if (!fs::is_directory(hint_path, error_code)) {
#ifdef __FreeBSD__
@@ -122,7 +127,7 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
return "";
}
}
-// Support only Mac, cannot support iOS
+ // Support only Mac, cannot support iOS
#elif (defined(__APPLE__) && defined(__MACH__)) && TARGET_OS_MAC == 1
static const fs::path home = std::getenv("HOME");
hint_path = home / "Library" / "Application Support" / "Steam";
@@ -130,18 +135,21 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
Logger::warning("Could not find path for Steam installation on Mac.");
return "";
}
-// All platforms that reach this point do not seem to even have unofficial Steam support
+ // All platforms that reach this point do not seem to even have unofficial Steam support
#else
Logger::warning("Could not find path for Steam installation on unsupported platform.");
#endif
}
// Could not determine Steam install on platform
- if (hint_path.empty()) return "";
+ if (hint_path.empty()) {
+ return "";
+ }
// Supplied path was useless, ignore hint_path
- if (!hint_path_was_empty && !fs::exists(hint_path, error_code))
+ if (!hint_path_was_empty && !fs::exists(hint_path, error_code)) {
return _search_for_game_path();
+ }
// Steam Library's directory that will contain Victoria 2
fs::path vic2_steam_lib_directory;
@@ -184,8 +192,9 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
parser.load_from_file(current_path);
if (!parser.parse()) {
// Could not find or load libraryfolders.vdf, report error as warning
- if (!buffer.empty())
+ if (!buffer.empty()) {
Logger::warning _(buffer);
+ }
return "";
}
std::optional current_node = *(parser.get_key_values());
@@ -305,8 +314,9 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
}
// Hail Mary check ignoring the hint_path
- if (!hint_path_was_empty)
+ if (!hint_path_was_empty) {
return _search_for_game_path();
+ }
Logger::warning("Could not find Victoria 2 game path, this requires manually supplying one.");
return ""; // The supplied path fits literally none of the criteria
@@ -314,8 +324,9 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
fs::path Dataloader::search_for_game_path(fs::path hint_path) {
auto it = _cached_paths.find(hint_path);
- if (it != _cached_paths.end())
+ if (it != _cached_paths.end()) {
return it->second;
+ }
return _cached_paths[hint_path] = _search_for_game_path(hint_path);
}
@@ -360,7 +371,9 @@ fs::path Dataloader::lookup_file(fs::path const& path) const {
static bool contains_file_with_name(Dataloader::path_vector_t const& paths, fs::path const& name) {
for (fs::path const& path : paths) {
- if (path.filename() == name) return true;
+ if (path.filename() == name) {
+ return true;
+ }
}
return false;
}
@@ -384,7 +397,8 @@ Dataloader::path_vector_t Dataloader::lookup_files_in_dir(fs::path const& path,
return ret;
}
-bool Dataloader::apply_to_files_in_dir(fs::path const& path, fs::path const& extension, callback_t<fs::path const&> callback) const {
+bool Dataloader::apply_to_files_in_dir(fs::path const& path, fs::path const& extension,
+ callback_t<fs::path const&> callback) const {
bool ret = true;
for (fs::path const& file : lookup_files_in_dir(path, extension)) {
if (!callback(file)) {
@@ -458,18 +472,27 @@ 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, 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, &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());
- });
+bool Dataloader::_load_pop_types(
+ PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager
+) const {
+ static const fs::path pop_type_directory = "poptypes";
+ const bool ret = apply_to_files_in_dir(pop_type_directory, ".txt",
+ [&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();
return ret;
}
-bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_manager, fs::path const& units_directory) const {
- const bool ret = apply_to_files_in_dir(units_directory, ".txt", [&unit_manager, &good_manager](fs::path const& file) -> bool {
- return unit_manager.load_unit_file(good_manager, parse_defines(file).get_file_node());
- });
+bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_manager) const {
+ static const fs::path units_directory = "units";
+ const bool ret = apply_to_files_in_dir(units_directory, ".txt",
+ [&unit_manager, &good_manager](fs::path const& file) -> bool {
+ return unit_manager.load_unit_file(good_manager, parse_defines(file).get_file_node());
+ }
+ );
unit_manager.lock_units();
return ret;
}
@@ -478,11 +501,13 @@ bool Dataloader::_load_oobs(GameManager& game_manager) const {
static const fs::path oob_directory = "history/units";
/* used for countries with no defined initial OOB */
- game_manager.get_military_manager().get_deployment_manager().add_deployment("NULL", std::vector<Army>(), std::vector<Navy>(), std::vector<Leader>());
+ game_manager.get_military_manager().get_deployment_manager().add_deployment(
+ "NULL", std::vector<Army>(), std::vector<Navy>(), std::vector<Leader>());
bool ret = apply_to_files_in_dir(oob_directory, ".txt", [&game_manager](fs::path const& file) -> bool {
if (file.filename() == "v2dd2.txt") return true; /* dev diary just stuck in there for no reason whatsoever */
- return game_manager.get_military_manager().get_deployment_manager().load_oob_file(game_manager, file.filename().string(), parse_defines(file).get_file_node());
+ return game_manager.get_military_manager().get_deployment_manager().load_oob_file(game_manager,
+ file.filename().string(), parse_defines(file).get_file_node());
});
/* we also load OOBs in top level subdirectories, for other start dates etc */
@@ -492,7 +517,9 @@ bool Dataloader::_load_oobs(GameManager& game_manager) const {
for (fs::directory_entry const& entry : fs::directory_iterator { path, ec }) {
if (entry.is_directory()) {
ret &= apply_to_files_in_dir(entry, ".txt", [&entry, &game_manager](fs::path const& file) -> bool {
- return game_manager.get_military_manager().get_deployment_manager().load_oob_file(game_manager, (entry.path().filename() / file.filename()).string(), parse_defines(file).get_file_node());
+ return game_manager.get_military_manager().get_deployment_manager().load_oob_file(
+ game_manager, (entry.path().filename() / file.filename()).string(),
+ parse_defines(file).get_file_node());
});
}
}
@@ -519,7 +546,8 @@ bool Dataloader::_load_countries(GameManager& game_manager) const {
return false;
}
- return game_manager.get_country_manager().load_country_data_file(game_manager, key, is_dynamic, parse_defines(lookup_file(countries_file.parent_path() / data_path)).get_file_node());
+ return game_manager.get_country_manager().load_country_data_file(game_manager, key, is_dynamic,
+ parse_defines(lookup_file(countries_file.parent_path() / data_path)).get_file_node());
}
)(parse_defines(lookup_file(countries_file)).get_file_node());
game_manager.get_country_manager().lock_countries();
@@ -530,18 +558,21 @@ bool Dataloader::_load_countries(GameManager& game_manager) const {
bool Dataloader::_load_history(GameManager& game_manager) const {
static const fs::path country_history_directory = "history/countries";
static const fs::path province_history_directory = "history/provinces";
-
+
/* Country History */
- bool ret = apply_to_files_in_dir(country_history_directory, ".txt", [this, &game_manager](fs::path const& file) -> bool {
- std::string tag = file.filename().string().substr(0, 3);
+ bool ret = apply_to_files_in_dir(country_history_directory, ".txt",
+ [this, &game_manager](fs::path const& file) -> bool {
+ std::string tag = file.filename().string().substr(0, 3);
- if (!game_manager.get_country_manager().has_country_identifier(tag)) {
- Logger::error("Error loading history for country ", tag, ": tag not defined!");
- return false;
+ if (!game_manager.get_country_manager().has_country_identifier(tag)) {
+ Logger::error("Error loading history for country ", tag, ": tag not defined!");
+ return false;
+ }
+
+ return game_manager.get_history_manager().get_country_manager().load_country_history_file(
+ game_manager, tag, parse_defines(lookup_file(file)).get_file_node());
}
-
- return game_manager.get_history_manager().get_country_manager().load_country_history_file(game_manager, tag, parse_defines(lookup_file(file)).get_file_node());
- });
+ );
game_manager.get_history_manager().get_country_manager().lock_country_histories();
/* Province History */
@@ -559,7 +590,8 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
return false;
}
- return game_manager.get_history_manager().get_province_manager().load_province_history_file(game_manager, province_id, parse_defines(lookup_file(file)).get_file_node());
+ return game_manager.get_history_manager().get_province_manager().load_province_history_file(
+ game_manager, province_id, parse_defines(lookup_file(file)).get_file_node());
});
}
}
@@ -569,7 +601,8 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
return ret;
}
-bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const {
+bool Dataloader::_load_map_dir(GameManager& game_manager) const {
+ static const fs::path map_directory = "map";
Map& map = game_manager.get_map();
static const fs::path defaults_filename = "default.map";
@@ -610,19 +643,19 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
bool ret = expect_dictionary_keys(
"max_provinces", ONE_EXACTLY,
- expect_uint<Province::index_t>(
- std::bind(&Map::set_max_provinces, &map, std::placeholders::_1)
- ),
+ expect_uint<Province::index_t>(
+ std::bind(&Map::set_max_provinces, &map, std::placeholders::_1)
+ ),
"sea_starts", ONE_EXACTLY,
- expect_list_reserve_length(
- water_province_identifiers,
- expect_identifier(
- [&water_province_identifiers](std::string_view identifier) -> bool {
- water_province_identifiers.push_back(identifier);
- return true;
- }
- )
- ),
+ expect_list_reserve_length(
+ water_province_identifiers,
+ expect_identifier(
+ [&water_province_identifiers](std::string_view identifier) -> bool {
+ water_province_identifiers.push_back(identifier);
+ return true;
+ }
+ )
+ ),
#define MAP_PATH_DICT_ENTRY(X) \
#X, ONE_EXACTLY, expect_string(assign_variable_callback(X)),
@@ -631,8 +664,7 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
#undef APPLY_TO_MAP_PATHS
- "border_heights",
- ZERO_OR_ONE, success_callback,
+ "border_heights", ZERO_OR_ONE, success_callback,
"terrain_sheet_heights", ZERO_OR_ONE, success_callback,
"tree", ZERO_OR_ONE, success_callback,
"border_cutoff", ZERO_OR_ONE, success_callback
@@ -643,22 +675,22 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
}
if (!map.load_province_definitions(
- parse_csv(lookup_file(map_directory / definitions)).get_lines()
- )) {
+ parse_csv(lookup_file(map_directory / definitions)).get_lines()
+ )) {
Logger::error("Failed to load province definitions file!");
ret = false;
}
if (!map.load_province_positions(
- game_manager.get_economy_manager().get_building_manager(), parse_defines(lookup_file(map_directory / positions)).get_file_node()
- )) {
+ game_manager.get_economy_manager().get_building_manager(), parse_defines(lookup_file(map_directory / positions)).get_file_node()
+ )) {
Logger::error("Failed to load province positions file!");
ret = false;
}
if (!map.load_region_file(
- parse_defines(lookup_file(map_directory / region)).get_file_node()
- )) {
+ parse_defines(lookup_file(map_directory / region)).get_file_node()
+ )) {
Logger::error("Failed to load region file!");
ret = false;
}
@@ -669,24 +701,24 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
}
if (!map.get_terrain_type_manager().load_terrain_types(
- game_manager.get_modifier_manager(),
- parse_defines(lookup_file(map_directory / terrain_definition)).get_file_node()
- )) {
+ game_manager.get_modifier_manager(),
+ parse_defines(lookup_file(map_directory / terrain_definition)).get_file_node()
+ )) {
Logger::error("Failed to load terrain types!");
ret = false;
}
if (!map.load_map_images(
- lookup_file(map_directory / provinces),
- lookup_file(map_directory / terrain), false
- )) {
+ lookup_file(map_directory / provinces),
+ lookup_file(map_directory / terrain), false
+ )) {
Logger::error("Failed to load map images!");
ret = false;
}
if (!map.generate_and_load_province_adjacencies(
- parse_csv(lookup_file(map_directory / adjacencies)).get_lines()
- )) {
+ parse_csv(lookup_file(map_directory / adjacencies)).get_lines()
+ )) {
Logger::error("Failed to generate and load province adjacencies!");
ret = false;
}
@@ -695,10 +727,6 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
}
bool Dataloader::load_defines(GameManager& game_manager) const {
- static const fs::path map_directory = "map";
- static const fs::path pop_type_directory = "poptypes";
- static const fs::path units_directory = "units";
-
static const fs::path defines_file = "common/defines.lua";
static const fs::path buildings_file = "common/buildings.txt";
static const fs::path bookmark_file = "common/bookmarks.txt";
@@ -724,82 +752,84 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
ret = false;
}
if (!game_manager.get_economy_manager().get_good_manager().load_goods_file(
- parse_defines(lookup_file(goods_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(goods_file)).get_file_node()
+ )) {
Logger::error("Failed to load goods!");
ret = false;
}
- if (!_load_units(game_manager.get_military_manager().get_unit_manager(), game_manager.get_economy_manager().get_good_manager(), units_directory)) {
+ if (!_load_units(game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_economy_manager().get_good_manager()
+ )) {
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)) {
+ 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()
+ )) {
Logger::error("Failed to load pop types!");
ret = false;
}
if (!game_manager.get_pop_manager().get_culture_manager().load_graphical_culture_type_file(
- parse_defines(lookup_file(graphical_culture_type_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(graphical_culture_type_file)).get_file_node()
+ )) {
Logger::error("Failed to load graphical culture types!");
ret = false;
}
if (!game_manager.get_pop_manager().get_culture_manager().load_culture_file(
- parse_defines(lookup_file(culture_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(culture_file)).get_file_node()
+ )) {
Logger::error("Failed to load cultures!");
ret = false;
}
if (!game_manager.get_pop_manager().get_religion_manager().load_religion_file(
- parse_defines(lookup_file(religion_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(religion_file)).get_file_node()
+ )) {
Logger::error("Failed to load religions!");
ret = false;
}
if (!game_manager.get_politics_manager().get_ideology_manager().load_ideology_file(
- parse_defines(lookup_file(ideology_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(ideology_file)).get_file_node()
+ )) {
Logger::error("Failed to load ideologies!");
ret = false;
}
if (!game_manager.get_politics_manager().load_government_types_file(
- parse_defines(lookup_file(governments_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(governments_file)).get_file_node()
+ )) {
Logger::error("Failed to load government types!");
ret = false;
}
if (!game_manager.get_politics_manager().get_issue_manager().load_issues_file(
- parse_defines(lookup_file(issues_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(issues_file)).get_file_node()
+ )) {
Logger::error("Failed to load issues!");
ret = false;
}
if (!game_manager.get_politics_manager().get_national_value_manager().load_national_values_file(
- game_manager.get_modifier_manager(), parse_defines(lookup_file(national_values_file)).get_file_node()
- )) {
+ game_manager.get_modifier_manager(), parse_defines(lookup_file(national_values_file)).get_file_node()
+ )) {
Logger::error("Failed to load national values!");
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()
- )) {
+ 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()
+ )) {
Logger::error("Failed to load production types!");
ret = false;
}
- if (!game_manager.get_economy_manager().load_buildings_file(
- game_manager.get_modifier_manager(),
- parse_defines(lookup_file(buildings_file)).get_file_node()
- )) {
+ if (!game_manager.get_economy_manager().load_buildings_file(game_manager.get_modifier_manager(),
+ parse_defines(lookup_file(buildings_file)).get_file_node()
+ )) {
Logger::error("Failed to load buildings!");
ret = false;
}
- if (!_load_map_dir(game_manager, map_directory)) {
+ if (!_load_map_dir(game_manager)) {
Logger::error("Failed to load map!");
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()
- )) {
+ 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 4a8b111..1a8e9ab 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -23,9 +23,11 @@ namespace OpenVic {
private:
path_vector_t roots;
- 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_pop_types(
+ PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager
+ ) const;
+ bool _load_units(UnitManager& unit_manager, GoodManager const& good_manager) const;
+ bool _load_map_dir(GameManager& game_manager) const;
bool _load_oobs(GameManager& game_manager) const;
bool _load_countries(GameManager& game_manager) const;
bool _load_history(GameManager& game_manager) const;
@@ -43,15 +45,18 @@ namespace OpenVic {
/// Supports being supplied:
/// 1. A valid Victoria 2 game directory (Victoria 2 directory that contains a v2game.exe file)
/// 2. An Empty path: assumes a common Steam install structure per platform.
- /// 2b. If Windows, returns "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Paradox Interactive\Victoria 2" "path" registry value
+ /// 2b. If Windows, returns "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Paradox Interactive\Victoria 2"
+ /// "path" registry value
/// 2c. If registry value returns an empty string, performs Steam checks below
/// 3. A path to a root Steam install. (eg: C:\Program Files(x86)\Steam, ~/.steam/steam)
- /// 4. A path to a root Steam steamapps directory. (eg: C:\Program Files(x86)\Steam\steamapps, ~/.steam/steam/steamapps)
+ /// 4. A path to a root Steam steamapps directory. (eg: C:\Program Files(x86)\Steam\steamapps,
+ /// ~/.steam/steam/steamapps)
/// 5. A path to the root Steam libraryfolders.vdf, commonly in the root Steam steamapps directory.
/// 6. A path to the Steam library directory that contains Victoria 2.
/// 7. A path to a Steam library's steamapps directory that contains Victoria 2.
/// 8. A path to a Steam library's steamapps/common directory that contains Victoria 2.
- /// 9. If any of these checks don't resolve to a valid Victoria 2 game directory when supplied a non-empty hint_path, performs empty path behavior.
+ /// 9. If any of these checks don't resolve to a valid Victoria 2 game directory when supplied
+ /// a non-empty hint_path, performs empty path behavior.
/// @return fs::path The root directory of a valid Victoria 2 install, or an empty path.
///
static fs::path search_for_game_path(fs::path hint_path = {});
@@ -64,7 +69,9 @@ namespace OpenVic {
*/
fs::path lookup_file(fs::path const& path) const;
path_vector_t lookup_files_in_dir(fs::path const& path, fs::path const& extension) const;
- bool apply_to_files_in_dir(fs::path const& path, fs::path const& extension, NodeTools::callback_t<fs::path const&> callback) const;
+ bool apply_to_files_in_dir(
+ fs::path const& path, fs::path const& extension, NodeTools::callback_t<fs::path const&> callback
+ ) const;
bool load_defines(GameManager& game_manager) const;
bool load_pop_history(GameManager& game_manager, fs::path const& path) const;
@@ -91,7 +98,9 @@ namespace OpenVic {
/* Args: key, locale, localisation */
using localisation_callback_t = NodeTools::callback_t<std::string_view, locale_t, std::string_view>;
- bool load_localisation_files(localisation_callback_t callback, fs::path const& localisation_dir = "localisation") const;
+ bool load_localisation_files(
+ localisation_callback_t callback, fs::path const& localisation_dir = "localisation"
+ ) const;
private:
struct fshash {
diff --git a/src/openvic-simulation/dataloader/Dataloader_Windows.hpp b/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
index f4abbb6..6b6fce3 100644
--- a/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
@@ -11,7 +11,9 @@
namespace OpenVic::Windows {
inline std::wstring convert(std::string_view as) {
// deal with trivial case of empty string
- if (as.empty()) return std::wstring();
+ if (as.empty()) {
+ return std::wstring();
+ }
// determine required length of new string
size_t length = ::MultiByteToWideChar(CP_UTF8, 0, as.data(), (int)as.length(), 0, 0);
@@ -28,7 +30,9 @@ namespace OpenVic::Windows {
inline std::string convert(std::wstring_view as) {
// deal with trivial case of empty string
- if (as.empty()) return std::string();
+ if (as.empty()) {
+ return std::string();
+ }
// determine required length of new string
size_t length = ::WideCharToMultiByte(CP_UTF8, 0, as.data(), (int)as.length(), 0, 0, NULL, NULL);
@@ -51,7 +55,10 @@ namespace OpenVic::Windows {
template<typename T>
concept has_data = requires(T t) {
- { t.data() } -> std::convertible_to<const typename T::value_type*>;
+ {
+ t.data()
+ }
+ -> std::convertible_to<const typename T::value_type*>;
};
class RegistryKey {
@@ -61,7 +68,9 @@ namespace OpenVic::Windows {
}
template<either_char_type CHAR_T, either_char_type CHAR_T2>
- RegistryKey(HKEY parent_key_handle, std::basic_string_view<CHAR_T> child_key_name, std::basic_string_view<CHAR_T2> value_name) {
+ RegistryKey(HKEY parent_key_handle,
+ std::basic_string_view<CHAR_T> child_key_name,
+ std::basic_string_view<CHAR_T2> value_name) {
open_key(parent_key_handle, child_key_name);
query_key(value_name);
}
@@ -80,29 +89,32 @@ namespace OpenVic::Windows {
template<either_char_type CHAR_T>
LSTATUS open_key(HKEY parent_key_handle, std::basic_string_view<CHAR_T> key_path) {
- if (is_open())
+ if (is_open()) {
close_key();
- if constexpr (std::is_same_v<CHAR_T, char>)
+ }
+ if constexpr (std::is_same_v<CHAR_T, char>) {
return RegOpenKeyExW(parent_key_handle, convert(key_path).data(), REG_NONE, KEY_READ, &_key_handle);
- else
+ } else {
return RegOpenKeyExW(parent_key_handle, key_path.data(), REG_NONE, KEY_READ, &_key_handle);
+ }
}
bool is_predefined() const {
return (_key_handle == HKEY_CURRENT_USER) ||
- (_key_handle == HKEY_LOCAL_MACHINE) ||
- (_key_handle == HKEY_CLASSES_ROOT) ||
- (_key_handle == HKEY_CURRENT_CONFIG) ||
- (_key_handle == HKEY_CURRENT_USER_LOCAL_SETTINGS) ||
- (_key_handle == HKEY_PERFORMANCE_DATA) ||
- (_key_handle == HKEY_PERFORMANCE_NLSTEXT) ||
- (_key_handle == HKEY_PERFORMANCE_TEXT) ||
- (_key_handle == HKEY_USERS);
+ (_key_handle == HKEY_LOCAL_MACHINE) ||
+ (_key_handle == HKEY_CLASSES_ROOT) ||
+ (_key_handle == HKEY_CURRENT_CONFIG) ||
+ (_key_handle == HKEY_CURRENT_USER_LOCAL_SETTINGS) ||
+ (_key_handle == HKEY_PERFORMANCE_DATA) ||
+ (_key_handle == HKEY_PERFORMANCE_NLSTEXT) ||
+ (_key_handle == HKEY_PERFORMANCE_TEXT) ||
+ (_key_handle == HKEY_USERS);
}
LSTATUS close_key() {
- if (!is_open() || is_predefined())
+ if (!is_open() || is_predefined()) {
return ERROR_SUCCESS;
+ }
auto result = RegCloseKey(_key_handle);
_key_handle = nullptr;
return result;
@@ -131,8 +143,9 @@ namespace OpenVic::Windows {
close_key();
std::size_t first_null = _value.find_first_of(L'\0');
- if (first_null != std::string::npos)
+ if (first_null != std::string::npos) {
_value.resize(first_null);
+ }
return result;
}
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index 92080c4..69aebc9 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -53,7 +53,8 @@ node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_vi
if (cast_node != nullptr) {
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());
+ Logger::error("Invalid node type ", node->get_type(), " when expecting ",
+ ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static());
} else {
Logger::error("Null node when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static());
}
@@ -123,18 +124,22 @@ node_callback_t NodeTools::expect_colour(callback_t<colour_t> callback) {
return [callback](ast::NodeCPtr node) -> bool {
colour_t col = NULL_COLOUR;
uint32_t components = 0;
- bool ret = expect_list_of_length(3, expect_fixed_point([&col, &components](fixed_point_t val) -> bool {
- components++;
- col <<= 8;
- if (val < 0 || val > 255) {
- Logger::error("Invalid colour component: ", val);
- return false;
- } else {
- if (val <= 1) val *= 255;
- col |= val.to_int32_t();
- return true;
- }
- }))(node);
+ bool ret = expect_list_of_length(3, expect_fixed_point(
+ [&col, &components](fixed_point_t val) -> bool {
+ components++;
+ col <<= 8;
+ if (val < 0 || val > 255) {
+ Logger::error("Invalid colour component: ", val);
+ return false;
+ } else {
+ if (val <= 1) {
+ val *= 255;
+ }
+ col |= val.to_int32_t();
+ return true;
+ }
+ }
+ ))(node);
ret &= callback(col << 8 * (3 - components));
return ret;
};
@@ -230,7 +235,9 @@ node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t
if (size != length) {
Logger::error("List length ", size, " does not match expected length ", length);
ret = false;
- if (length < size) return length;
+ if (length < size) {
+ return length;
+ }
}
return size;
},
@@ -289,7 +296,8 @@ node_callback_t NodeTools::expect_dictionary(key_value_callback_t callback) {
return expect_dictionary_and_length(default_length_callback, callback);
}
-bool NodeTools::add_key_map_entry(key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count, node_callback_t callback) {
+bool NodeTools::add_key_map_entry(key_map_t& key_map, std::string_view key,
+ dictionary_entry_t::expected_count_t expected_count, node_callback_t callback) {
if (key_map.find(key) == key_map.end()) {
key_map.emplace(key, dictionary_entry_t { expected_count, callback });
return true;
@@ -336,7 +344,8 @@ bool NodeTools::check_key_map_counts(key_map_t& key_map) {
return ret;
}
-node_callback_t NodeTools::expect_dictionary_key_map_and_length_and_default(key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback) {
+node_callback_t NodeTools::expect_dictionary_key_map_and_length_and_default(key_map_t key_map,
+ length_callback_t length_callback, key_value_callback_t default_callback) {
return [length_callback, default_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool {
bool ret = expect_dictionary_and_length(
length_callback, dictionary_keys_callback(key_map, default_callback)
@@ -355,7 +364,8 @@ node_callback_t NodeTools::expect_dictionary_key_map_and_default(key_map_t key_m
}
node_callback_t NodeTools::expect_dictionary_key_map(key_map_t key_map) {
- return expect_dictionary_key_map_and_length_and_default(std::move(key_map), default_length_callback, key_value_invalid_callback);
+ return expect_dictionary_key_map_and_length_and_default(std::move(key_map),
+ default_length_callback, key_value_invalid_callback);
}
node_callback_t NodeTools::name_list_callback(callback_t<std::vector<std::string>&&> callback) {
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 6469100..7ad5412 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -27,13 +27,19 @@ namespace OpenVic {
namespace NodeTools {
template<typename Fn, typename Return = void, typename... Args>
- concept Functor = requires(Fn&& fn, Args&&... args) {
- { std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...) } -> std::same_as<Return>;
+ concept Functor = requires(Fn&& fn, Args&& ... args) {
+ {
+ std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...)
+ }
+ -> std::same_as<Return>;
};
template<typename Fn, typename Return = void, typename... Args>
- concept FunctorConvertible = requires(Fn&& fn, Args&&... args) {
- { std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...) } -> std::convertible_to<Return>;
+ concept FunctorConvertible = requires(Fn&& fn, Args&& ... args) {
+ {
+ std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...)
+ }
+ -> std::convertible_to<Return>;
};
template<typename Fn, typename... Args>
@@ -52,10 +58,14 @@ namespace OpenVic {
using callback_t = std::function<bool(Args...)>;
using node_callback_t = callback_t<ast::NodeCPtr>;
- constexpr bool success_callback(ast::NodeCPtr) { return true; }
+ constexpr bool success_callback(ast::NodeCPtr) {
+ return true;
+ }
using key_value_callback_t = callback_t<std::string_view, ast::NodeCPtr>;
- constexpr bool key_value_success_callback(std::string_view, ast::NodeCPtr) { return true; }
+ constexpr bool key_value_success_callback(std::string_view, ast::NodeCPtr) {
+ return true;
+ }
inline bool key_value_invalid_callback(std::string_view key, ast::NodeCPtr) {
Logger::error("Invalid dictionary key: ", key);
return false;
@@ -109,7 +119,9 @@ namespace OpenVic {
node_callback_t expect_assign(key_value_callback_t callback);
using length_callback_t = std::function<size_t(size_t)>;
- constexpr size_t default_length_callback(size_t size) { return size; };
+ constexpr size_t default_length_callback(size_t size) {
+ return size;
+ };
node_callback_t expect_list_and_length(length_callback_t length_callback, node_callback_t callback);
node_callback_t expect_list_of_length(size_t length, node_callback_t callback);
@@ -147,33 +159,40 @@ namespace OpenVic {
using enum dictionary_entry_t::expected_count_t;
using key_map_t = string_map_t<dictionary_entry_t>;
- bool add_key_map_entry(key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count, node_callback_t callback);
+ bool add_key_map_entry(key_map_t& key_map, std::string_view key,
+ dictionary_entry_t::expected_count_t expected_count, node_callback_t callback);
bool remove_key_map_entry(key_map_t& key_map, std::string_view key);
key_value_callback_t dictionary_keys_callback(key_map_t& key_map, key_value_callback_t default_callback);
bool check_key_map_counts(key_map_t& key_map);
- constexpr bool add_key_map_entries(key_map_t& key_map) { return true; }
+ constexpr bool add_key_map_entries(key_map_t& key_map) {
+ return true;
+ }
template<typename... Args>
- bool add_key_map_entries(key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count, NodeCallback auto callback, Args... args) {
+ bool add_key_map_entries(key_map_t& key_map, std::string_view key,
+ dictionary_entry_t::expected_count_t expected_count, NodeCallback auto callback, Args... args) {
bool ret = add_key_map_entry(key_map, key, expected_count, callback);
ret &= add_key_map_entries(key_map, args...);
return ret;
}
- node_callback_t expect_dictionary_key_map_and_length_and_default(key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback);
+ node_callback_t expect_dictionary_key_map_and_length_and_default(key_map_t key_map,
+ length_callback_t length_callback, key_value_callback_t default_callback);
node_callback_t expect_dictionary_key_map_and_length(key_map_t key_map, length_callback_t length_callback);
node_callback_t expect_dictionary_key_map_and_default(key_map_t key_map, key_value_callback_t default_callback);
node_callback_t expect_dictionary_key_map(key_map_t key_map);
template<typename... Args>
- NodeCallback auto expect_dictionary_key_map_and_length_and_default(key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback, Args... args) {
+ NodeCallback auto expect_dictionary_key_map_and_length_and_default(key_map_t key_map,
+ length_callback_t length_callback, key_value_callback_t default_callback, Args... args) {
// TODO - pass return value back up (part of big key_map_t rewrite?)
add_key_map_entries(key_map, args...);
return expect_dictionary_key_map_and_length_and_default(std::move(key_map), length_callback, default_callback);
}
template<typename... Args>
- NodeCallback auto expect_dictionary_keys_and_length_and_default(LengthCallback auto length_callback, KeyValueCallback auto default_callback, Args... args) {
+ NodeCallback auto expect_dictionary_keys_and_length_and_default(LengthCallback auto length_callback,
+ KeyValueCallback auto default_callback, Args... args) {
return expect_dictionary_key_map_and_length_and_default({}, length_callback, default_callback, args...);
}
@@ -194,7 +213,10 @@ namespace OpenVic {
template<typename T>
concept Reservable = requires(T& t) {
- { t.size() } -> std::same_as<size_t>;
+ {
+ t.size()
+ }
+ -> std::same_as<size_t>;
t.reserve(size_t {});
};
template<Reservable T>