Skip to content

Commit

Permalink
Fix renaming of launchSites and sorted the Squad launchSites
Browse files Browse the repository at this point in the history
  • Loading branch information
GER-Space committed Jan 20, 2019
1 parent 00ba631 commit aa9b5dd
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
Binary file modified GameData/KerbalKonstructs/KerbalKonstructs.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/KerbalKonstructs/KerbalKonstructs.version
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"MAJOR":1,
"MINOR":4,
"PATCH":5,
"BUILD":50
"BUILD":51
},
"KSP_VERSION":
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/LaunchSites/LaunchSiteChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static void PrepareSystem()
/// <returns></returns>
public PreFlightCheck NewPreflightCheck(string launchSiteName)
{
Log.Normal("using injected call");
//Log.Normal("using injected call");
PreFlightCheck check = (PreFlightCheck)preFlightCheckDetour.CallOriginal(EditorLogic.fetch, new object[] { launchSiteName });
check.AddTest(new KKPrelaunchSizeCheck(launchSiteName));
check.AddTest(new KKPrelaunchMassCheck(launchSiteName));
Expand Down
42 changes: 23 additions & 19 deletions src/Core/LaunchSites/LaunchSiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ internal static void RegisterLaunchSite(KKLaunchSite site , bool isSquad = false
//site.staticInstance.gameObject.transform.name = site.LaunchSiteName;
//site.staticInstance.gameObject.name = site.LaunchSiteName;

if (KKFacilities == null)
{
KKFacilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();
}
KKFacilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();

if (KKFacilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() == null)
{
Expand Down Expand Up @@ -354,12 +351,16 @@ internal static void RegisterLaunchSite(KKLaunchSite site , bool isSquad = false
}
spaceCenterFacility.Setup(new PQS[] { site.staticInstance.CelestialBody.pqsController });



KKFacilities.Add(spaceCenterFacility);

KKFacilities.Sort(delegate (PSystemSetup.SpaceCenterFacility a, PSystemSetup.SpaceCenterFacility b)
{
return (a.facilityDisplayName).CompareTo(b.facilityDisplayName);
});

PSystemSetup.Instance.SpaceCenterFacilities = KKFacilities.ToArray();


site.spaceCenterFacility = spaceCenterFacility;

if (site.staticInstance.destructible != null)
Expand Down Expand Up @@ -427,7 +428,7 @@ public static void AlterMHSelector(bool triggerRestart = true)

internal static void RegisterMHLaunchSites(EditorFacility facility)
{
foreach (KKLaunchSite site in allLaunchSites)
foreach (KKLaunchSite site in allLaunchSites )
{
if (facility == EditorFacility.SPH && site.LaunchSiteType == SiteType.VAB)
{
Expand Down Expand Up @@ -469,17 +470,22 @@ internal static void UnregisterLaunchSite(KKLaunchSite site)
CloseLaunchSite(site);
}

List<PSystemSetup.SpaceCenterFacility> spaceCenters = PSystemSetup.Instance.SpaceCenterFacilities.ToList();
PSystemSetup.SpaceCenterFacility spaceToDel = spaceCenters.Where(x => x.facilityName == site.LaunchSiteName).FirstOrDefault();
List<PSystemSetup.SpaceCenterFacility> spaceCenters = new List<PSystemSetup.SpaceCenterFacility>();

if (spaceToDel != null)
foreach (PSystemSetup.SpaceCenterFacility center in PSystemSetup.Instance.SpaceCenterFacilities)
{
spaceCenters.Remove(spaceToDel);
PSystemSetup.Instance.SpaceCenterFacilities = spaceCenters.ToArray();
Log.Normal("Launchsite: " + site.LaunchSiteName + " sucessfully unregistered");
if (center.facilityDisplayName == site.LaunchSiteName)
{
Log.Normal("Launchsite: " + site.LaunchSiteName + " sucessfully unregistered");
continue;
}
else
{
spaceCenters.Add(center);
}
}

KKFacilities.Remove(site.spaceCenterFacility);
PSystemSetup.Instance.SpaceCenterFacilities = spaceCenters.ToArray();

}

Expand Down Expand Up @@ -512,14 +518,12 @@ internal static void DeleteLaunchSite(KKLaunchSite site2delete)
/// <param name="site2add"></param>
internal static void AddLaunchSite(KKLaunchSite site2add)
{

launchSites.Add(site2add);
List<KKLaunchSite> tmpList = launchSites.ToList();
tmpList.Sort(delegate (KKLaunchSite a, KKLaunchSite b)
launchSites.Sort(delegate (KKLaunchSite a, KKLaunchSite b)
{
return (a.LaunchSiteName).CompareTo(b.LaunchSiteName);
});
allLaunchSites = tmpList.ToArray();
allLaunchSites = launchSites.ToArray();
launchSiteNames.Add(site2add.LaunchSiteName);
}

Expand Down Expand Up @@ -658,9 +662,9 @@ public static KKLaunchSite GetLaunchSiteByName(string siteName)
if (site.LaunchSiteName.Equals(siteName))
{
mySite = site;
Log.Normal("found LS: " + mySite.LaunchSiteName);
}
}
Log.Normal("Returning LS: " + mySite.LaunchSiteName);
return mySite;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ internal class Log
internal static void Debug(string message)
{
if (KerbalKonstructs.instance.DebugMode)
{
UnityEngine.Debug.Log("KK: " + new StackFrame(1, true).GetMethod().Name + ": " + message);
}
}

/// <summary>
Expand Down
21 changes: 20 additions & 1 deletion src/Editor/InstanceEditor/LaunchSiteEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,21 @@ internal void SaveSettings()
selectedObject.launchSite.body = selectedObject.CelestialBody;
addToDB = true;
}
else
{
// delete old LaunchSite on name change and add the new one.
if (siteName != selectedObject.launchSite.LaunchSiteName)
{
Log.Normal("Renaming of a LaunchSite triggered 1");
LaunchSiteManager.DeleteLaunchSite(selectedObject.launchSite);
}
}

string oldName = selectedObject.launchSite.LaunchSiteName;
LaunchSiteCategory oldCategory = category;
bool oldState = selectedObject.launchSite.ILSIsActive;


selectedObject.launchSite.LaunchSiteName = siteName;
selectedObject.launchSite.LaunchSiteLength = float.Parse(stLength);
selectedObject.launchSite.LaunchSiteWidth = float.Parse(stWidth);
Expand Down Expand Up @@ -468,7 +478,6 @@ internal void SaveSettings()
}
}


if (addToDB)
{
selectedObject.launchSite.ParseLSConfig(selectedObject, null);
Expand All @@ -477,6 +486,16 @@ internal void SaveSettings()
selectedObject.ToggleAllColliders(true);
LaunchSiteManager.RegisterLaunchSite(selectedObject.launchSite);
}
else
{
// register with the new name.
if (siteName != oldName)
{
Log.Normal("Renaming of a LaunchSite triggered 2");
LaunchSiteManager.RegisterLaunchSite(selectedObject.launchSite);
}
}

selectedObject.SaveConfig();

}
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("1.4.5.50")]
[assembly: AssemblyInformationalVersion("1.4.5.50")]
[assembly: AssemblyFileVersion("1.4.5.51")]
[assembly: AssemblyInformationalVersion("1.4.5.51")]
[assembly: KSPAssembly("KerbalKonstructs", 0, 9)]

0 comments on commit aa9b5dd

Please sign in to comment.