From 007b391dc2d35955718fe724bc54a02669c8d22a Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Wed, 18 Sep 2024 21:33:20 +0200 Subject: [PATCH] parse out commander names from logs --- EDPlayerJournal/BGS/Parsers/CommanderParser.cs | 17 +++++++++++++++++ EDPlayerJournal/BGS/TransactionParser.cs | 17 ++++++++--------- EDPlayerJournal/BGS/TransactionParserContext.cs | 5 +++++ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 EDPlayerJournal/BGS/Parsers/CommanderParser.cs diff --git a/EDPlayerJournal/BGS/Parsers/CommanderParser.cs b/EDPlayerJournal/BGS/Parsers/CommanderParser.cs new file mode 100644 index 0000000..0d1eac2 --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/CommanderParser.cs @@ -0,0 +1,17 @@ +using EDPlayerJournal.BGS; +using EDPlayerJournal.Entries; + +internal class CommanderParser : ITransactionParserPart { + public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + CommanderEntry commanderEntry = (CommanderEntry)entry; + if (commanderEntry != null && !string.IsNullOrEmpty(commanderEntry.FullName)) { + if (!context.Commanders.Contains(commanderEntry.FullName)) { + context.Commanders.Add(commanderEntry.FullName); + } + } + // A commander entry happens when you log out, and log back in again + // for example when switching from Open, to Solo or PG. + context.DiscernCombatZone(transactions, entry); + context.ResetCombatZone(); + } +} \ No newline at end of file diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index 1577b18..f8d0c1d 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -602,15 +602,6 @@ internal class DropshipDeployParser : ITransactionParserPart { } } -internal class CommanderParser : ITransactionParserPart { - public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - // A commander entry happens when you log out, and log back in again - // for example when switching from Open, to Solo or PG. - context.DiscernCombatZone(transactions, entry); - context.ResetCombatZone(); - } -} - public class TransactionParser { private static Dictionary ParserParts { get; } = new() { @@ -669,6 +660,11 @@ public class TransactionParser { return Parse(entries, defaultOptions); } + /// + /// List of commanders seen during parsing. + /// + public List Commanders { get; set; } = new(); + public List? Parse(IEnumerable entries, TransactionParserOptions options) { TransactionList transactions = new(); TransactionParserContext context = new(); @@ -686,6 +682,9 @@ public class TransactionParser { transactionParserPart.Parse(entry, context, options, transactions); } + // Copy out list of commanders seen + Commanders = context.Commanders; + return transactions.ToList(); } } diff --git a/EDPlayerJournal/BGS/TransactionParserContext.cs b/EDPlayerJournal/BGS/TransactionParserContext.cs index 34624e0..22b3e51 100644 --- a/EDPlayerJournal/BGS/TransactionParserContext.cs +++ b/EDPlayerJournal/BGS/TransactionParserContext.cs @@ -3,6 +3,11 @@ namespace EDPlayerJournal.BGS; internal class TransactionParserContext { + /// + /// List of commander names seen in the logs. May be empty. + /// + public List Commanders { get; } = new(); + /// /// Name of the current system the player is in. ///