parse out commander names from logs

This commit is contained in:
Florian Stinglmayr 2024-09-18 21:33:20 +02:00
parent 9918c7d559
commit 007b391dc2
3 changed files with 30 additions and 9 deletions

View File

@ -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();
}
}

View File

@ -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<string, ITransactionParserPart> ParserParts { get; } = new()
{
@ -669,6 +660,11 @@ public class TransactionParser {
return Parse(entries, defaultOptions);
}
/// <summary>
/// List of commanders seen during parsing.
/// </summary>
public List<string> Commanders { get; set; } = new();
public List<Transaction>? Parse(IEnumerable<Entry> 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();
}
}

View File

@ -3,6 +3,11 @@
namespace EDPlayerJournal.BGS;
internal class TransactionParserContext {
/// <summary>
/// List of commander names seen in the logs. May be empty.
/// </summary>
public List<string> Commanders { get; } = new();
/// <summary>
/// Name of the current system the player is in.
/// </summary>