public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.StartObject) { // This is an object - use standard deserialization return(serializer.Deserialize <Volcanism>(reader)); } else if (reader.TokenType == JsonToken.String) { // This is a simple string, from EDDB. return(Volcanism.FromName(reader.Value.ToString())); } else { // Unsupported return(null); } }
/// <summary> Planet or Moon definition </summary> public Body(string bodyName, long?bodyId, List <IDictionary <string, object> > parents, decimal?distanceLs, bool?tidallylocked, TerraformState terraformstate, PlanetClass planetClass, AtmosphereClass atmosphereClass, List <AtmosphereComposition> atmosphereCompositions, Volcanism volcanism, decimal?earthmass, decimal?radiusKm, decimal gravity, decimal?temperatureKelvin, decimal?pressureAtm, bool?landable, List <MaterialPresence> materials, List <SolidComposition> solidCompositions, decimal?semimajoraxisLs, decimal?eccentricity, decimal?orbitalinclinationDegrees, decimal?periapsisDegrees, decimal?orbitalPeriodDays, decimal?rotationPeriodDays, decimal?axialtiltDegrees, List <Ring> rings, ReserveLevel reserveLevel, bool?alreadydiscovered, bool?alreadymapped, string systemName = null, long?systemAddress = null) { this.bodyname = bodyName; this.bodyType = (bool)parents?.Exists(p => p.ContainsKey("Planet")) ? BodyType.FromEDName("Moon") : BodyType.FromEDName("Planet"); this.rings = rings; this.temperature = temperature; this.bodyId = bodyId; // Planet or Moon specific items this.planetClass = planetClass; this.earthmass = earthmass; this.radius = radiusKm; this.gravity = gravity; this.temperature = temperatureKelvin; this.pressure = pressureAtm; this.tidallylocked = tidallylocked; this.landable = landable; this.atmosphereclass = atmosphereClass; this.atmospherecompositions = atmosphereCompositions; this.solidcompositions = solidCompositions; this.volcanism = volcanism; this.reserveLevel = reserveLevel; this.materials = materials; this.terraformState = terraformstate; // Orbital characteristics this.distance = distanceLs; this.parents = parents; this.orbitalperiod = orbitalPeriodDays; this.rotationalperiod = rotationPeriodDays; this.semimajoraxis = semimajoraxisLs; this.eccentricity = eccentricity; this.inclination = orbitalinclinationDegrees; this.periapsis = periapsisDegrees; this.tilt = axialtiltDegrees; // System details this.systemname = systemName; // This is needed to derive the "shortname" property this.systemAddress = systemAddress; // Scan details this.alreadydiscovered = alreadydiscovered; this.alreadymapped = alreadymapped; // Other calculations this.density = GetDensity(); }