public static Rect ReadRect(this ConfigNode node, string name, Rect defaultValue = default(Rect)) { if (node.HasValue(name)) { try { Vector4 vector = KSPUtil.ParseVector4(node.GetValue(name)); return(new Rect(vector.x, vector.y, vector.z, vector.w)); } catch (Exception ex) { Log.Debug("[ScienceAlert]:ConfigUtil.ReadRect: exception while reading value '{0}': {1}", name, ex); } return(defaultValue); } return(defaultValue); }
/// <summary> /// Returns true if the ConfigNode has the specified value and stores it in the ref value if it is parsable. Value is left unchanged if not. /// </summary> /// <param name="name">Name of the value to searched for</param> /// <param name="value">Value to assign</param> public static bool TryGetValue(this ConfigNode node, string name, ref Color value) { Color result; if (node.HasValue(name)) { try { Vector4 col = KSPUtil.ParseVector4(node.GetValue(name)); result = new Color(col.x, col.y, col.z, col.w); value = result; return(true); } catch (Exception e) { MonoBehaviour.print("Exception: Error parsing as color4: original text: " + node.GetValue("name") + " --- exception " + e.Message); } } return(false); }
public static Rect ReadRect(this ConfigNode node, string name, Rect defaultValue = new Rect()) { if (!node.HasValue(name)) { Log.Error("ConfigUtil.ReadRect: value '{0}' does not exist", name); } else { try { var parsed = KSPUtil.ParseVector4(node.GetValue(name)); return(new Rect(parsed.x, parsed.y, parsed.z, parsed.w)); } catch (Exception e) { Log.Error("ConfigUtil.ReadRect: exception while reading value '{0}': {1}", name, e); } } return(defaultValue); }
void Start() { if (!CompatibilityChecker.IsCompatible()) { return; } //The lights are instantiated on each scene startup, unlike planets which instantiate at the beginning of the game //so a more specific check has to be performed if (HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.FLIGHT) { ConfigNode RSSSettings = null; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("REALSOLARSYSTEMSETTINGS")) { RSSSettings = node; } if (RSSSettings == null) { print("*RSS* REALSOLARSYSTEMSETTINGS node not found, could not load light settings!"); return; } GameObject sunLight = GameObject.Find("SunLight"); GameObject scaledSunLight = GameObject.Find("Scaledspace SunLight"); if (sunLight != null) { print("*RSS* LightShifter: Found sunlight and scaled sunlight, shifting..."); if (RSSSettings.HasValue("sunlightColor")) { try { Vector4 col = KSPUtil.ParseVector4(RSSSettings.GetValue("sunlightColor")); Color c = new Color(col.x, col.y, col.z, col.w); sunLight.light.color = c; } catch (Exception e) { print("*RSS* Error parsing as color4: original text: " + RSSSettings.GetValue("sunlightColor") + " --- exception " + e.Message); } } if (RSSSettings.HasValue("sunlightIntensity")) { try { float f = float.Parse(RSSSettings.GetValue("sunlightIntensity")); sunLight.light.intensity = f; } catch (Exception e) { print("*RSS* Error parsing as float: original text: " + RSSSettings.GetValue("sunlightIntensity") + " --- exception " + e.Message); } } if (RSSSettings.HasValue("sunlightShadowStrength")) { try { float f = float.Parse(RSSSettings.GetValue("sunlightShadowStrength")); sunLight.light.shadowStrength = f; } catch (Exception e) { print("*RSS* Error parsing as float: original text: " + RSSSettings.GetValue("sunlightShadowStrength") + " --- exception " + e.Message); } } if (RSSSettings.HasValue("scaledSunlightColor")) { try { Vector4 col = KSPUtil.ParseVector4(RSSSettings.GetValue("scaledSunlightColor")); Color c = new Color(col.x, col.y, col.z, col.w); scaledSunLight.light.color = c; } catch (Exception e) { print("*RSS* Error parsing as color4: original text: " + RSSSettings.GetValue("scaledSunlightColor") + " --- exception " + e.Message); } } if (RSSSettings.HasValue("scaledSunlightIntensity")) { try { float f = float.Parse(RSSSettings.GetValue("scaledSunlightIntensity")); scaledSunLight.light.intensity = f; } catch (Exception e) { print("*RSS* Error parsing as float: original text: " + RSSSettings.GetValue("scaledSunlightIntensity") + " --- exception " + e.Message); } } } else { print("*RSS* LightShifter: Couldn't find either sunlight or scaled sunlight"); } if (HighLogic.LoadedScene == GameScenes.FLIGHT) { GameObject IVASun = GameObject.Find("IVASun"); if (IVASun != null) { print("LightShifter: Found IVA sun, shifting..."); if (RSSSettings.HasValue("IVASunColor")) { try { Vector4 col = KSPUtil.ParseVector4(RSSSettings.GetValue("IVASunColor")); Color c = new Color(col.x, col.y, col.z, col.w); IVASun.light.color = c; } catch (Exception e) { print("*RSS* Error parsing as color4: original text: " + RSSSettings.GetValue("IVASunColor") + " --- exception " + e.Message); } } if (RSSSettings.HasValue("IVASunIntensity")) { try { float f = float.Parse(RSSSettings.GetValue("IVASunIntensity")); IVASun.light.intensity = f; } catch (Exception e) { print("*RSS* Error parsing as float: original text: " + RSSSettings.GetValue("IVASunIntensity") + " --- exception " + e.Message); } } } else { print("*RSS* LightShifter: No IVA sun found."); } } LensFlare sunLightFlare = sunLight.gameObject.GetComponent <LensFlare>(); if (sunLightFlare != null) { print("*RSS* LightShifter: Shifting LensFlare"); if (RSSSettings.HasValue("sunlightLensFlareColor")) { try { Vector4 col = KSPUtil.ParseVector4(RSSSettings.GetValue("sunlightLensFlareColor")); Color c = new Color(col.x, col.y, col.z, col.w); sunLightFlare.color = c; } catch (Exception e) { print("*RSS* Error parsing as color4: original text: " + RSSSettings.GetValue("sunlightLensFlareColor") + " --- exception " + e.Message); } } } DynamicAmbientLight ambientLight = FindObjectOfType(typeof(DynamicAmbientLight)) as DynamicAmbientLight; //Funny story behind locating this one. When I was typing "Light l" in the foreach function earlier, one of the suggestions //from the autocomplete was DynamicAmbientLight. Saved me a lot of trial and error looking for it to be sure. if (ambientLight != null) { print("*RSS* LightShifter: Found DynamicAmbientLight. Shifting..."); if (RSSSettings.HasValue("ambientLightColor")) { try { Vector4 col = KSPUtil.ParseVector4(RSSSettings.GetValue("ambientLightColor")); Color c = new Color(col.x, col.y, col.z, col.w); ambientLight.vacuumAmbientColor = c; } catch (Exception e) { print("*RSS* Error parsing as color4: original text: " + RSSSettings.GetValue("ambientLightColor") + " --- exception " + e.Message); } } } else { print("*RSS* LightShifter: Couldn't find DynamicAmbientLight"); } Sun sun = Sun.Instance; if (sun != null) { if (RSSSettings.HasValue("dumpBrightnessCurve")) { print("**DUMP** Sun AU: " + sun.AU); for (int i = 0; i < sun.brightnessCurve.keys.Length; i++) { Keyframe k = sun.brightnessCurve.keys[i]; print("Key " + k.time + ", " + k.value + ", " + k.inTangent + "," + k.outTangent + " : mode " + k.tangentMode); } } if (RSSSettings.HasNode("sunBrightnessCurve")) { AnimationCurve newCurve = Utils.LoadAnimationCurve(RSSSettings.GetNode("sunBrightnessCurve")); } RSSSettings.TryGetValue("sunAU", ref sun.AU); } } }
public void Start() { ConfigNode RSSSettings = null; bool UseLegacyAtmosphere; float ftmp; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("REALSOLARSYSTEM")) { RSSSettings = node; } if (RSSSettings != null) { if (RSSSettings.HasNode(body.GetName())) { ConfigNode node = RSSSettings.GetNode(body.GetName()); print("*RSS* checking useLegacyAtmosphere for " + body.GetName()); if (node.HasValue("useLegacyAtmosphere")) { bool.TryParse(node.GetValue("useLegacyAtmosphere"), out UseLegacyAtmosphere); print("*RSSWatchDog* " + body.GetName() + ".useLegacyAtmosphere = " + body.useLegacyAtmosphere.ToString()); if (UseLegacyAtmosphere != body.useLegacyAtmosphere) { print("*RSSWatchDog* resetting useLegacyAtmosphere to " + UseLegacyAtmosphere.ToString()); body.useLegacyAtmosphere = UseLegacyAtmosphere; } } /*if (node.HasNode("AtmosphereFromGround")) * { * ConfigNode agnode = node.GetNode("AtmosphereFromGround"); * foreach (AtmosphereFromGround ag in Resources.FindObjectsOfTypeAll(typeof(AtmosphereFromGround))) * { * if (ag != null && ag.planet != null) * { * // generalized version of Starwaster's code. Thanks Starwaster! * if (ag.planet.name.Equals(node.name)) * { * if (agnode.HasValue("outerRadius")) * { * if (float.TryParse(agnode.GetValue("outerRadius"), out ftmp)) * ag.outerRadius = ftmp * ScaledSpace.InverseScaleFactor; * } * ag.outerRadius2 = ag.outerRadius * ag.outerRadius; * ag.innerRadius2 = ag.innerRadius * ag.innerRadius; * ag.scale = 1f / (ag.outerRadius - ag.innerRadius); * ag.scaleDepth = -0.25f; * ag.scaleOverScaleDepth = ag.scale / ag.scaleDepth; * } * } * } * }*/ if (node.HasNode("AtmosphereFromGround")) { ConfigNode agnode = node.GetNode("AtmosphereFromGround"); foreach (AtmosphereFromGround ag in Resources.FindObjectsOfTypeAll(typeof(AtmosphereFromGround))) { if (ag != null && ag.planet != null) { // generalized version of Starwaster's code. Thanks Starwaster! if (ag.planet.name.Equals(node.name)) { if (node.HasNode("AtmosphereFromGround")) { ConfigNode modNode = node.GetNode("AtmosphereFromGround"); if (modNode.HasValue("outerRadius")) { if (float.TryParse(modNode.GetValue("outerRadius"), out ftmp)) { ag.outerRadius = ftmp * ScaledSpace.InverseScaleFactor; } } else if (modNode.HasValue("outerRadiusAtmo")) { ag.outerRadius = ((float)body.Radius + body.maxAtmosphereAltitude) * ScaledSpace.InverseScaleFactor; } else if (modNode.HasValue("outerRadiusMult")) { if (float.TryParse(modNode.GetValue("outerRadiusMult"), out ftmp)) { ag.outerRadius = ftmp * (float)body.Radius * ScaledSpace.InverseScaleFactor; } } if (modNode.HasValue("innerRadius")) { if (float.TryParse(modNode.GetValue("innerRadius"), out ftmp)) { ag.innerRadius = ftmp * ScaledSpace.InverseScaleFactor; } } else if (modNode.HasValue("innerRadiusMult")) { if (float.TryParse(modNode.GetValue("innerRadiusMult"), out ftmp)) { ag.innerRadius = ftmp * ag.outerRadius; } } modNode.TryGetValue("doScale", ref ag.doScale); if (modNode.HasValue("transformScale")) { if (float.TryParse(modNode.GetValue("transformScale"), out ftmp) && ag.transform != null) { ag.transform.localScale = new Vector3(ftmp, ftmp, ftmp); } } else if (modNode.HasValue("transformAtmo")) { ag.transform.localScale = Vector3.one * ((float)(body.Radius + body.maxAtmosphereAltitude) / (float)body.Radius); } if (modNode.HasValue("invWaveLength")) { Vector4 col = KSPUtil.ParseVector4(modNode.GetValue("invWaveLength")); ag.invWaveLength = new Color(col.x, col.y, col.z, col.w); } if (modNode.HasValue("waveLength")) { Vector4 col = KSPUtil.ParseVector4(modNode.GetValue("waveLength")); ag.waveLength = new Color(col.x, col.y, col.z, col.w); } } else { // the defaults ag.outerRadius = (float)body.Radius * 1.025f * ScaledSpace.InverseScaleFactor; ag.innerRadius = ag.outerRadius * 0.975f; } ag.outerRadius2 = ag.outerRadius * ag.outerRadius; ag.innerRadius2 = ag.innerRadius * ag.innerRadius; ag.scale = 1f / (ag.outerRadius - ag.innerRadius); ag.scaleDepth = -0.25f; ag.scaleOverScaleDepth = ag.scale / ag.scaleDepth; MethodInfo setMaterial = ag.GetType().GetMethod("SetMaterial", BindingFlags.NonPublic | BindingFlags.Instance); setMaterial.Invoke(ag, new object[] { true }); } } } } } } }