provide detailed faction information from Location and FSDJump
This commit is contained in:
parent
47d3fd778e
commit
69f76ba3fb
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace EDJournal {
|
namespace EDJournal {
|
||||||
public class FSDJumpEntry : Entry {
|
public class FSDJumpEntry : Entry {
|
||||||
@ -9,11 +10,23 @@ namespace EDJournal {
|
|||||||
if (faction != null) {
|
if (faction != null) {
|
||||||
SystemFaction = faction.Value<string>("Name");
|
SystemFaction = faction.Value<string>("Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JArray factions = JSON.Value<JArray>("Factions");
|
||||||
|
if (factions != null) {
|
||||||
|
foreach (JObject system_faction in factions) {
|
||||||
|
Faction f = Faction.FromJSON(system_faction);
|
||||||
|
if (f != null) {
|
||||||
|
SystemFactions.Add(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public string StarSystem { get; set; }
|
public string StarSystem { get; set; }
|
||||||
|
|
||||||
public string SystemFaction { get; set; }
|
public string SystemFaction { get; set; }
|
||||||
|
|
||||||
public ulong SystemAddress { get; set; }
|
public ulong SystemAddress { get; set; }
|
||||||
|
|
||||||
|
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
102
Faction.cs
Normal file
102
Faction.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace EDJournal {
|
||||||
|
public class FactionState {
|
||||||
|
public string State { get; set; }
|
||||||
|
public long Trend { get; set; }
|
||||||
|
|
||||||
|
public static FactionState FromJSON(JObject j) {
|
||||||
|
if (j == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
FactionState s = new FactionState() {
|
||||||
|
State = j.Value<string>("State") ?? "",
|
||||||
|
Trend = j.Value<long?>("Trend") ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(s.State)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Faction {
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string FactionState { get; set; }
|
||||||
|
public string Government { get; set; }
|
||||||
|
public double Influence { get; set; }
|
||||||
|
public string Allegiance { get; set; }
|
||||||
|
public string Happiness { get; set; }
|
||||||
|
public string HappinessLocalised { get; set; }
|
||||||
|
public double MyReputation { get; set; }
|
||||||
|
public bool SquadronFaction { get; set; } = false;
|
||||||
|
public bool HomeSystem { get; set; } = false;
|
||||||
|
|
||||||
|
public List<FactionState> RecoveringStates { get; set; } = new List<FactionState>();
|
||||||
|
public List<FactionState> ActiveStates { get; set; } = new List<FactionState>();
|
||||||
|
public List<FactionState> PendingStates { get; set; } = new List<FactionState>();
|
||||||
|
|
||||||
|
public static Faction FromJSON(JObject j) {
|
||||||
|
if (j == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Faction f = new Faction() {
|
||||||
|
Name = j.Value<string>("Name") ?? "",
|
||||||
|
FactionState = j.Value<string>("FactionState") ?? "",
|
||||||
|
Government = j.Value<string>("Government") ?? "",
|
||||||
|
Influence = j.Value<double?>("Influence") ?? 1.0,
|
||||||
|
Allegiance = j.Value<string>("Allegiance") ?? "",
|
||||||
|
Happiness = j.Value<string>("Happiness") ?? "",
|
||||||
|
HappinessLocalised = j.Value<string>("Happiness_Localised") ?? "",
|
||||||
|
MyReputation = j.Value<double?>("MyReputation") ?? 1.0,
|
||||||
|
SquadronFaction = j.Value<bool?>("SquadronFaction") ?? false,
|
||||||
|
HomeSystem = j.Value<bool?>("HomeSystem") ?? false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(f.Name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
JArray recovering_states = j.Value<JArray>("RecoveringStates");
|
||||||
|
if (recovering_states != null) {
|
||||||
|
foreach (JObject s in recovering_states) {
|
||||||
|
FactionState state = EDJournal.FactionState.FromJSON(s);
|
||||||
|
if (state != null) {
|
||||||
|
f.RecoveringStates.Add(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JArray active_states = j.Value<JArray>("ActiveStates");
|
||||||
|
if (active_states != null) {
|
||||||
|
foreach (JObject s in active_states) {
|
||||||
|
FactionState state = EDJournal.FactionState.FromJSON(s);
|
||||||
|
if (state != null) {
|
||||||
|
f.ActiveStates.Add(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JArray pending_states = j.Value<JArray>("PendingStates");
|
||||||
|
if (pending_states != null) {
|
||||||
|
foreach (JObject s in pending_states) {
|
||||||
|
FactionState state = EDJournal.FactionState.FromJSON(s);
|
||||||
|
if (state != null) {
|
||||||
|
f.PendingStates.Add(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,8 @@ namespace EDJournal {
|
|||||||
public string Body { get; set; }
|
public string Body { get; set; }
|
||||||
public bool Docked { get; set; }
|
public bool Docked { get; set; }
|
||||||
|
|
||||||
|
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
|
||||||
|
|
||||||
protected override void Initialise() {
|
protected override void Initialise() {
|
||||||
StarSystem = JSON.Value<string>("StarSystem") ?? "";
|
StarSystem = JSON.Value<string>("StarSystem") ?? "";
|
||||||
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
|
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
|
||||||
@ -24,6 +26,16 @@ namespace EDJournal {
|
|||||||
if (systemfaction != null) {
|
if (systemfaction != null) {
|
||||||
SystemFaction = systemfaction.Value<string>("Name") ?? "";
|
SystemFaction = systemfaction.Value<string>("Name") ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JArray factions = JSON.Value<JArray>("Factions");
|
||||||
|
if (factions != null) {
|
||||||
|
foreach (JObject system_faction in factions) {
|
||||||
|
Faction f = Faction.FromJSON(system_faction);
|
||||||
|
if (f != null) {
|
||||||
|
SystemFactions.Add(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
<Compile Include="EliteDangerous.cs" />
|
<Compile Include="EliteDangerous.cs" />
|
||||||
<Compile Include="Entry.cs" />
|
<Compile Include="Entry.cs" />
|
||||||
<Compile Include="Events.cs" />
|
<Compile Include="Events.cs" />
|
||||||
|
<Compile Include="Faction.cs" />
|
||||||
<Compile Include="FactionKillBondEntry.cs" />
|
<Compile Include="FactionKillBondEntry.cs" />
|
||||||
<Compile Include="FSDJumpEntry.cs" />
|
<Compile Include="FSDJumpEntry.cs" />
|
||||||
<Compile Include="HullDamageEntry.cs" />
|
<Compile Include="HullDamageEntry.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user