Skip to content

Commit

Permalink
Also removed undefined traits from dated history entries
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Jan 5, 2025
1 parent 64b00e2 commit 4b1437c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}.");
}
Expand Down
9 changes: 6 additions & 3 deletions ImperatorToCK3/CommonUtils/IHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ public void RemoveAllEntries() {
/// Removes all entries with values matching the predicate
/// </summary>
/// <param name="predicate"></param>
public void RemoveAllEntries(Func<object, bool> predicate) {
InitialEntries.RemoveAll(kvp => predicate(kvp.Value));
public int RemoveAllEntries(Func<object, bool> 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);
Expand Down

0 comments on commit 4b1437c

Please sign in to comment.