using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json.Linq; namespace EDPlayerJournal; 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("State"), Trend = j.Value("Trend"), }; if (string.IsNullOrEmpty(s.State)) { return null; } return s; } } public class Factions { /// /// Internal name for the Pilots Federation faction /// public static string PilotsFederation = "$faction_PilotsFederation;"; /// /// Internal name for the Thargoid faction /// public static string Thargoid = "$faction_Thargoid;"; } 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 RecoveringStates { get; set; } = new List(); public List ActiveStates { get; set; } = new List(); public List PendingStates { get; set; } = new List(); public static Faction? FromJSON(JObject j) { if (j == null) { return null; } Faction f = new Faction() { Name = j.Value("Name") ?? "", FactionState = j.Value("FactionState") ?? "", Government = j.Value("Government") ?? "", Influence = j.Value("Influence") ?? 1.0, Allegiance = j.Value("Allegiance") ?? "", Happiness = j.Value("Happiness") ?? "", HappinessLocalised = j.Value("Happiness_Localised") ?? "", MyReputation = j.Value("MyReputation") ?? 1.0, SquadronFaction = (j.Value("SquadronFaction") ?? false), HomeSystem = (j.Value("HomeSystem") ?? false), }; if (string.IsNullOrEmpty(f.Name)) { return null; } JArray? recovering_states = j.Value("RecoveringStates"); if (recovering_states != null) { foreach (JObject s in recovering_states) { FactionState? state = EDPlayerJournal.FactionState.FromJSON(s); if (state != null) { f.RecoveringStates.Add(state); } } } JArray? active_states = j.Value("ActiveStates"); if (active_states != null) { foreach (JObject s in active_states) { FactionState? state = EDPlayerJournal.FactionState.FromJSON(s); if (state != null) { f.ActiveStates.Add(state); } } } JArray? pending_states = j.Value("PendingStates"); if (pending_states != null) { foreach (JObject s in pending_states) { FactionState? state = EDPlayerJournal.FactionState.FromJSON(s); if (state != null) { f.PendingStates.Add(state); } } } return f; } }