diff --git a/ImperatorToCK3/CK3/Characters/CharacterCollection.cs b/ImperatorToCK3/CK3/Characters/CharacterCollection.cs index 72a178415..6e83f51bf 100644 --- a/ImperatorToCK3/CK3/Characters/CharacterCollection.cs +++ b/ImperatorToCK3/CK3/Characters/CharacterCollection.cs @@ -836,8 +836,7 @@ public void RemoveUndefinedTraits(TraitMapper traitMapper) { } var traitsField = character.History.Fields["traits"]; - int removedCount = traitsField.InitialEntries.RemoveAll( - kvp => !definedTraits.Contains(kvp.Value.ToString() ?? string.Empty)); + int removedCount = traitsField.RemoveAllEntries(value => !definedTraits.Contains(value.ToString() ?? string.Empty)); if (removedCount > 0) { Logger.Debug($"Removed {removedCount} undefined traits from character {character.Id}."); } diff --git a/ImperatorToCK3/CommonUtils/IHistoryField.cs b/ImperatorToCK3/CommonUtils/IHistoryField.cs index 9c3a4764a..7b651bad9 100644 --- a/ImperatorToCK3/CommonUtils/IHistoryField.cs +++ b/ImperatorToCK3/CommonUtils/IHistoryField.cs @@ -30,11 +30,14 @@ public void RemoveAllEntries() { /// Removes all entries with values matching the predicate /// /// - public void RemoveAllEntries(Func predicate) { - InitialEntries.RemoveAll(kvp => predicate(kvp.Value)); + public int RemoveAllEntries(Func predicate) { + int removed = 0; + removed += InitialEntries.RemoveAll(kvp => predicate(kvp.Value)); foreach (var datedEntriesBlock in DateToEntriesDict) { - datedEntriesBlock.Value.RemoveAll(kvp => predicate(kvp.Value)); + removed += datedEntriesBlock.Value.RemoveAll(kvp => predicate(kvp.Value)); } + + return removed; } public void RegisterKeywords(Parser parser, Date date);