EDBGS/EliteBGS/Report.cs
Florian Stinglmayr 34e0a0c8ba change layout of tree to go: system / faction / bgs
This was requested by some very special commanders who, after a massive BGS bender, have very long lists in terms of BGS actions taken
2024-04-11 16:25:20 +02:00

56 lines
1.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using EDPlayerJournal.BGS;
namespace EliteBGS;
public class SystemObjectives {
public bool IsEnabled { get; set; } = true;
public bool IsExpanded { get; set; } = false;
public string SystemName { get; set; } = string.Empty;
public List<Objective> Objectives { get; set; } = new();
}
public class Report {
public List<SystemObjectives> SystemObjectives { get; set; } = new();
public Report() { }
public Report(List<Transaction> transactions) {
Populate(transactions);
}
public List<Objective> Objectives {
get {
return SystemObjectives
.Where(t => t.IsEnabled)
.SelectMany(x => x.Objectives)
.ToList()
;
}
}
private void Populate(List<Transaction> transactions) {
if (transactions == null || transactions.Count == 0) {
return;
}
foreach (Transaction t in transactions) {
var o = SystemObjectives.Find(x => string.Compare(x.SystemName, t.System) == 0);
if (o == null) {
o = new SystemObjectives() { SystemName = t.System };
SystemObjectives.Add(o);
}
var objective = o.Objectives.Find(x => x.Matches(t.System, t.Faction));
if (objective == null) {
objective = new Objective() { Faction = t.Faction, System = t.System };
o.Objectives.Add(objective);
}
objective.UITransactions.Add(new UITransaction(t));
}
}
}