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

Log when province mappings are in the wrong region. #644

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 37 additions & 7 deletions src/mappers/provinces/province_mapper_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ std::map<std::string, std::string> GenerateProvinceToStateMap(
}

void AreVic3ProvincesFromSameState(const std::vector<std::string>& provinces_from_map,
std::map<std::string, std::string> province_to_state_map)
const std::map<std::string, std::string>& province_to_state_map)
{
std::set<std::string> state_names;
for (const auto& province: provinces_from_map)
{
auto linked_state = province_to_state_map.find(province);
if (linked_state != province_to_state_map.end())
if (auto linked_state = province_to_state_map.find(province); linked_state != province_to_state_map.end())
{
state_names.insert(linked_state->second);
}
Expand All @@ -82,7 +81,26 @@ void AreVic3ProvincesFromSameState(const std::vector<std::string>& provinces_fro
"Province {} is designated as part of {} in Vic3 data and is placed in a mapping with provinces from "
"other states.",
province_from_map,
province_to_state_map[province_from_map]);
province_to_state_map.at(province_from_map));
}
}
}


void IsMappingInWrongRegion(std::string_view current_region,
const std::vector<std::string>& provinces_from_map,
const std::map<std::string, std::string>& province_to_state_map)
{
for (const auto& province: provinces_from_map)
{
auto linked_state = province_to_state_map.find(province);
if (linked_state != province_to_state_map.end() && linked_state->second != current_region)
{
Log(LogLevel::Warning) << fmt::format(
Idhrendur marked this conversation as resolved.
Show resolved Hide resolved
"Province {} is designated as part of {} in Vic3 data and is placed in a mapping in the {} region.",
province,
province_to_state_map.at(province),
current_region);
}
}
}
Expand All @@ -92,7 +110,7 @@ void CheckAllHoi4ProvincesMapped(const mappers::Hoi4ToVic3ProvinceMapping& hoi4_
const commonItems::ModFilesystem& filesystem)
{
const auto definition_location = filesystem.GetActualFileLocation("/map/definition.csv");
if (!definition_location.has_value())
if (!definition_location.has_value())
{
throw std::runtime_error("Could not find /map/definition.csv");
}
Expand Down Expand Up @@ -136,17 +154,28 @@ mappers::ProvinceMapperImporter::ProvinceMapperImporter(const commonItems::ModFi

mapping_parser_.registerKeyword("link", [this, vic3_state_regions](std::istream& input_stream) {
const auto the_mapping = mapping_importer_.ImportProvinceMapping(input_stream);
if (the_mapping.comment.has_value())
{
current_region_ = the_mapping.comment.value();
}
if (the_mapping.vic3_provinces.empty() && the_mapping.hoi4_provinces.empty())
{
return;
}

if (!vic3_state_regions.empty())
{
auto vic3_province = the_mapping.vic3_provinces;
AreVic3ProvincesFromSameState(vic3_province, province_to_state_map_);
AreVic3ProvincesFromSameState(the_mapping.vic3_provinces, province_to_state_map_);
}

if (!vic3_state_regions.empty())
Idhrendur marked this conversation as resolved.
Show resolved Hide resolved
{
AreVic3ProvincesFromSameState(the_mapping.vic3_provinces, province_to_state_map_);
}
if (!vic3_state_regions.empty())
{
IsMappingInWrongRegion(current_region_, the_mapping.vic3_provinces, province_to_state_map_);
}

for (auto color: the_mapping.vic3_provinces)
{
Expand All @@ -171,6 +200,7 @@ mappers::ProvinceMapperImporter::ProvinceMapperImporter(const commonItems::ModFi

mappers::ProvinceMapper mappers::ProvinceMapperImporter::ImportProvinceMappings()
{
Log(LogLevel::Info) << "Importing province mappings.";
vic3_to_hoi4_province_map_.clear();
hoi4_to_vic3_province_map_.clear();

Expand Down
2 changes: 2 additions & 0 deletions src/mappers/provinces/province_mapper_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ProvinceMapperImporter
commonItems::parser mapping_parser_;
ProvinceMappingImporter mapping_importer_;

std::string current_region_;

Vic3ToHoi4ProvinceMapping vic3_to_hoi4_province_map_;
Hoi4ToVic3ProvinceMapping hoi4_to_vic3_province_map_;
std::map<std::string, std::string> province_to_state_map_;
Expand Down
3 changes: 3 additions & 0 deletions src/mappers/provinces/province_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@



#include <optional>
#include <string>
#include <vector>


Expand All @@ -14,6 +16,7 @@ struct ProvinceMapping
{
std::vector<std::string> vic3_provinces;
std::vector<int> hoi4_provinces;
std::optional<std::string> comment;
};

} // namespace mappers
Expand Down
15 changes: 13 additions & 2 deletions src/mappers/provinces/province_mapping_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ mappers::ProvinceMappingImporter::ProvinceMappingImporter()
parser_.registerKeyword("hoi4", [this](std::istream& theStream) {
hoi4_provinces_.push_back(commonItems::getInt(theStream));
});
parser_.registerKeyword("comment", commonItems::ignoreItem);
parser_.registerKeyword("comment", [this](std::istream& the_stream) {
Idhrendur marked this conversation as resolved.
Show resolved Hide resolved
const std::string raw_string = commonItems::getString(the_stream);
if (const size_t start = raw_string.find_first_not_of("* "); start != std::string::npos)
{
comment_ = raw_string.substr(start, raw_string.length());
if (const size_t last = comment_.value().find_last_not_of("* "); last != std::string::npos)
{
comment_ = comment_.value().substr(0, last + 1);
}
}
});
parser_.IgnoreAndLogUnregisteredItems();
}

Expand All @@ -27,8 +37,9 @@ mappers::ProvinceMapping mappers::ProvinceMappingImporter::ImportProvinceMapping
{
vic3_provinces_.clear();
hoi4_provinces_.clear();
comment_.reset();

parser_.parseStream(input_stream);

return ProvinceMapping{vic3_provinces_, hoi4_provinces_};
return ProvinceMapping{.vic3_provinces = vic3_provinces_, .hoi4_provinces = hoi4_provinces_, .comment = comment_};
}
5 changes: 4 additions & 1 deletion src/mappers/provinces/province_mapping_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@



#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "external/commonItems/Parser.h"
#include "src/mappers/provinces/province_mapping.h"
Expand All @@ -24,6 +26,7 @@ class ProvinceMappingImporter

std::vector<std::string> vic3_provinces_;
std::vector<int> hoi4_provinces_;
std::optional<std::string> comment_;
};

} // namespace mappers
Expand Down
Loading