/// <summary> /// Reads a property setting from a ConfigNode and writes the content to the targets field with the same name /// </summary> /// <param name="target"></param> /// <param name="property"></param> /// <param name="cfgNode"></param> internal static void ReadCFGNode(object target, PropertyInfo property, ConfigNode cfgNode) { if (!cfgNode.HasValue(property.Name)) { return; } if (!string.IsNullOrEmpty(cfgNode.GetValue(property.Name))) { switch (property.PropertyType.ToString()) { case "System.String": property.SetValue(target, cfgNode.GetValue(property.Name), null); break; case "System.Int32": property.SetValue(target, int.Parse(cfgNode.GetValue(property.Name)), null); break; case "System.Single": property.SetValue(target, float.Parse(cfgNode.GetValue(property.Name)), null); break; case "System.Double": property.SetValue(target, double.Parse(cfgNode.GetValue(property.Name)), null); break; case "System.Boolean": bool result; bool.TryParse(cfgNode.GetValue(property.Name), out result); property.SetValue(target, result, null); break; case "UnityEngine.Vector3": property.SetValue(target, ConfigNode.ParseVector3(cfgNode.GetValue(property.Name)), null); break; case "UnityEngine.Vector3d": property.SetValue(target, ConfigNode.ParseVector3D(cfgNode.GetValue(property.Name)), null); break; case "CelestialBody": property.SetValue(target, ConfigUtil.GetCelestialBody(cfgNode.GetValue(property.Name)), null); break; case "UnityEngine.Color": property.SetValue(target, ConfigNode.ParseColor(cfgNode.GetValue(property.Name)), null); break; case "KerbalKonstructs.Core.SiteType": SiteType value = SiteType.Any; try { value = (SiteType)Enum.Parse(typeof(SiteType), cfgNode.GetValue(property.Name)); } catch { value = SiteType.Any; } property.SetValue(target, value, null); break; case "KerbalKonstructs.Core.LaunchSiteCategory": LaunchSiteCategory category = LaunchSiteCategory.Other; try { category = (LaunchSiteCategory)Enum.Parse(typeof(LaunchSiteCategory), cfgNode.GetValue(property.Name)); } catch { category = LaunchSiteCategory.Other; } property.SetValue(target, category, null); break; } } }
/// <summary> /// Writes out all the data of the instance To a ConfigNode (+ the Facilities) /// </summary> /// <param name="instance"></param> /// <param name="cfgNode"></param> internal static void WriteInstanceConfig(StaticInstance instance, ConfigNode cfgNode) { foreach (var instanceSetting in ConfigUtil.instanceFields) { if (instanceSetting.Value.GetValue(instance) == null) { continue; } if (instanceSetting.Key == "FacilityType") { continue; } // Remove legacy GrassColor values //if ((instanceSetting.Key == "GrasColor") || (instanceSetting.Key == "GrasTexture")) //{ // continue; //} // No Longer save Legacy Values if (instanceSetting.Key == "RadialPosition" || instanceSetting.Key == "RadiusOffset" || instanceSetting.Key == "RotationAngle" || instanceSetting.Key == "RefLatitude" || instanceSetting.Key == "RefLongitude" || instanceSetting.Key == "IsRelativeToTerrain") { continue; } ConfigUtil.Write2CfgNode(instance, instanceSetting.Value, cfgNode); } if (instance.hasFacilities) { for (int i = 0; i < instance.myFacilities.Count; i++) { ConfigNode facNode = cfgNode.AddNode("Facility"); instance.myFacilities[i].WriteConfig(facNode); } } if (instance.hasLauchSites) { ConfigNode lsNode = cfgNode.AddNode("LaunchSite"); LaunchSiteParser.WriteConfig(instance.launchSite, lsNode); } // save unsaved grassSettings before we write everything to the instance node if (instance.isSpawned) { GrassColor2[] grassArray = instance.mesh.GetComponents <GrassColor2>(); if (grassArray.Length > 0) { instance.grassColor2Configs.Clear(); foreach (GrassColor2 grassColor in grassArray) { instance.grassColor2Configs.Add(grassColor.GiveConfig()); } } } foreach (ConfigNode grassNode in instance.grassColor2Configs) { cfgNode.AddNode("GrassColor2", grassNode); } }
/// <summary> /// prefills LaunchSiteManager with the runway and the KSC /// </summary> private static void AddKSC() { StaticInstance rwInstance = new StaticInstance(); rwInstance.gameObject = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableFacility>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject; rwInstance.RefLatitude = getKSCLat; rwInstance.RefLongitude = getKSCLon; rwInstance.CelestialBody = ConfigUtil.GetCelestialBody("HomeWorld"); rwInstance.RadialPosition = rwInstance.radialPosition; rwInstance.hasLauchSites = true; rwInstance.launchSite = runway; StaticInstance padInstance = new StaticInstance(); padInstance.gameObject = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableFacility>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject; padInstance.RefLatitude = getKSCLat; padInstance.RefLongitude = getKSCLon; padInstance.CelestialBody = ConfigUtil.GetCelestialBody("HomeWorld"); padInstance.RadialPosition = rwInstance.radialPosition; padInstance.hasLauchSites = true; padInstance.launchSite = launchpad; runway.staticInstance = rwInstance; runway.isSquad = true; runway.LaunchSiteName = "Runway"; runway.LaunchSiteAuthor = "Squad"; runway.LaunchSiteType = SiteType.SPH; runway.sitecategory = LaunchSiteCategory.Runway; runway.logo = UIMain.MakeSprite("KerbalKonstructs/Assets/KSCRunway"); runway.LaunchSiteDescription = "The KSC runway is a concrete runway measuring about 2.5km long and 70m wide, on a magnetic heading of 90/270. It is not uncommon to see burning chunks of metal sliding across the surface."; runway.body = ConfigUtil.GetCelestialBody("HomeWorld"); runway.refLat = (float)rwInstance.RefLatitude; runway.refLon = (float)rwInstance.RefLongitude; runway.refAlt = 69f; runway.LaunchSiteLength = 2500f; runway.LaunchSiteWidth = 0f; runway.InitialCameraRotation = -60f; runway.staticInstance.mesh = rwInstance.gameObject; runway.SetOpen(); launchpad.staticInstance = padInstance; launchpad.isSquad = true; launchpad.LaunchSiteName = "LaunchPad"; launchpad.LaunchSiteAuthor = "Squad"; launchpad.LaunchSiteType = SiteType.VAB; launchpad.sitecategory = LaunchSiteCategory.RocketPad; launchpad.logo = UIMain.MakeSprite("KerbalKonstructs/Assets/KSCLaunchpad"); launchpad.LaunchSiteDescription = "The KSC launchpad is a platform used to fire screaming Kerbals into the kosmos. There was a tower here at one point but for some reason nobody seems to know where it went..."; launchpad.body = ConfigUtil.GetCelestialBody("HomeWorld"); launchpad.refLat = getKSCLat; launchpad.refLon = getKSCLon; launchpad.refAlt = 72; launchpad.LaunchSiteLength = 0f; launchpad.LaunchSiteWidth = 0f; launchpad.InitialCameraRotation = -60f; launchpad.staticInstance.mesh = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableFacility>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject; launchpad.SetOpen(); AddLaunchSite(runway); AddLaunchSite(launchpad); }
/// <summary> /// Set the SpaceCenterCam to the location os the current LaunchSite /// </summary> /// <param name="currentSite"></param> internal static void SetSpaceCenterCam(KKLaunchSite currentSite) { if (KerbalKonstructs.focusLastLaunchSite && (currentSite.body.name == ConfigUtil.GetCelestialBody("HomeWorld").name)) { foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { Log.Normal("Restting to: " + currentSite.LaunchSiteName); scCam.transform.parent = currentSite.lsGameObject.transform; scCam.transform.position = currentSite.lsGameObject.transform.position; scCam.initialPositionTransformName = currentSite.lsGameObject.transform.name; scCam.pqsName = currentSite.body.name; scCam.rotationInitial = currentSite.InitialCameraRotation; scCam.ResetCamera(); KerbalKonstructs.scCamWasAltered = true; } } else { foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { Log.Normal("Restting to KSC"); Upgradeables.UpgradeableObject kscRnD = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableObject>().Where(x => x.name == "ResearchAndDevelopment").First(); scCam.transform.parent = kscRnD.gameObject.transform; scCam.transform.position = kscRnD.gameObject.transform.transform.position; scCam.initialPositionTransformName = kscRnD.gameObject.transform.name; scCam.pqsName = ConfigUtil.GetCelestialBody("HomeWorld").name; scCam.rotationInitial = -60; scCam.ResetCamera(); KerbalKonstructs.scCamWasAltered = false; } } if (currentSite.LaunchSiteName == "Runway" || currentSite.LaunchSiteName == "LaunchPad" || currentSite.body.name != ConfigUtil.GetCelestialBody("HomeWorld").name) { foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2))) { cam.altitudeInitial = 45f; cam.ResetCamera(); } } else { PQSCity sitePQS = currentSite.staticInstance.groupCenter.pqsCity; foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2))) { double nomHeight = currentSite.body.pqsController.GetSurfaceHeight((Vector3d)sitePQS.repositionRadial.normalized) - currentSite.body.Radius; if (sitePQS.repositionToSphereSurface) { nomHeight += sitePQS.repositionRadiusOffset; } cam.altitudeInitial = 0f - (float)nomHeight; cam.ResetCamera(); Log.Normal("fixed the Space Center camera."); } } SetNextMorningPoint(currentSite); }