From 874a20258469cf1a91296a6158b2a61fe5d884f9 Mon Sep 17 00:00:00 2001 From: Idhrendur Date: Mon, 16 Dec 2024 09:53:22 -0800 Subject: [PATCH 1/2] Correctly get province indexes from mods --- .../vic3_province_definitions_loader.cpp | 8 ++++++- .../states/state_regions_importer.cpp | 21 ++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/vic3_world/provinces/vic3_province_definitions_loader.cpp b/src/vic3_world/provinces/vic3_province_definitions_loader.cpp index 7d123c7d..11c6ccef 100644 --- a/src/vic3_world/provinces/vic3_province_definitions_loader.cpp +++ b/src/vic3_world/provinces/vic3_province_definitions_loader.cpp @@ -120,7 +120,13 @@ vic3::ProvinceDefinitions vic3::LoadProvinceDefinitions(const StateRegions& stat }); file_parser.IgnoreAndLogUnregisteredItems(); - for (const std::string& strategic_region: filesystem.GetAllFilesInFolder("common/strategic_regions")) + const std::set files = filesystem.GetAllFilesInFolder("common/strategic_regions"); + std::vector sorted_files(files.begin(), files.end()); + std::ranges::sort(sorted_files, [](const std::string& a, const std::string& b) { + return std::filesystem::path(a).filename() < std::filesystem::path(b).filename(); + }); + + for (const std::string& strategic_region: sorted_files) { if (std::filesystem::path(strategic_region).extension() != ".txt") { diff --git a/src/vic3_world/states/state_regions_importer.cpp b/src/vic3_world/states/state_regions_importer.cpp index 9d54bc26..ecee7646 100644 --- a/src/vic3_world/states/state_regions_importer.cpp +++ b/src/vic3_world/states/state_regions_importer.cpp @@ -1,5 +1,7 @@ #include "src/vic3_world/states/state_regions_importer.h" +#include + #include "external/commonItems/CommonRegexes.h" #include "external/commonItems/Log.h" #include "external/commonItems/Parser.h" @@ -55,20 +57,15 @@ vic3::StateRegions vic3::ImportStateRegions(const commonItems::ModFilesystem& fi region_parser.parseStream(input_stream); name_to_region_map.emplace(region_name, StateRegion(significant_provinces, provinces)); region_indexes.emplace(region_name, static_cast(region_indexes.size())); - for (const auto& [id, type]: significant_provinces) - { - if (!provinces.contains(id)) - { - Log(LogLevel::Warning) << fmt::format( - "Significant province {} ({}) does not correspond to a province in state region {}.", - id, - type, - region_name); - } - } }); - for (const auto& state_regions_file: filesystem.GetAllFilesInFolder("map_data/state_regions")) + const std::set files = filesystem.GetAllFilesInFolder("map_data/state_regions"); + std::vector sorted_files(files.begin(), files.end()); + std::ranges::sort(sorted_files, [](const std::string& a, const std::string& b) { + return std::filesystem::path(a).filename() < std::filesystem::path(b).filename(); + }); + + for (const std::string& state_regions_file: sorted_files) { file_parser.parseFile(state_regions_file); } From e9a652ae1e1ab00c057e3f70717a9d93cffd1245 Mon Sep 17 00:00:00 2001 From: Idhrendur Date: Mon, 16 Dec 2024 10:15:03 -0800 Subject: [PATCH 2/2] Remove test of removed behavior. --- .../states/state_regions_importer_tests.cpp | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/src/vic3_world/states/state_regions_importer_tests.cpp b/src/vic3_world/states/state_regions_importer_tests.cpp index e6142c63..8803befe 100644 --- a/src/vic3_world/states/state_regions_importer_tests.cpp +++ b/src/vic3_world/states/state_regions_importer_tests.cpp @@ -51,34 +51,4 @@ TEST(Vic3worldStatesStateRegionsImporterTests, ItemsAreImported) testing::Pair("STATE_PIEDMONT", 2))); } - -TEST(Vic3worldStatesStateRegionsImporterTests, BadSpecialProvincesAreLogged) -{ - std::stringstream log; - std::streambuf* cout_buffer = std::cout.rdbuf(); - std::cout.rdbuf(log.rdbuf()); - - const commonItems::ModFilesystem mod_filesystem("test_files/vic3_world/states/BadSpecialProvincesAreLogged/game", - {}); - const StateRegions _ = ImportStateRegions(mod_filesystem); - - std::cout.rdbuf(cout_buffer); - - EXPECT_THAT(log.str(), - testing::HasSubstr("[WARNING] Significant province x9686A5 (city) does not correspond to a province in state " - "region STATE_SVEALAND.")); - EXPECT_THAT(log.str(), - testing::HasSubstr("[WARNING] Significant province x93C3BC (port) does not correspond to a province in state " - "region STATE_SVEALAND.")); - EXPECT_THAT(log.str(), - testing::HasSubstr("[WARNING] Significant province xF48646 (farm) does not correspond to a province in state " - "region STATE_SVEALAND.")); - EXPECT_THAT(log.str(), - testing::HasSubstr("[WARNING] Significant province x6F40EC (mine) does not correspond to a province in state " - "region STATE_SVEALAND.")); - EXPECT_THAT(log.str(), - testing::HasSubstr("[WARNING] Significant province x4C9918 (wood) does not correspond to a province in state " - "region STATE_SVEALAND.")); -} - } // namespace vic3 \ No newline at end of file