Skip to content

Commit

Permalink
Prevent exception when adding a character from Imperator with a taken…
Browse files Browse the repository at this point in the history
… ID (#1549)
  • Loading branch information
IhateTrains authored Oct 6, 2023
1 parent 8a90771 commit 15e1359
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Configuration config
config
);
character.CK3Character = newCharacter;
Add(newCharacter);
AddOrReplace(newCharacter);
}

public override void Remove(string key) {
Expand Down
7 changes: 6 additions & 1 deletion ImperatorToCK3/CK3/Titles/RulerTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace ImperatorToCK3.CK3.Titles;

public class RulerTerm {
public string CharacterId { get; } = "0";
public string? CharacterId { get; }
public Date StartDate { get; }
public string? Government { get; }
public Imperator.Countries.RulerTerm.PreImperatorRulerInfo? PreImperatorRuler { get; }
Expand Down Expand Up @@ -55,6 +55,11 @@ Configuration config
provinceMapper,
config
);
if (characters.ContainsKey(character.Id)) {
Logger.Warn($"Cannot add pre-Imperator ruler {character.Id} " +
$"- a character with this ID already exists!");
return;
}
characters.Add(character);
CharacterId = character.Id;
}
Expand Down
3 changes: 3 additions & 0 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ void FillHolderAndGovernmentHistory() {
);

var characterId = rulerTerm.CharacterId;
if (characterId is null) {
continue;
}
var gov = rulerTerm.Government;

var termStartDate = new Date(rulerTerm.StartDate);
Expand Down

0 comments on commit 15e1359

Please sign in to comment.