private void OnGameStateCreated(Game game) { LastKSC.CreateSettings(game); if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { ProtoScenarioModule m = HighLogic.CurrentGame.scenarios.FirstOrDefault(m => m.moduleName == "LastKSC"); if (m == null) { return; } LastKSC l = (LastKSC)m.Load(ScenarioRunner.Instance); bool noSite; if (!string.IsNullOrEmpty(l.lastSite)) { // found a site, load it ConfigNode site = Sites.GetSiteByName(l.lastSite); if (site == null) { l.lastSite = Sites.defaultSite; noSite = true; } else { KSCSwitcher.SetSiteAndResetCamera(site); Debug.Log("KSCSwitcher set the launch site to the last site, " + l.lastSite); return; } } else { l.lastSite = Sites.defaultSite; noSite = true; } if (noSite) { if (!string.IsNullOrEmpty(Sites.defaultSite)) { ConfigNode site = Sites.GetSiteByName(Sites.defaultSite); if (site == null) { Debug.LogError("KSCSwitcher found a default site name but could not retrieve the site config: " + Sites.defaultSite); return; } else { KSCSwitcher.SetSiteAndResetCamera(site); Debug.Log("KSCSwitcher set the initial launch site to the default" + Sites.defaultSite); } } } } }
void onGameStateCreated(Game game) { LastKSC.CreateSettings(game); bool noSite = false; if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { foreach (ProtoScenarioModule m in HighLogic.CurrentGame.scenarios) { if (m.moduleName == "LastKSC") { LastKSC l = (LastKSC)m.Load(ScenarioRunner.Instance); if (l.lastSite.Length > 0) { // found a site, load it ConfigNode site = Sites.getSiteByName(l.lastSite); if (site == null) { l.lastSite = Sites.defaultSite; noSite = true; } else { KSCSwitcher.setSite(site); Debug.Log("KSCSwitcher set the launch site to " + l.lastSite); return; } } else { l.lastSite = Sites.defaultSite; noSite = true; } if (noSite) { if (Sites.defaultSite.Length > 0) { ConfigNode site = Sites.getSiteByName(Sites.defaultSite); if (site == null) { Debug.LogError("KSCSwitcher found a default site name but could not retrieve the site config: " + Sites.defaultSite); return; } else { KSCSwitcher.setSite(site); Debug.Log("KSCSwitcher set the initial launch site to " + Sites.defaultSite); } } } } } } }
private void setSite(LaunchSite newSite) { ConfigNode site = KSCLoader.instance.Sites.getSiteByName(newSite.name); if (site == null) { return; } if (KSCSwitcher.setSite(site)) { activeSite = newSite.name; ScreenMessages.PostScreenMessage("Launch site changed to " + newSite.displayName, 2.5f, ScreenMessageStyle.LOWER_CENTER); showWindow = false; } }
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); }