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); }
void Start() { UrlDir.UrlConfig[] nodes = GameDatabase.Instance?.GetConfigs("SigmaCartographer"); foreach (var node in nodes) { foreach (var planetInfo in node.config.GetNodes("Maps")) { bool.TryParse(planetInfo.GetValue("heightMap"), out exportHeightMap); bool.TryParse(planetInfo.GetValue("normalMap"), out exportNormalMap); bool.TryParse(planetInfo.GetValue("slopeMap"), out exportSlopeMap); if (!bool.TryParse(planetInfo.GetValue("colorMap"), out exportColorMap)) { exportColorMap = true; } bool.TryParse(planetInfo.GetValue("oceanMap"), out exportOceanMap); bool.TryParse(planetInfo.GetValue("satelliteMap"), out exportSatelliteMap); bool.TryParse(planetInfo.GetValue("biomeMap"), out exportBiomeMap); if (!exportAny && !exportBiomeMap) { continue; } string bodyName = planetInfo.GetValue("body"); body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == bodyName) ?? FlightGlobals.GetHomeBody(); if (!int.TryParse(planetInfo.GetValue("width"), out width)) { width = 2048; } if (!int.TryParse(planetInfo.GetValue("tile"), out tile)) { tile = 1024; } TryParse.Path(planetInfo.GetValue("exportFolder"), out exportFolder); bool.TryParse(planetInfo.GetValue("leaflet"), out leaflet); bool.TryParse(planetInfo.GetValue("flipV"), out flipV); bool.TryParse(planetInfo.GetValue("flipH"), out flipH); if (!bool.TryParse(planetInfo.GetValue("oceanFloor"), out oceanFloor)) { oceanFloor = true; } if (!TryParse.Color(planetInfo.GetValue("oceanColor"), out oceanColor)) { oceanColor = body?.pqsController?.mapOceanColor ?? new Color(0.1f, 0.1f, 0.2f, 1f); } if (!double.TryParse(planetInfo.GetValue("LAToffset"), out LAToffset)) { LAToffset = 0; } if (!double.TryParse(planetInfo.GetValue("LONoffset"), out LONoffset)) { LONoffset = 0; } if (planetInfo.HasNode("AltitudeColor")) { altitudeColor = Parse(planetInfo.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(planetInfo.GetValue("normalStrength"), out normalStrength)) { normalStrength = 1; } if (!TryParse.Color(planetInfo.GetValue("slopeMin"), out slopeMin)) { slopeMin = new Color(0.2f, 0.3f, 0.4f); } if (!TryParse.Color(planetInfo.GetValue("slopeMax"), out slopeMax)) { slopeMax = new Color(0.9f, 0.6f, 0.5f); } printTile = new List <int>(); foreach (string s in planetInfo.GetValues("printTile")) { int i = 0; if (int.TryParse(s, out i)) { printTile.Add(i); } } int temp = 0; if (int.TryParse(planetInfo.GetValue("printFrom"), out temp)) { printFrom = temp; } else { printFrom = null; } if (int.TryParse(planetInfo.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; } if (!exportAny && !exportBiomeMap) { continue; } GeneratePQSMaps(); } } }