EDBGS/EDPlayerJournal/Entries/LocationEntry.cs

81 lines
2.3 KiB
C#
Raw Normal View History

using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
2022-11-01 18:01:28 +01:00
public class LocationEntry : Entry {
/// <summary>
/// Current star system.
/// </summary>
2022-11-01 18:01:28 +01:00
public string? StarSystem { get; set; }
/// <summary>
/// Faction in control of the current star system. Empty for unpopulated
/// systems.
/// </summary>
2022-11-01 18:01:28 +01:00
public string? SystemFaction { get; set; }
/// <summary>
/// 64bit system address.
/// </summary>
2022-11-01 18:01:28 +01:00
public ulong SystemAddress { get; set; }
/// <summary>
/// Station name if docked at a station.
/// </summary>
public string? StationName { get; set; }
/// <summary>
/// Faction in control of the current station, if docked.
/// </summary>
public string? StationFaction { get; set; }
/// <summary>
/// Body within the system, might be null.
/// </summary>
2022-11-01 18:01:28 +01:00
public string? Body { get; set; }
/// <summary>
/// Returns true if the player is docked somewhere.
/// </summary>
2022-11-01 18:01:28 +01:00
public bool Docked { get; set; }
/// <summary>
/// Position of the star system.
/// </summary>
2022-11-01 18:01:28 +01:00
public long[]? StarPos { get; set; }
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
protected override void Initialise() {
StarSystem = JSON.Value<string>("StarSystem") ?? "";
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
Docked = JSON.Value<bool?>("Docked") ?? false;
StationName = JSON.Value<string>("StationName") ?? "";
var pos = JSON.Value<JArray>("StarPos");
if (pos != null) {
StarPos = pos.ToObject<long[]>();
}
JObject? systemfaction = JSON.Value<JObject>("SystemFaction");
if (systemfaction != null) {
SystemFaction = systemfaction.Value<string>("Name");
}
JObject? stationfaction = JSON.Value<JObject>("StationFaction");
if (stationfaction != null) {
StationFaction = stationfaction.Value<string>("Name");
2022-11-01 18:01:28 +01:00
}
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);
}
}
}
}
}