internal static List <KeyValuePair <double, Color> > Parse(ConfigNode node, List <KeyValuePair <double, Color> > defaultValue) { for (int i = 0; i < node?.values?.Count; i++) { ConfigNode.Value val = node.values[i]; defaultValue = defaultValue ?? new List <KeyValuePair <double, Color> >(); if (double.TryParse(val.name, out double alt) && TryParse.Color(val.value, out Color color)) { defaultValue.Add(new KeyValuePair <double, Color>(alt, color)); } else { defaultValue = null; break; } defaultValue = defaultValue.OrderBy(v => v.Key).ToList(); } return(defaultValue); }
internal static void LoadSettings(ConfigNode node) { bool.TryParse(node.GetValue("heightMap"), out exportHeightMap); bool.TryParse(node.GetValue("satelliteHeight"), out exportSatelliteHeight); bool.TryParse(node.GetValue("normalMap"), out exportNormalMap); bool.TryParse(node.GetValue("slopeMap"), out exportSlopeMap); bool.TryParse(node.GetValue("satelliteSlope"), out exportSatelliteSlope); if (!bool.TryParse(node.GetValue("colorMap"), out exportColorMap)) { exportColorMap = true; } bool.TryParse(node.GetValue("satelliteMap"), out exportSatelliteMap); bool.TryParse(node.GetValue("oceanMap"), out exportOceanMap); bool.TryParse(node.GetValue("biomeMap"), out exportBiomeMap); bool.TryParse(node.GetValue("satelliteBiome"), out exportSatelliteBiome); //------------------ //--adding in a check to see whether maps exist. 2019-0830 STH bool.TryParse(node.GetValue("overwriteHeightMap"), out overwriteHeightMap); bool.TryParse(node.GetValue("overwriteNormalMap"), out overwriteNormalMap); bool.TryParse(node.GetValue("overwriteSlopeMap"), out overwriteSlopeMap); bool.TryParse(node.GetValue("overwriteColorMap"), out overwriteColorMap); bool.TryParse(node.GetValue("overwriteOceanMap"), out overwriteOceanMap); bool.TryParse(node.GetValue("overwriteBiomeMap"), out overwriteBiomeMap); bool.TryParse(node.GetValue("overwriteSatelliteHeight"), out overwriteSatelliteHeight); bool.TryParse(node.GetValue("overwriteSatelliteSlope"), out overwriteSatelliteSlope); bool.TryParse(node.GetValue("overwriteSatelliteMap"), out overwriteSatelliteMap); bool.TryParse(node.GetValue("overwriteSatelliteBiome"), out overwriteSatelliteBiome); //------------------ if (!exportAny && !exportBiomeMap) { return; } string bodyName = node.GetValue("body"); body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == bodyName) ?? FlightGlobals.GetHomeBody(); if (!int.TryParse(node.GetValue("width"), out width)) { width = 2048; } if (!int.TryParse(node.GetValue("tile"), out tile)) { tile = 1024; } TryParse.Path(node.GetValue("exportFolder"), out exportFolder); bool.TryParse(node.GetValue("leaflet"), out leaflet); bool.TryParse(node.GetValue("flipV"), out flipV); bool.TryParse(node.GetValue("flipH"), out flipH); bool.TryParse(node.GetValue("alpha"), out alpha); if (!bool.TryParse(node.GetValue("oceanFloor"), out oceanFloor)) { oceanFloor = true; } if (!TryParse.Color(node.GetValue("oceanColor"), out oceanColor)) { oceanColor = body?.pqsController?.mapOceanColor ?? new Color(0.1f, 0.1f, 0.2f, 1f); } if (!double.TryParse(node.GetValue("LAToffset"), out LAToffset)) { LAToffset = 0; } if (!double.TryParse(node.GetValue("LONoffset"), out LONoffset)) { LONoffset = 0; } if (node.HasNode("AltitudeColor")) { altitudeColor = Utility.Parse(node.GetNode("AltitudeColor"), altitudeColor); } if (altitudeColor == null) { altitudeColor = new List <KeyValuePair <double, Color> > { new KeyValuePair <double, Color>(0, Color.black), new KeyValuePair <double, Color>(1, Color.white) }; } if (!float.TryParse(node.GetValue("normalStrength"), out normalStrength)) { normalStrength = 1; } if (!TryParse.Color(node.GetValue("slopeMin"), out slopeMin)) { slopeMin = new Color(0.2f, 0.3f, 0.4f); } if (!TryParse.Color(node.GetValue("slopeMax"), out slopeMax)) { slopeMax = new Color(0.9f, 0.6f, 0.5f); } printTile = new List <int>(); foreach (string s in node.GetValues("printTile")) { int i = 0; if (int.TryParse(s, out i)) { printTile.Add(i); } } int temp = 0; if (int.TryParse(node.GetValue("printFrom"), out temp)) { printFrom = temp; } else { printFrom = null; } if (int.TryParse(node.GetValue("printTo"), out temp)) { printTo = temp; } else { printTo = null; } if (!body.ocean) { oceanFloor = true; exportOceanMap = false; } if (body.pqsController == null) { exportAny = false; } if (body.BiomeMap == null) { exportBiomeMap = false; } }
internal static void LoadSettings(ConfigNode node) { settings = null; if (!node.HasValue("texture")) { return; } string bodyName = node.GetValue("body"); body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == bodyName) ?? FlightGlobals.GetHomeBody(); source = node.GetValue("texture"); if (!int.TryParse(node.GetValue("size"), out size)) { size = 2048; } TryParse.Path(node.GetValue("exportFolder"), out exportFolder); name = node.GetValue("name"); if (!bool.TryParse(node.GetValue("oceanFloor"), out oceanFloor)) { oceanFloor = true; } if (!double.TryParse(node.GetValue("LAToffset"), out LAToffset)) { LAToffset = 0; } if (!double.TryParse(node.GetValue("LONoffset"), out LONoffset)) { LONoffset = 0; } if (!double.TryParse(node.GetValue("lightLAT"), out lightLAT)) { lightLAT = 0; } if (!double.TryParse(node.GetValue("lightLON"), out lightLON)) { lightLON = 0; } if (!TryParse.Color(node.GetValue("backgroundColor"), out background)) { background = Color.clear; } bool.TryParse(node.GetValue("unlit"), out unlit); TryParse.Color(node.GetValue("_Color"), out _Color); TryParse.Color(node.GetValue("_SpecColor"), out _SpecColor); if (float.TryParse(node.GetValue("_Shininess"), out float shininess)) { _Shininess = shininess; } else { _Shininess = null; } if (!body.ocean) { oceanFloor = true; } string[] sources = { "heightMap", "satelliteHeight", "normalMap", "slopeMap", "satelliteSlope", "colorMap", "satelliteMap", "oceanMap", "biomeMap", "satelliteBiome" }; for (int i = 0; i < sources.Length; i++) { if (source == sources[i]) { // Clean node node.RemoveValues("heightMap"); node.RemoveValues("satelliteHeight"); node.RemoveValues("normalMap"); node.RemoveValues("slopeMap"); node.RemoveValues("satelliteSlope"); node.RemoveValues("colorMap"); node.RemoveValues("satelliteMap"); node.RemoveValues("oceanMap"); node.RemoveValues("biomeMap"); node.RemoveValues("satelliteBiome"); node.RemoveValues("leaflet"); node.RemoveValues("flipV"); node.RemoveValues("flipH"); node.RemoveValues("LAToffset"); node.RemoveValues("LONoffset"); node.RemoveValues("printTile"); node.RemoveValues("printFrom"); node.RemoveValues("printTo"); if (double.TryParse(node.GetValue("width"), out double width)) { node.RemoveValues("tile"); node.AddValue("tile", width); } else { node.RemoveValues("width"); node.RemoveValues("tile"); node.AddValue("width", size); node.AddValue("tile", size); } // Failsafe node.AddValue("colorMap", "false"); // Checks if (body.pqsController == null) { return; } if (source == "oceanMap" && !body.ocean) { return; } if (source == "satelliteBiome" && body.BiomeMap == null) { return; } if (source == "colorMap") { node.RemoveValues("colorMap"); } else { node.AddValue(source, "true"); } node.AddValue("LONoffset", "-90"); node.AddValue("flipH", "true"); settings = node; break; } } }