1- using System . Collections . Generic ;
2- using commonItems ;
1+ using commonItems ;
32using ImperatorToCK3 . Imperator . Families ;
3+ using System . Collections . Generic ;
4+ using System . Linq ;
45
56namespace ImperatorToCK3 . Imperator . Characters {
67 public class Character {
@@ -33,7 +34,8 @@ public string Culture {
3334 public Date ? DeathDate { get ; private set ; }
3435 public bool IsDead => DeathDate is not null ;
3536 public string ? DeathReason { get ; set ; }
36- public Dictionary < ulong , Character ? > Spouses { get ; set ; } = new ( ) ;
37+ private HashSet < ulong > parsedSpouseIds = new ( ) ;
38+ public Dictionary < ulong , Character > Spouses { get ; set ; } = new ( ) ;
3739 public Dictionary < ulong , Character ? > Children { get ; set ; } = new ( ) ;
3840 public KeyValuePair < ulong , Character ? > Mother { get ; set ; } = new ( ) ;
3941 public KeyValuePair < ulong , Character ? > Father { get ; set ; } = new ( ) ;
@@ -141,9 +143,7 @@ static Character() {
141143 parsedCharacter . Wealth = ParserHelpers . GetDouble ( reader ) ;
142144 } ) ;
143145 parser . RegisterKeyword ( "spouse" , reader => {
144- foreach ( var spouse in ParserHelpers . GetULongs ( reader ) ) {
145- parsedCharacter . Spouses . Add ( spouse , null ) ;
146- }
146+ parsedCharacter . parsedSpouseIds = ParserHelpers . GetULongs ( reader ) . ToHashSet ( ) ;
147147 } ) ;
148148 parser . RegisterKeyword ( "children" , reader => {
149149 foreach ( var child in ParserHelpers . GetULongs ( reader ) ) {
@@ -170,5 +170,20 @@ public static Character Parse(BufferedReader reader, string idString, Genes.Gene
170170
171171 return parsedCharacter ;
172172 }
173+
174+ // Returns counter of linked spouses
175+ public int LinkSpouses ( Dictionary < ulong , Character > characters ) {
176+ var counter = 0 ;
177+ foreach ( var spouseId in parsedSpouseIds ) {
178+ if ( characters . TryGetValue ( spouseId , out var spouseToLink ) ) {
179+ Spouses . Add ( spouseToLink . Id , spouseToLink ) ;
180+ ++ counter ;
181+ } else {
182+ Logger . Warn ( $ "Spouse ID: { spouseId } has no definition!") ;
183+ }
184+ }
185+
186+ return counter ;
187+ }
173188 }
174189}
0 commit comments