introduce parser options

And use it to ignore exo biology data.
This commit is contained in:
Florian Stinglmayr 2023-03-02 20:09:19 +01:00
parent 2a393809fc
commit f9eb0d34f9

View File

@ -1,7 +1,14 @@
using EDPlayerJournal;
using EDPlayerJournal.Entries;
using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS;
namespace EDPlayerJournal.BGS;
public class TransactionParserOptions {
/// <summary>
/// Whether to ignore exo biology. It does not contribute to BGS, so this
/// is true per default.
/// </summary>
public bool IgnoreExoBiology { get; set; } = true;
}
internal class TransactionParserContext {
public string? CurrentSystem { get; set; }
@ -236,7 +243,7 @@ internal interface TransactionParserPart{
/// <param name="entry">The entry to parse</param>
/// <param name="context">Parsing context that may contain useful information</param>
/// <param name="transactions">List of parsed transactions</param>
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions);
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions);
}
/// <summary>
@ -245,7 +252,7 @@ internal interface TransactionParserPart{
/// as we are getting controlling faction, system factions, address and station name.
/// </summary>
internal class LocationParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
LocationEntry? entry = e as LocationEntry;
if (entry == null) {
throw new NotImplementedException();
@ -276,7 +283,7 @@ internal class LocationParser : TransactionParserPart {
}
internal class FSDJumpParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
FSDJumpEntry? entry = e as FSDJumpEntry;
if (entry == null) {
throw new NotImplementedException();
@ -309,7 +316,7 @@ internal class FSDJumpParser : TransactionParserPart {
}
internal class DockedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
DockedEntry? entry = e as DockedEntry;
if (entry == null) {
throw new NotImplementedException();
@ -339,7 +346,7 @@ internal class DockedParser : TransactionParserPart {
/// useful later when said NPC gets killed or murdered.
/// </summary>
internal class ShipTargetedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
ShipTargetedEntry? entry = e as ShipTargetedEntry;
if (entry == null) {
throw new NotImplementedException();
@ -374,7 +381,7 @@ internal class ShipTargetedParser : TransactionParserPart {
/// murder.
/// </summary>
internal class CommitCrimeParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
CommitCrimeEntry? entry = e as CommitCrimeEntry;
if (entry == null) {
throw new NotImplementedException();
@ -430,7 +437,7 @@ internal class CommitCrimeParser : TransactionParserPart {
}
internal class MissionsParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
MissionsEntry? missions = entry as MissionsEntry;
if (missions == null) {
@ -459,7 +466,7 @@ internal class MissionsParser : TransactionParserPart {
}
internal class MissionAcceptedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
MissionAcceptedEntry? entry = e as MissionAcceptedEntry;
if (entry == null) {
throw new NotImplementedException();
@ -485,7 +492,7 @@ internal class MissionAcceptedParser : TransactionParserPart {
}
internal class MissionCompletedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
MissionCompletedEntry? entry = e as MissionCompletedEntry;
if (entry == null || entry.Mission == null) {
throw new NotImplementedException();
@ -596,7 +603,7 @@ internal class MissionCompletedParser : TransactionParserPart {
}
internal class MissionFailedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
Mission? mission = null;
Location? accepted_location = null;
string? accepted_system = null;
@ -651,7 +658,7 @@ internal class MissionFailedParser : TransactionParserPart {
}
internal class SellExplorationDataParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
SellExplorationDataEntry? entry = e as SellExplorationDataEntry;
if (entry == null) {
throw new NotImplementedException();
@ -667,7 +674,12 @@ internal class SellExplorationDataParser : TransactionParserPart {
}
internal class SellOrganicDataParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
// If exo biology is ignored, simply do nothing
if (options.IgnoreExoBiology) {
return;
}
SellOrganicDataEntry? entry = e as SellOrganicDataEntry;
if (entry == null) {
throw new NotImplementedException();
@ -683,7 +695,7 @@ internal class SellOrganicDataParser : TransactionParserPart {
}
internal class MultiSellExplorationDataParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
MultiSellExplorationDataEntry? entry = e as MultiSellExplorationDataEntry;
if (entry == null) {
throw new NotImplementedException();
@ -699,7 +711,7 @@ internal class MultiSellExplorationDataParser : TransactionParserPart {
}
internal class RedeemVoucherParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
RedeemVoucherEntry? entry = e as RedeemVoucherEntry;
if (entry == null) {
throw new NotImplementedException();
@ -756,7 +768,7 @@ internal class RedeemVoucherParser : TransactionParserPart {
}
internal class SellMicroResourcesParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
SellMicroResourcesEntry? entry = e as SellMicroResourcesEntry;
if (entry == null) {
throw new NotImplementedException();
@ -772,7 +784,7 @@ internal class SellMicroResourcesParser : TransactionParserPart {
}
internal class SearchAndRescueParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
SearchAndRescueEntry? entry = e as SearchAndRescueEntry;
if (entry == null) {
throw new NotImplementedException();
@ -788,7 +800,7 @@ internal class SearchAndRescueParser : TransactionParserPart {
}
internal class MarketBuyParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
MarketBuyEntry? entry = e as MarketBuyEntry;
if (entry == null) {
throw new NotImplementedException();
@ -806,7 +818,7 @@ internal class MarketBuyParser : TransactionParserPart {
}
internal class MarketSellParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
long profit = 0;
MarketSellEntry? entry = e as MarketSellEntry;
@ -834,7 +846,7 @@ internal class MarketSellParser : TransactionParserPart {
}
internal class FactionKillBondParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
FactionKillBondEntry? entry = e as FactionKillBondEntry;
if (entry == null) {
throw new NotImplementedException();
@ -867,7 +879,7 @@ internal class FactionKillBondParser : TransactionParserPart {
}
internal class EmbarkDisembarkParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
if (e.Is(Events.Embark)) {
context.IsOnFoot = false;
} else if (e.Is(Events.Disembark)) {
@ -877,7 +889,7 @@ internal class EmbarkDisembarkParser : TransactionParserPart {
}
internal class SupercruiseEntryParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
// After a super cruise entry we are no longer on foot.
context.IsOnFoot = false;
context.DiscernCombatZone(transactions, entry);
@ -886,14 +898,14 @@ internal class SupercruiseEntryParser : TransactionParserPart {
}
internal class ShutdownParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
context.DiscernCombatZone(transactions, entry);
context.ResetCombatZone();
}
}
internal class CapShipBondParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
if (entry.GetType() != typeof(CapShipBondEntry)) {
return;
}
@ -903,7 +915,7 @@ internal class CapShipBondParser : TransactionParserPart {
}
internal class FileHeaderParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
FileHeaderEntry? fileheader = entry as FileHeaderEntry;
if (fileheader == null) {
@ -915,7 +927,7 @@ internal class FileHeaderParser : TransactionParserPart {
}
internal class ReceiveTextParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
ReceiveTextEntry? receivetext = entry as ReceiveTextEntry;
if (receivetext == null) {
@ -933,7 +945,7 @@ internal class ReceiveTextParser : TransactionParserPart {
}
internal class DiedParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
// You can't complete a combat zone if you die in it. Others might keep it open
// for you, but still you will not have completed it unless you jump back in.
context.ResetCombatZone();
@ -941,14 +953,14 @@ internal class DiedParser : TransactionParserPart {
}
internal class DropshipDeployParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
// On drop ship deploy we are now on foot
context.IsOnFoot = true;
}
}
internal class CommanderParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
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);
@ -1000,7 +1012,17 @@ public class TransactionParser {
return IsRelevant(e.Event);
}
/// <summary>
/// Parses a list of entries with default options.
/// </summary>
/// <param name="entries"></param>
/// <returns></returns>
public List<Transaction>? Parse(IEnumerable<Entry> entries) {
TransactionParserOptions defaultOptions = new();
return Parse(entries, defaultOptions);
}
public List<Transaction>? Parse(IEnumerable<Entry> entries, TransactionParserOptions options) {
TransactionList transactions = new();
TransactionParserContext context = new();
@ -1014,7 +1036,7 @@ public class TransactionParser {
}
TransactionParserPart transactionParserPart = ParserParts[entry.Event];
transactionParserPart.Parse(entry, context, transactions);
transactionParserPart.Parse(entry, context, options, transactions);
}
return transactions.ToList();