void Start() { foreach (ConfigNode GroupsLoader in GameDatabase.Instance.GetConfigNodes("PQSCity_Groups")) { AddGroups(GroupsLoader.GetNodes("GROUP")); if (GroupsLoader.HasValue("debug") && !debugAllGroups.Value) { debugAllGroups.SetFromString(GroupsLoader.GetValue("debug")); } } SaveGroups(); }
bool GetSetting(string name, bool Default) { bool output = Default; foreach (ConfigNode Settings in GameDatabase.Instance.GetConfigNodes("SASSLoadingScreen")) { if (Settings.HasValue(name)) { NumericParser <bool> userSetting = new NumericParser <bool>(); userSetting.SetFromString(Settings.GetValue(name)); if (userSetting.value == Default) { return(Default); } else { output = !Default; } } } return(output); }
Vector3?GetCenter(ConfigNode node, CelestialBody body) { if (node.HasValue("CentralPQSCity")) { return(body.GetComponentsInChildren <PQSCity>(true).FirstOrDefault(p => p.name == node.GetValue("CentralPQSCity")).repositionRadial); } else if (node.HasValue("CentralPQSCity2")) { return(body.GetComponentsInChildren <PQSCity2>(true).First(p => p.name == node.GetValue("CentralPQSCity2")).PlanetRelativePosition); } else if (node.HasValue("CentralPosition")) { Vector3Parser v = new Vector3Parser(); v.SetFromString(node.GetValue("CentralPosition")); return(v); } else if (node.HasValue("CentralLAT") && node.HasValue("CentralLON")) { NumericParser <double> LAT = new NumericParser <double>(); NumericParser <double> LON = new NumericParser <double>(); LAT.SetFromString(node.GetValue("CentralLAT")); LON.SetFromString(node.GetValue("CentralLON")); return(Utility.LLAtoECEF(LAT, LON, 1, 1)); } else if (node.HasValue("PQSCity")) { return(body.GetComponentsInChildren <PQSCity>(true).FirstOrDefault(p => p.name == node.GetValue("PQSCity")).repositionRadial); } else if (node.HasValue("PQSCity2")) { return(body.GetComponentsInChildren <PQSCity2>(true).First(p => p.name == node.GetValue("PQSCity2")).PlanetRelativePosition); } else { return(null); } }
private void Start() { // FIX BODIES MOVED POST SPAWN // Boolean postSpawnChanges = false; // Replaced 'foreach' with 'for' to improve performance CelestialBody[] postSpawnBodies = PSystemManager.Instance.localBodies.Where(b => b.Has("orbitPatches")).ToArray(); for (Int32 i = 0; i < postSpawnBodies.Length; i++) { CelestialBody cb = postSpawnBodies[i]; // Fix position if the body gets moved PostSpawn ConfigNode patch = cb.Get <ConfigNode>("orbitPatches"); if (patch == null) { continue; } if (patch.GetValue("referenceBody") == null && patch.GetValue("semiMajorAxis") == null) { continue; } if (cb.orbitDriver == null) { continue; } // Get the body PSystemBody body = PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true).FirstOrDefault(b => b.name == cb.transform.name); if (body == null) { Debug.Log("[Kopernicus]: RnDFixer: Could not find PSystemBody => " + cb.transform.name); continue; } // Get the parent PSystemBody oldParent = PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true).FirstOrDefault(b => b.children.Contains(body)); if (oldParent == null) { Debug.Log("[Kopernicus]: RnDFixer: Could not find referenceBody of CelestialBody => " + cb.transform.name); continue; } // Check if PostSpawnOrbit changes referenceBody PSystemBody newParent = oldParent; if (patch.GetValue("referenceBody") != null) { newParent = PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true) .FirstOrDefault(b => b.name == patch.GetValue("referenceBody")); } if (oldParent == null) { Debug.Log("[Kopernicus]: RnDFixer: Could not find PostSpawn referenceBody of CelestialBody => " + cb.transform.name); newParent = oldParent; } NumericParser <Double> newSemiMajorAxis = body.orbitDriver.orbit.semiMajorAxis; if (patch.GetValue("semiMajorAxis") != null) { newSemiMajorAxis.SetFromString(patch.GetValue("semiMajorAxis")); } // Remove the body from oldParent.children oldParent.children.Remove(body); // Find the index of the body in newParent.children if (newParent != null) { Int32 index = newParent.children.FindAll(c => c.orbitDriver.orbit.semiMajorAxis < newSemiMajorAxis.Value).Count; // Add the body to newParent.children if (index > newParent.children.Count) { newParent.children.Add(body); } else { newParent.children.Insert(index, body); } } // Signal that the system has PostSpawn changes postSpawnChanges = true; } // Rebuild Archives if (postSpawnChanges) { AddPlanets(); } // RDVisibility = HIDDEN // RDVisibility = SKIP // // Create a list with body to hide and their parent List <KeyValuePair <PSystemBody, KeyValuePair <PSystemBody, Int32> > > hideList = new List <KeyValuePair <PSystemBody, KeyValuePair <PSystemBody, Int32> > >(); // Create a list with body to skip and their parent List <KeyValuePair <PSystemBody, PSystemBody> > skipList = new List <KeyValuePair <PSystemBody, PSystemBody> >(); // Replaced 'foreach' with 'for' to improve performance PSystemBody[] bodies = PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true); CelestialBody[] hideBodies = PSystemManager.Instance.localBodies.Where(cb => cb.Has("hiddenRnD")).ToArray(); for (Int32 i = 0; i < hideBodies.Length; i++) { CelestialBody body = hideBodies[i]; PropertiesLoader.RnDVisibility visibility = body.Get <PropertiesLoader.RnDVisibility>("hiddenRnD"); if (visibility != PropertiesLoader.RnDVisibility.Hidden && visibility != PropertiesLoader.RnDVisibility.Skip) { continue; } PSystemBody hidden = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, body.transform.name); PSystemBody parent = bodies.FirstOrDefault(b => b.children.Contains(hidden)); if (parent == null) { continue; } // Hide if (hidden.children.Count == 0 || visibility == PropertiesLoader.RnDVisibility.Hidden) { body.Set("hiddenRnd", PropertiesLoader.RnDVisibility.Hidden); hideList.Add(new KeyValuePair <PSystemBody, KeyValuePair <PSystemBody, Int32> >(hidden, new KeyValuePair <PSystemBody, Int32>(parent, 0))); } // Skip else { if (skipList.Any(b => b.Key == parent)) { Int32 index = skipList.IndexOf(skipList.FirstOrDefault(b => b.Key == parent)); skipList.Insert(index, new KeyValuePair <PSystemBody, PSystemBody>(hidden, parent)); } else { skipList.Add(new KeyValuePair <PSystemBody, PSystemBody>(hidden, parent)); } } } // Skip bodies for (Int32 i = 0; i < skipList.Count; i++) { KeyValuePair <PSystemBody, PSystemBody> pair = skipList[i]; // Get hidden body and parent PSystemBody hidden = pair.Key; PSystemBody parent = pair.Value; // Find where the hidden body is Int32 index = parent.children.IndexOf(hidden); // Remove the hidden body from its parent's children list so it won't show up when clicking the parent parent.children.Remove(hidden); // Put its children in its place parent.children.InsertRange(index, hidden.children); } // Hide bodies for (Int32 i = 0; i < hideList.Count; i++) { KeyValuePair <PSystemBody, KeyValuePair <PSystemBody, Int32> > pair = hideList[i]; // Get hidden body and parent PSystemBody hidden = pair.Key; PSystemBody parent = bodies.FirstOrDefault(b => b.children.Contains(hidden)); if (parent == null) { continue; } // Find where the hidden body is Int32 index = parent.children.IndexOf(hidden); // Remove the hidden body from its parent's children list so it won't show up when clicking the parent parent.children.Remove(hidden); // Save the position in the hideList hideList[i] = new KeyValuePair <PSystemBody, KeyValuePair <PSystemBody, Int32> >(hidden, new KeyValuePair <PSystemBody, Int32>(parent, index)); } // Apply changes and revert to the original PSystem if (hideList.Count > 0 || skipList.Count > 0) { // Rebuild Archives AddPlanets(); // Undo the changes to the PSystem (hide) for (Int32 i = hideList.Count - 1; i > -1; i--) { PSystemBody hidden = hideList[i].Key; PSystemBody parent = hideList[i].Value.Key; Int32 oldIndex = hideList[i].Value.Value; parent.children.Insert(oldIndex, hidden); } // Undo the changes to the PSystem (skip) for (Int32 i = skipList.Count - 1; i > -1; i--) { PSystemBody hidden = skipList[i].Key; PSystemBody parent = skipList[i].Value; Int32 oldIndex = parent.children.IndexOf(hidden.children.FirstOrDefault()); parent.children.Insert(oldIndex, hidden); for (Int32 j = 0; j < hidden.children.Count; j++) { PSystemBody child = hidden.children[j]; if (parent.children.Contains(child)) { parent.children.Remove(child); } } } } // RDVisibility = NOICON // Kill Rotation // // Loop through the Containers RDPlanetListItemContainer[] containers = Resources.FindObjectsOfTypeAll <RDPlanetListItemContainer>().Where(i => i.label_planetName.text != "Planet name").ToArray(); for (Int32 i = 0; i < containers.Length; i++) { RDPlanetListItemContainer planetItem = containers[i]; // The label text is set from the CelestialBody's displayName CelestialBody body = PSystemManager.Instance.localBodies.FirstOrDefault(cb => cb.transform.name == planetItem.name); if (body == null) { Debug.Log("[Kopernicus]: RnDFixer: Could not find CelestialBody for the label => " + planetItem.name); continue; } // Barycenter if (body.Has("barycenter") || !body.Get("selectable", true)) { planetItem.planet.SetActive(false); planetItem.label_planetName.alignment = TextAlignmentOptions.MidlineLeft; } // RD Visibility if (body.Has("hiddenRnD")) { PropertiesLoader.RnDVisibility visibility = body.Get <PropertiesLoader.RnDVisibility>("hiddenRnD"); if (visibility == PropertiesLoader.RnDVisibility.Noicon) { planetItem.planet.SetActive(false); planetItem.label_planetName.alignment = TextAlignmentOptions.MidlineLeft; } else { planetItem.planet.SetActive(true); planetItem.label_planetName.alignment = TextAlignmentOptions.MidlineRight; } } // Add planetItems to 'RnDRotationKill' if (planetItem.planet.transform == null) { continue; } if (body.Has("RnDRotation") ? !body.Get <Boolean>("RnDRotation") : body.scaledBody.GetComponentInChildren <SunCoronas>(true) != null) { RnDRotationKill.Add(planetItem); } } }
public static void TextureFixer(Body body1, Body body2, List<Body> list) { if (!SigmaBinary.IamSad) { if (DateTime.Today.Day == 26 && DateTime.Today.Month == 1) { foreach (Body b in list) { b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureScale("_MainTex", new Vector2(b.generatedBody.scaledVersion.GetComponent<Renderer>().material.GetTextureScale("_MainTex").x, -b.generatedBody.scaledVersion.GetComponent<Renderer>().material.GetTextureScale("_MainTex").y)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureScale("_BumpMap", new Vector2(b.generatedBody.scaledVersion.GetComponent<Renderer>().material.GetTextureScale("_BumpMap").x, -b.generatedBody.scaledVersion.GetComponent<Renderer>().material.GetTextureScale("_BumpMap").y)); } } if (DateTime.Today.Day == 14 && DateTime.Today.Month == 2) { Texture2D MainTex = Resources.FindObjectsOfTypeAll<Texture>().Where(tex => tex.name == "NewMunSurfaceMapDiffuse").FirstOrDefault() as Texture2D; Texture2D BumpMap = Resources.FindObjectsOfTypeAll<Texture>().Where(tex => tex.name == "NewMunSurfaceMapNormals").FirstOrDefault() as Texture2D; foreach (Body b in list) { EnumParser<BodyType> type = new EnumParser<BodyType>(b.template == null ? BodyType.Atmospheric : b.template.type); if (type != BodyType.Star) { b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTexture("_MainTex", MainTex); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTexture("_BumpMap", BumpMap); if (OnDemandStorage.useOnDemand) { ScaledSpaceDemand demand = b.generatedBody.scaledVersion.GetComponent<ScaledSpaceDemand>(); demand.texture = MainTex.name; demand.normals = BumpMap.name; } b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureOffset("_MainTex", new Vector2(0, 0)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureScale("_MainTex", new Vector2(1, 1)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureOffset("_BumpMap", new Vector2(0, 0)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureScale("_BumpMap", new Vector2(1, 1)); } } } if (SigmaBinary.ListOfBinaries.Count == 0 && DateTime.Today.Day == 14 && DateTime.Today.Month == 3) { string[] P = new string[] { "92653", "58979", "32384", "62643", "38327", "95028", "84197", "16939", "93751", "05820", "97494", "45923", "07816", "40628", "62089", "98628", "03482", "53421", "17067", "98214" }; Dictionary<CelestialBody, double> pList = new Dictionary<CelestialBody, double>(); foreach (Body pBody in SigmaBinary.ListOfBodies) { if (pBody.name == "Sun") { if (!pBody.generatedBody.celestialBody.GetComponent<NameChanger>()) { NameChanger changer = pBody.generatedBody.celestialBody.gameObject.AddComponent<NameChanger>(); changer.oldName = pBody.name; changer.newName = "3.1415"; } else pBody.generatedBody.celestialBody.gameObject.AddComponent<NameChanger>().newName = "3.1415"; } else if (pBody.generatedBody.celestialBody.Has("orbitPatches") && pBody.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches").GetValue("referenceBody") == "Sun") { pList.Add(pBody.generatedBody.celestialBody, pBody.generatedBody.orbitDriver.orbit.semiMajorAxis); } else if (pBody.orbit.referenceBody == "Sun" && !(pBody.generatedBody.celestialBody.Has("orbitPatches") && pBody.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches").GetValue("referenceBody") != "Sun")) { if (!(pBody.name == "Kerbin" && SigmaBinary.kerbinFixer != "Sun")) { pList.Add(pBody.generatedBody.celestialBody, pBody.generatedBody.orbitDriver.orbit.semiMajorAxis); } } if (pList.ContainsKey(pBody.generatedBody.celestialBody) && pBody.generatedBody.celestialBody.Has("orbitPatches") && pBody.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches").GetValue("semiMajorAxis") != null) { NumericParser<double> sma = new NumericParser<double>(); sma.SetFromString(pBody.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches").GetValue("semiMajorAxis")); pList[pBody.generatedBody.celestialBody] = sma.value; } } foreach (string pSBP in SigmaBinary.archivesFixerList.Keys) { if (pSBP == "Kerbin") { CelestialBody pKF = pList.Keys.ToList().Find(KF => KF.name == SigmaBinary.kerbinFixer); if (pKF != null) { pList.Add(SigmaBinary.ListOfBodies.Find(SBP => SBP.name == pSBP).generatedBody.celestialBody, pList[pKF]); pList.Remove(pKF); } } else { CelestialBody pSBB = pList.Keys.ToList().Find(pREF => pREF.name == SigmaBinary.ListOfBodies.Find(SBP => SBP.name == pSBP).orbit.referenceBody); if (pSBB != null) { pList.Add(SigmaBinary.ListOfBodies.Find(SBP => SBP.name == pSBP).generatedBody.celestialBody, pList[pSBB]); pList.Remove(pSBB); } } } int pCount = 0; foreach (KeyValuePair<CelestialBody, double> pFix in pList.OrderBy(pKey => pKey.Value)) { if (pCount < 20) { if (!pFix.Key.GetComponent<NameChanger>()) { NameChanger changer = pFix.Key.gameObject.AddComponent<NameChanger>(); changer.oldName = pFix.Key.name; changer.newName = P[pCount]; } else pFix.Key.gameObject.GetComponent<NameChanger>().newName = P[pCount]; pCount++; } } } if (DateTime.Today.Day == 1 && DateTime.Today.Month == 4) { EnumParser<BodyType> type1 = new EnumParser<BodyType>(body1.template == null ? BodyType.Atmospheric : body1.template.type); EnumParser<BodyType> type2 = new EnumParser<BodyType>(body2.template == null ? BodyType.Atmospheric : body2.template.type); if (type1.value != BodyType.Star && type2.value != BodyType.Star) { Material material1 = new Material(body1.generatedBody.scaledVersion.GetComponent<Renderer>().material); Material material2 = new Material(body2.generatedBody.scaledVersion.GetComponent<Renderer>().material); body1.generatedBody.scaledVersion.GetComponent<Renderer>().material = material2; body2.generatedBody.scaledVersion.GetComponent<Renderer>().material = material1; if (OnDemandStorage.useOnDemand) { ScaledSpaceDemand demand1 = body1.generatedBody.scaledVersion.GetComponent<ScaledSpaceDemand>(); ScaledSpaceDemand demand2 = body2.generatedBody.scaledVersion.GetComponent<ScaledSpaceDemand>(); demand1.texture = material2.GetTexture("_MainTex").name; demand1.normals = material2.GetTexture("_BumpMap").name; demand2.texture = material1.GetTexture("_MainTex").name; demand2.normals = material1.GetTexture("_BumpMap").name; } } } if (DateTime.Today.Day == 22 && DateTime.Today.Month == 4) { Texture2D MainTex = Resources.FindObjectsOfTypeAll<Texture>().Where(tex => tex.name == "KerbinScaledSpace300").FirstOrDefault() as Texture2D; Texture2D BumpMap = Resources.FindObjectsOfTypeAll<Texture>().Where(tex => tex.name == "KerbinScaledSpace401").FirstOrDefault() as Texture2D; foreach (Body b in list) { EnumParser<BodyType> type = new EnumParser<BodyType>(b.template == null ? BodyType.Atmospheric : b.template.type); if (type != BodyType.Star) { b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTexture("_MainTex", MainTex); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTexture("_BumpMap", BumpMap); if (OnDemandStorage.useOnDemand) { ScaledSpaceDemand demand = b.generatedBody.scaledVersion.GetComponent<ScaledSpaceDemand>(); demand.texture = MainTex.name; demand.normals = BumpMap.name; } b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureOffset("_MainTex", new Vector2(0, 0)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureScale("_MainTex", new Vector2(1, 1)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureOffset("_BumpMap", new Vector2(0, 0)); b.generatedBody.scaledVersion.GetComponent<Renderer>().material.SetTextureScale("_BumpMap", new Vector2(1, 1)); } } } if (DateTime.Today.Day == 25 && DateTime.Today.Month == 05) { list.Find(x => x.name == "Sun").generatedBody.celestialBody.bodyDescription = "\n\n\n DON'T\n PANIC"; list.Find(x => x.name == "Kerbin").generatedBody.celestialBody.bodyDescription = "Mostly harmless."; } if (DateTime.Today.Day == 31 && DateTime.Today.Month == 10) { foreach (Body b in list) { if (b.generatedBody.orbitRenderer != null) { b.generatedBody.orbitRenderer.SetColor(new Color(0.5f, 0.25f, 0f, 1f)); } } } } }