Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly get province indexes from mods #685

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> files = filesystem.GetAllFilesInFolder("common/strategic_regions");
std::vector<std::string> 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")
{
Expand Down
21 changes: 9 additions & 12 deletions src/vic3_world/states/state_regions_importer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "src/vic3_world/states/state_regions_importer.h"

#include <filesystem>

#include "external/commonItems/CommonRegexes.h"
#include "external/commonItems/Log.h"
#include "external/commonItems/Parser.h"
Expand Down Expand Up @@ -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<int>(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<std::string> files = filesystem.GetAllFilesInFolder("map_data/state_regions");
std::vector<std::string> 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);
}
Expand Down
30 changes: 0 additions & 30 deletions src/vic3_world/states/state_regions_importer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading