Skip to content

Commit

Permalink
Fix an error while converting Imperator characters (#2176) #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Sep 12, 2024
1 parent 0169aa1 commit 1b235a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
19 changes: 12 additions & 7 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ Configuration config
var parallelOptions = new ParallelOptions {
MaxDegreeOfParallelism = Environment.ProcessorCount - 1,
};
Parallel.ForEach(impWorld.Characters, parallelOptions, irCharacter => {
try {

try {
Parallel.ForEach(impWorld.Characters, parallelOptions, irCharacter => {
ImportImperatorCharacter(
irCharacter,
religionMapper,
Expand All @@ -64,11 +65,15 @@ Configuration config
config,
unlocalizedImperatorNames
);
} catch (Exception e) {
Logger.Error($"Exception while importing Imperator character {irCharacter.Id}: {e}");
Logger.Debug("Exception stack trace: " + e.StackTrace);
}
});
});
} catch (AggregateException e) {
var innerException = e.InnerExceptions[0];
Logger.Error("Exception thrown during Imperator characters import: " + innerException.Message);
Logger.Debug("Exception stack trace: " + innerException.StackTrace);

// Rethrow the inner exception to stop the program.
throw innerException;
}

if (unlocalizedImperatorNames.Any()) {
Logger.Warn("Found unlocalized Imperator names: " + string.Join(", ", unlocalizedImperatorNames));
Expand Down
9 changes: 5 additions & 4 deletions ImperatorToCK3/CK3/Localization/CK3LocBlock.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using commonItems.Collections;
using commonItems.Localization;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace ImperatorToCK3.CK3.Localization;

public class CK3LocBlock : IIdentifiable<string> { // TODO: add ILocBlock interface that both this and commonItems' LocBlock would implement.
private readonly string baseLanguage;
private readonly Dictionary<string, (string, CK3LocType)> localizations = new();
private readonly ConcurrentDictionary<string, (string, CK3LocType)> localizations = new();

public string Id { get; }

Expand Down Expand Up @@ -59,7 +60,7 @@ public string? this[string language] {
}
set {
if (value is null) {
localizations.Remove(language);
localizations.Remove(language, out _);
} else {
localizations[language] = (value, CK3LocType.ConverterGenerated);
}
Expand Down Expand Up @@ -96,7 +97,7 @@ public void ModifyForEveryLanguage(CK3LocBlock otherBlock, TwoArgLocDelegate mod
foreach (var language in localizations.Keys) {
var locValue = modifyingFunction(localizations[language].Item1, otherBlock[language], language);
if (locValue is null) {
localizations.Remove(language);
localizations.Remove(language, out _);
continue;
}
localizations[language] = (locValue, CK3LocType.ConverterGenerated);
Expand All @@ -112,7 +113,7 @@ public void ModifyForEveryLanguage(LocDelegate modifyingFunction) {
foreach (var language in localizations.Keys) {
var locValue = modifyingFunction(localizations[language].Item1, language);
if (locValue is null) {
localizations.Remove(language);
localizations.Remove(language, out _);
continue;
}
localizations[language] = (locValue, CK3LocType.ConverterGenerated);
Expand Down

0 comments on commit 1b235a1

Please sign in to comment.