From 116e6b4e26a2dfc572347578498c268035d6e76c Mon Sep 17 00:00:00 2001 From: T'kael Date: Mon, 27 May 2024 19:59:09 -0700 Subject: [PATCH] Fix failing unit tests --- JournalMonitor/JournalMonitor.cs | 42 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/JournalMonitor/JournalMonitor.cs b/JournalMonitor/JournalMonitor.cs index a4c51a0495..5b2b7b4fe3 100644 --- a/JournalMonitor/JournalMonitor.cs +++ b/JournalMonitor/JournalMonitor.cs @@ -5232,30 +5232,40 @@ private static Faction GetFaction(IDictionary data, string type, }; faction.presences.Add( factionPresense ); } + } + + // Since systems can have Thargoid allegiance, treat Thargoids like a faction for the purpose of + // allegiance and government (even when no human faction exists). - // Get the faction allegiance - if ( data.TryGetValue( type + "Allegiance", out _ ) ) + // Get the faction allegiance + if ( data.TryGetValue( type + "Allegiance", out _ ) ) + { + if ( faction is null ) { faction = new Faction(); } + faction.Allegiance = GetAllegiance( data, type + "Allegiance" ); + if ( string.IsNullOrEmpty( faction.name ) && faction.Allegiance != null ) { - faction.Allegiance = GetAllegiance( data, type + "Allegiance" ); + faction.name = faction.Allegiance.localizedName; } - else if ( data.TryGetValue( "Factions", out var val ) ) + } + else if ( data.TryGetValue( "Factions", out var val ) && val is List factionsList ) + { + // Station controlling faction government is not discretely available in 'Location' event + if ( faction is null ) { faction = new Faction(); } + foreach ( IDictionary factionDetail in factionsList ) { - // Station controlling faction government not discretely available in 'Location' event - if ( val is List factionsList ) + string fName = JsonParsing.getString( factionDetail, "Name" ); + if ( fName == faction.name ) { - foreach ( IDictionary factionDetail in factionsList ) - { - string fName = JsonParsing.getString( factionDetail, "Name" ); - if ( fName == faction.name ) - { - faction.Allegiance = GetAllegiance( factionDetail, "Allegiance" ); - break; - } - } + faction.Allegiance = GetAllegiance( factionDetail, "Allegiance" ); + break; } } + } - // Get the controlling faction (system or station) government + // Get the controlling faction (system or station) government + if ( data.TryGetValue( type + "Government", out _ ) ) + { + if ( faction is null ) { faction = new Faction(); } faction.Government = Government.FromEDName( JsonParsing.getString( data, type + "Government" ) ) ?? Government.None; }