Skip to content

Prevent exception when determining map edge provinces #2117

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

Merged
merged 2 commits into from
Aug 31, 2024
Merged
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
8 changes: 7 additions & 1 deletion ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
LoadProvincesHistory(ck3ModFs);
}

private void LoadProvinceDefinitions(ModFilesystem ck3ModFs) { // TODO: get rid of this (duplicates functionality of ProvinceDefinitions class)

Check warning on line 26 in ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs

View workflow job for this annotation

GitHub Actions / build (self-hosted, linux)

TODO get rid of this (duplicates functionality of ProvinceDefinitions class) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 26 in ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs

View workflow job for this annotation

GitHub Actions / build (macos-14)

TODO get rid of this (duplicates functionality of ProvinceDefinitions class) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 26 in ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs

View workflow job for this annotation

GitHub Actions / test (macos-14)

TODO get rid of this (duplicates functionality of ProvinceDefinitions class) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 26 in ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs

View workflow job for this annotation

GitHub Actions / build (self-hosted, windows)

TODO get rid of this (duplicates functionality of ProvinceDefinitions class) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 26 in ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs

View workflow job for this annotation

GitHub Actions / test_and_check_coverage

TODO get rid of this (duplicates functionality of ProvinceDefinitions class) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 26 in ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs

View workflow job for this annotation

GitHub Actions / test (self-hosted, windows)

TODO get rid of this (duplicates functionality of ProvinceDefinitions class) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
Logger.Info("Loading CK3 province definitions...");

var filePath = ck3ModFs.GetActualFileLocation("map_data/definition.csv");
Expand Down Expand Up @@ -159,7 +159,13 @@
var parser = new Parser();
parser.RegisterRegex(CommonRegexes.Integer, (reader, provIdStr) => {
var provId = ulong.Parse(provIdStr);
this[provId].UpdateHistory(reader);

if (TryGetValue(provId, out var province)) {
province.UpdateHistory(reader);
} else {
Logger.Warn($"Province {provId} referenced in prehistory not found!");
ParserHelpers.IgnoreItem(reader);
}
});
parser.IgnoreAndLogUnregisteredItems();
parser.ParseFile(prehistoryPath);
Expand Down
24 changes: 20 additions & 4 deletions ImperatorToCK3/CommonUtils/Map/MapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,21 +493,37 @@ private void DetermineMapEdgeProvinces(ModFilesystem modFS) {
for (var y = 0; y < height; ++y) {
// Get left edge color.
var color = GetPixelColor(new Point(0, y), mapPng);
mapEdgeProvinces.Add(ProvinceDefinitions.ColorToProvinceDict[color]);
if (ProvinceDefinitions.ColorToProvinceDict.TryGetValue(color, out var provinceId)) {
mapEdgeProvinces.Add(provinceId);
} else {
Logger.Warn($"Province not found for color {color}!");
}

// Get right edge color.
color = GetPixelColor(new Point(width - 1, y), mapPng);
mapEdgeProvinces.Add(ProvinceDefinitions.ColorToProvinceDict[color]);
if (ProvinceDefinitions.ColorToProvinceDict.TryGetValue(color, out provinceId)) {
mapEdgeProvinces.Add(provinceId);
} else {
Logger.Warn($"Province not found for color {color}!");
}
}

for (var x = 0; x < width; ++x) {
// Get top edge color.
var color = GetPixelColor(new Point(x, 0), mapPng);
mapEdgeProvinces.Add(ProvinceDefinitions.ColorToProvinceDict[color]);
if (ProvinceDefinitions.ColorToProvinceDict.TryGetValue(color, out var provinceId)) {
mapEdgeProvinces.Add(provinceId);
} else {
Logger.Warn($"Province not found for color {color}!");
}

// Get bottom edge color.
color = GetPixelColor(new Point(x, height - 1), mapPng);
mapEdgeProvinces.Add(ProvinceDefinitions.ColorToProvinceDict[color]);
if (ProvinceDefinitions.ColorToProvinceDict.TryGetValue(color, out provinceId)) {
mapEdgeProvinces.Add(provinceId);
} else {
Logger.Warn($"Province not found for color {color}!");
}
}
}
}
Loading