From c695e41f08b5135d255df700bac9663e47cea430 Mon Sep 17 00:00:00 2001 From: iht Date: Mon, 9 Jun 2025 19:52:40 +0200 Subject: [PATCH 1/2] Tweaks to the province outputting code --- .../Outputter/ProvincesOutputter.cs | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/ImperatorToCK3/Outputter/ProvincesOutputter.cs b/ImperatorToCK3/Outputter/ProvincesOutputter.cs index bf983da6e..227562d51 100644 --- a/ImperatorToCK3/Outputter/ProvincesOutputter.cs +++ b/ImperatorToCK3/Outputter/ProvincesOutputter.cs @@ -17,7 +17,7 @@ public static async Task OutputProvinces( Title.LandedTitles titles ) { Logger.Info("Writing provinces..."); - + FrozenSet countyCapitalProvinceIds = titles.Counties.AsValueEnumerable() .Select(title => title.CapitalBaronyProvinceId) .Where(id => id is not null) @@ -25,7 +25,7 @@ Title.LandedTitles titles .ToFrozenSet(); // Output provinces to files named after their de jure kingdoms. - var alreadyOutputtedProvinces = new ConcurrentHashSet(); + var alreadyOutputtedProvIds = new ConcurrentHashSet(); var deJureKingdoms = titles.GetDeJureKingdoms(); Parallel.ForEach(deJureKingdoms, kingdom => { @@ -36,7 +36,7 @@ Title.LandedTitles titles } ProvinceOutputter.WriteProvince(sb, province, countyCapitalProvinceIds.Contains(province.Id)); - alreadyOutputtedProvinces.Add(province.Id); + alreadyOutputtedProvIds.Add(province.Id); } var filePath = $"{outputModPath}/history/provinces/{kingdom.Id}.txt"; @@ -44,52 +44,55 @@ Title.LandedTitles titles historyOutput.Write(sb.ToString()); }); - if (alreadyOutputtedProvinces.Count != provinces.Count) { + if (alreadyOutputtedProvIds.Count != provinces.Count) { var filePath = $"{outputModPath}/history/provinces/onlyDeJureDuchy.txt"; await using var historyOutput = TextWriter.Synchronized(new StreamWriter(filePath)); var deJureDuchies = titles.GetDeJureDuchies(); - Parallel.ForEach(deJureDuchies, duchy => { + foreach (var duchy in deJureDuchies) { var sb = new System.Text.StringBuilder(); foreach (var province in provinces) { - if (alreadyOutputtedProvinces.Contains(province.Id)) { + if (alreadyOutputtedProvIds.Contains(province.Id)) { continue; } if (duchy.DuchyContainsProvince(province.Id)) { sb.AppendLine($"# {duchy.Id}"); ProvinceOutputter.WriteProvince(sb, province, countyCapitalProvinceIds.Contains(province.Id)); - alreadyOutputtedProvinces.Add(province.Id); + alreadyOutputtedProvIds.Add(province.Id); } } if (sb.Length > 0) { - historyOutput.Write(sb.ToString()); + await historyOutput.WriteAsync(sb.ToString()); } - }); + } } - // Create province mapping file. - if (alreadyOutputtedProvinces.Count != provinces.Count) { - var mappingsPath = $"{outputModPath}/history/province_mapping/province_mapping.txt"; - await using var mappingsWriter = FileHelper.OpenWriteWithRetries(mappingsPath, System.Text.Encoding.UTF8); - await using var threadSafeWriter = TextWriter.Synchronized(mappingsWriter); + if (alreadyOutputtedProvIds.Count != provinces.Count) { + await CreateProvinceMappingFile(outputModPath, provinces, alreadyOutputtedProvIds); + } - foreach (var province in provinces) { - if (alreadyOutputtedProvinces.Contains(province.Id)) { - continue; - } + Logger.IncrementProgress(); + } - var baseProvId = province.BaseProvinceId; - if (baseProvId is null) { - continue; - } + private static async Task CreateProvinceMappingFile(string outputModPath, ProvinceCollection provinces, ConcurrentHashSet alreadyOutputtedProvinceIds) { + var mappingsPath = $"{outputModPath}/history/province_mapping/province_mapping.txt"; + await using var mappingsWriter = FileHelper.OpenWriteWithRetries(mappingsPath, System.Text.Encoding.UTF8); + await using var threadSafeWriter = TextWriter.Synchronized(mappingsWriter); - await threadSafeWriter.WriteLineAsync($"{province.Id} = {baseProvId}"); - alreadyOutputtedProvinces.Add(province.Id); + foreach (var province in provinces) { + if (alreadyOutputtedProvinceIds.Contains(province.Id)) { + continue; } - } - Logger.IncrementProgress(); + var baseProvId = province.BaseProvinceId; + if (baseProvId is null) { + continue; + } + + await threadSafeWriter.WriteLineAsync($"{province.Id} = {baseProvId}"); + alreadyOutputtedProvinceIds.Add(province.Id); + } } } \ No newline at end of file From e61465b14bac57a262fca7eb256041d4035ecaf9 Mon Sep 17 00:00:00 2001 From: iht Date: Mon, 9 Jun 2025 19:57:23 +0200 Subject: [PATCH 2/2] Update changelog-config.json --- .github/config/changelog-config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/config/changelog-config.json b/.github/config/changelog-config.json index d40a0a149..e63069f37 100644 --- a/.github/config/changelog-config.json +++ b/.github/config/changelog-config.json @@ -8,6 +8,10 @@ "title": "## ๐Ÿ› Fixes", "labels": ["fix"] }, + { + "title": "## ๐Ÿงน Maintenance", + "labels": ["maintenance", "chore", "refactor"] + }, { "title": "## ๐Ÿงช Tests", "labels": ["test"]