public static bool setSite(ConfigNode KSC) { bool hasChanged = false; double dtmp; float ftmp; bool btmp; ConfigNode pqsCity = KSC.GetNode("PQSCity"); if (pqsCity == null) { return(false); } ConfigNode pqsDecal = KSC.GetNode("PQSMod_MapDecalTangent"); CelestialBody home = getKSCBody(); PQSCity ksc = findKSC(home); if (ksc != null) { if (pqsCity.HasValue("KEYname")) { if (!(ksc.name.Equals(pqsCity.GetValue("KEYname")))) { Debug.Log("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on."); return(false); } } if (pqsCity.HasValue("repositionRadial")) { ksc.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial")); } if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude")) { double lat, lon; double.TryParse(pqsCity.GetValue("latitude"), out lat); double.TryParse(pqsCity.GetValue("longitude"), out lon); ksc.repositionRadial = KSCSwitcher.LLAtoECEF(lat, lon, 0, home.Radius); } if (pqsCity.HasValue("reorientInitialUp")) { ksc.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp")); } if (pqsCity.HasValue("repositionToSphere")) { if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp)) { ksc.repositionToSphere = btmp; } } if (pqsCity.HasValue("repositionToSphereSurface")) { if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp)) { ksc.repositionToSphereSurface = btmp; } } if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight")) { if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp)) { ksc.repositionToSphereSurfaceAddHeight = btmp; } } if (pqsCity.HasValue("reorientToSphere")) { if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp)) { ksc.reorientToSphere = btmp; } } if (pqsCity.HasValue("repositionRadiusOffset")) { if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp)) { ksc.repositionRadiusOffset = dtmp; } } if (pqsCity.HasValue("lodvisibleRangeMult")) { if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp)) { foreach (PQSCity.LODRange l in ksc.lod) { l.visibleRange *= (float)dtmp; } } } if (pqsCity.HasValue("reorientFinalAngle")) { if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp)) { ksc.reorientFinalAngle = ftmp; } } print("KSCSwitcher changed PQSCity"); hasChanged = true; ksc.OnSetup(); ksc.OnPostSetup(); SpaceCenter.Instance.transform.localPosition = ksc.transform.localPosition; SpaceCenter.Instance.transform.localRotation = ksc.transform.localRotation; } else { Debug.LogError("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on."); return(false); } PQSMod_MapDecalTangent decal = findKSCMapDecal(home); if (decal != null && pqsDecal != null) { // KSC Flat area if (pqsDecal.HasValue("position")) { decal.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position")); } if (pqsDecal.HasValue("radius")) { if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp)) { decal.radius = dtmp; } } if (pqsDecal.HasValue("heightMapDeformity")) { if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp)) { decal.heightMapDeformity = dtmp; } } if (pqsDecal.HasValue("absoluteOffset")) { if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp)) { decal.absoluteOffset = dtmp; } } if (pqsDecal.HasValue("absolute")) { if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp)) { decal.absolute = btmp; } } if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude")) { double lat, lon; double.TryParse(pqsDecal.GetValue("latitude"), out lat); double.TryParse(pqsDecal.GetValue("longitude"), out lon); decal.position = KSCSwitcher.LLAtoECEF(lat, lon, 0, home.Radius); } print("KSCSwitcher changed MapDecal_Tangent"); hasChanged = true; decal.OnSetup(); } if (hasChanged) { SpaceCenter.Instance.Start(); // 1.0.5 if (KSC.HasValue("name")) { KSCLoader.instance.Sites.lastSite = LastKSC.fetch.lastSite = KSC.GetValue("name"); print("KSCSwitcher changed MapDecal_Tangent"); } } return(hasChanged); }
public static bool setSite(ConfigNode KSC) { bool hasChanged = false; double dtmp; float ftmp; bool btmp; CelestialBody Kerbin = getKSCBody(); var mods = Kerbin.pqsController.transform.GetComponentsInChildren(typeof(PQSMod), true); ConfigNode pqsCity = KSC.GetNode("PQSCity"); ConfigNode pqsDecal = KSC.GetNode("PQSMod_MapDecalTangent"); if (pqsCity == null) { return(false); } foreach (var m in mods) { if (m.GetType().ToString().Equals("PQSCity")) { PQSCity mod = m as PQSCity; if (pqsCity.HasValue("KEYname")) { if (!(mod.name.Equals(pqsCity.GetValue("KEYname")))) { continue; } } if (pqsCity.HasValue("repositionRadial")) { mod.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial")); } if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude")) { double lat, lon; double.TryParse(pqsCity.GetValue("latitude"), out lat); double.TryParse(pqsCity.GetValue("longitude"), out lon); mod.repositionRadial = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius); } if (pqsCity.HasValue("reorientInitialUp")) { mod.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp")); } if (pqsCity.HasValue("repositionToSphere")) { if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp)) { mod.repositionToSphere = btmp; } } if (pqsCity.HasValue("repositionToSphereSurface")) { if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp)) { mod.repositionToSphereSurface = btmp; } } if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight")) { if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp)) { mod.repositionToSphereSurfaceAddHeight = btmp; } } if (pqsCity.HasValue("reorientToSphere")) { if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp)) { mod.reorientToSphere = btmp; } } if (pqsCity.HasValue("repositionRadiusOffset")) { if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp)) { mod.repositionRadiusOffset = dtmp; } } if (pqsCity.HasValue("lodvisibleRangeMult")) { if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp)) { foreach (PQSCity.LODRange l in mod.lod) { l.visibleRange *= (float)dtmp; } } } if (pqsCity.HasValue("reorientFinalAngle")) { if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp)) { mod.reorientFinalAngle = ftmp; } } print("*RSS* changed PQSCity"); hasChanged = true; mod.OnSetup(); mod.OnPostSetup(); SpaceCenter.Instance.transform.localPosition = mod.transform.localPosition; SpaceCenter.Instance.transform.localRotation = mod.transform.localRotation; } // KSC Flat area if (pqsDecal != null && m.GetType().ToString().Equals("PQSMod_MapDecalTangent")) { // thanks to asmi for this! PQSMod_MapDecalTangent mod = m as PQSMod_MapDecalTangent; if (pqsDecal.HasValue("position")) { mod.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position")); } if (pqsDecal.HasValue("radius")) { if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp)) { mod.radius = dtmp; } } if (pqsDecal.HasValue("heightMapDeformity")) { if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp)) { mod.heightMapDeformity = dtmp; } } if (pqsDecal.HasValue("absoluteOffset")) { if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp)) { mod.absoluteOffset = dtmp; } } if (pqsDecal.HasValue("absolute")) { if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp)) { mod.absolute = btmp; } } if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude")) { double lat, lon; double.TryParse(pqsDecal.GetValue("latitude"), out lat); double.TryParse(pqsDecal.GetValue("longitude"), out lon); mod.position = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius); } print("*RSS* changed MapDecal_Tangent"); hasChanged = true; mod.OnSetup(); } } if (hasChanged) { Kerbin.pqsController.RebuildSphere(); } return(hasChanged); }
static bool PatchPQS(CelestialBody body, ConfigNode node, double origRadius) { List <string> PQSs = new List <string>(); bool modified = false; bool custom = false; if (node != null && node.HasNode("PQS")) { foreach (ConfigNode n in node.GetNode("PQS").nodes) { PQSs.Add(n.name); } custom = true; } else { if (body.Radius != origRadius) { PQSs.Add(body.bodyName); PQSs.Add(body.bodyName + "Ocean"); } } foreach (string pName in PQSs) { print("**Patching PQS " + pName); // yeah, slow, but juuuuuuuuust in case. foreach (PQS p in Resources.FindObjectsOfTypeAll(typeof(PQS))) { if (p.name.Equals(pName)) { /*if (body.pqsController != p) * if (body.pqsController != p.parentSphere) * continue;*/ if (p.radius != body.Radius) { modified = true; } p.radius = body.Radius; // do nothing yet, because I don't want to copy-paste all my code var mods = p.transform.GetComponentsInChildren(typeof(PQSMod), true); // rebuilding should catch it, but... foreach (var m in mods) { if (m is PQSCity) { PQSCity mod = (PQSCity)m; try { mod.OnSetup(); mod.OnPostSetup(); } catch { } //SpaceCenter.Instance.transform.localPosition = mod.transform.localPosition; //SpaceCenter.Instance.transform.localRotation = mod.transform.localRotation; } if (m is PQSMod_MapDecal) { PQSMod_MapDecal mod = (PQSMod_MapDecal)m; mod.radius *= globalRescale; mod.position *= (float)globalRescale; try { mod.OnSetup(); mod.OnPostSetup(); } catch { } } if (m is PQSMod_MapDecalTangent) { PQSMod_MapDecalTangent mod = (PQSMod_MapDecalTangent)m; mod.radius *= globalRescale; mod.position *= (float)globalRescale; try { mod.OnSetup(); mod.OnPostSetup(); } catch { } } } try { p.RebuildSphere(); } catch (Exception e) { print("Rebuild sphere for " + node.name + " failed: " + e.Message); } } } } return(modified); }