/// <summary>Retrieves the dust colors which are stored in the DustColors-file and are auto-loaded by KSP.</summary> static void ReadDustColor() { bool error = false; // DustColors.cfg DustColors = new Dictionary <string, Dictionary <string, Color> >(); ConfigNode configFile = ConfigNode.Load(dustColorsFileName); ConfigNode configNode = configFile.GetNode("DustColorDefinitions"); if (Equals(configFile, null) || !configFile.HasNode("DustColorDefinitions")) // DustColorDefinitions node doesn't exist. { KFLog.Warning("DustColors.cfg is missing or damaged!"); error = true; } if (!error && (Equals(configNode, null) || Equals(configNode.CountNodes, 0))) { KFLog.Warning("Dust color definitions not found or damaged!"); error = true; } if (error) { dustConfigsPresent = false; return; } dustConfigsPresent = true; // Implied: "error" is false, which means the above two checks also returned false, // which means the file is there and properly formatted. foreach (ConfigNode celestialNode in configNode.GetNodes()) // For each celestial body do this: { var biomes = new Dictionary <string, Color>(); foreach (ConfigNode biomeNode in celestialNode.GetNodes()) // For each biome of that celestial body do this: { float r = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[0], out r); float g = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[1], out g); float b = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[2], out b); float a = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[3], out a); biomes.Add(biomeNode.name, new Color(r, g, b, a)); } DustColors.Add(celestialNode.name, biomes); if (Equals(biomes.Count, 0)) { KFLog.Error(string.Format("No biome colors found for {0}!", celestialNode.name)); } else { KFLog.Log(string.Format("Found {0} biome color definitions for {1}.", biomes.Count, celestialNode.name)); } } }
public override void OnStart(PartModule.StartState state) { try { Anim[animationName].layer = 2; SetInitState(); base.OnStart(state); if (Equals(speedForward, 0f)) { speedForward = 1f; } if (Equals(speedBackward, 0f)) { speedBackward = 1f; } } catch (Exception ex) { KFLog.Error(string.Format("Error in OnStart. \"{0}\"", ex.Message)); } }
/// <summary>Shortcut to rounding a value to the nearest number.</summary> /// <param name="input">Value to be rounded.</param> /// <param name="roundto">Rounds the value to the nearest "roundto". If value is between 0 and 1 (non-inclusive) then we will round to that decimal, otherwise we round to nearest while interval of "roundto".</param> /// <returns>Nearest "roundto" in relation to "value"</returns> public static float RoundToNearestValue(this float input, float roundto) { float output; if (roundto < 1f && roundto > 0f) { roundto *= 10f; output = (float)((Math.Round(((input * 10f) / roundto), MidpointRounding.AwayFromZero) * roundto) / 10f); } else if (roundto >= 1f) { output = (float)(Math.Round(input / roundto, MidpointRounding.AwayFromZero) * roundto); } else { output = (float)(Math.Round(input, MidpointRounding.AwayFromZero)); KFLog.Error("Invalid float entered for rounding value. Defaulting to nearest whole integer."); } return(output); }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); if (HighLogic.LoadedSceneIsFlight && !Equals(vessel.vesselType, VesselType.Debris)) { GameEvents.onGamePause.Add(OnPause); GameEvents.onGameUnpause.Add(OnUnPause); _moduleWheel = part.GetComponentInChildren <KFModuleWheel>(); if (!Equals(_moduleWheel, null)) { tweakScaleCorrector = _moduleWheel.tweakScaleCorrector; } KFLog.Warning(string.Format("TS Corrector: {0}", tweakScaleCorrector)); colliderList = colliderNames.SplitString(); for (int i = 0; i < colliderList.Count(); i++) { colliders.Add(transform.SearchStartsWith(colliderList[i]).GetComponent <WheelCollider>()); objectCount++; } susTrav = transform.SearchStartsWith(susTravName); initialPosition = susTrav.localPosition; susTravIndex = susTravAxis.SetAxisIndex(); MoveSuspension(susTravIndex, -fLastFrameTraverse, susTrav); if (objectCount > 0) { StartCoroutine("WaitAndStart"); } else { KFLog.Error("KFSuspension not configured correctly"); } } }