Skip to content

Commit

Permalink
remove extension methods on KSP classes. breaks backwards compat.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbudda committed Jun 27, 2021
1 parent cc5bab0 commit 4da62d4
Show file tree
Hide file tree
Showing 24 changed files with 144 additions and 182 deletions.
Binary file modified Assets/Plugins/KerbalEngineer.Unity.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions Documents/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.1.9.0, 2021-6-27, KSP 1.12.0 #3140
- Fix backwards compatibility

1.1.8.4, 2021-6-24, KSP 1.12.0 #3140
- Update to KSP 1.12. No changes.

Expand Down
36 changes: 18 additions & 18 deletions KerbalEngineer/Editor/BuildOverlayPartInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void ResetInfo()

private void SetAlternatorInfo()
{
ModuleAlternator moduleAlternator = selectedPart.GetModule<ModuleAlternator>();
ModuleAlternator moduleAlternator = PartExtensions.GetModule<ModuleAlternator>(selectedPart);
if (moduleAlternator != null)
{
infoItems.Add(PartInfoItem.Create("Alternator"));
Expand All @@ -230,12 +230,12 @@ private void SetAlternatorInfo()

private void SetCostInfo()
{
infoItems.Add(PartInfoItem.Create("Cost", Units.ConcatF(selectedPart.GetCostDry(), selectedPart.GetCostWet())));
infoItems.Add(PartInfoItem.Create("Cost", Units.ConcatF(PartExtensions.GetCostDry(selectedPart), PartExtensions.GetCostWet(selectedPart))));
}

private void SetDecouplerInfo()
{
var protoModuleDecoupler = selectedPart.GetProtoModuleDecoupler();
var protoModuleDecoupler = PartExtensions.GetProtoModuleDecoupler(selectedPart);
if (protoModuleDecoupler != null)
{
infoItems.Add(PartInfoItem.Create("Ejection Force", protoModuleDecoupler.EjectionForce.ToForce()));
Expand All @@ -248,7 +248,7 @@ private void SetDecouplerInfo()

private void SetEngineInfo()
{
var protoModuleEngine = selectedPart.GetProtoModuleEngine();
var protoModuleEngine = PartExtensions.GetProtoModuleEngine(selectedPart);
if (protoModuleEngine != null)
{
infoItems.Add(PartInfoItem.Create("Thrust", Units.ToForce(protoModuleEngine.MinimumThrust, protoModuleEngine.MaximumThrust)));
Expand All @@ -274,7 +274,7 @@ private void SetEngineInfo()

private void SetGeneratorInfo()
{
var moduleGenerator = selectedPart.GetModule<ModuleGenerator>();
var moduleGenerator = PartExtensions.GetModule<ModuleGenerator>(selectedPart);
if (moduleGenerator != null)
{
if (moduleGenerator.resHandler.inputResources.Count > 0)
Expand Down Expand Up @@ -306,7 +306,7 @@ private void SetGeneratorInfo()

private void SetGimbalInfo()
{
var moduleGimbal = selectedPart.GetModule<ModuleGimbal>();
var moduleGimbal = PartExtensions.GetModule<ModuleGimbal>(selectedPart);
if (moduleGimbal != null)
{
infoItems.Add(PartInfoItem.Create("Thrust Vectoring", moduleGimbal.gimbalRange.ToString("F2")));
Expand All @@ -317,13 +317,13 @@ private void SetMassItems()
{
if (selectedPart.physicalSignificance == Part.PhysicalSignificance.FULL)
{
infoItems.Add(PartInfoItem.Create("Mass", Units.ToMass(selectedPart.GetDryMass(), selectedPart.GetWetMass())));
infoItems.Add(PartInfoItem.Create("Mass", Units.ToMass(PartExtensions.GetDryMass(selectedPart), PartExtensions.GetWetMass(selectedPart))));
}
}

private void SetParachuteInfo()
{
var moduleParachute = selectedPart.GetModule<ModuleParachute>();
var moduleParachute = PartExtensions.GetModule<ModuleParachute>(selectedPart);
if (moduleParachute != null)
{
infoItems.Add(PartInfoItem.Create("Deployed Drag", Units.ConcatF(moduleParachute.semiDeployedDrag, moduleParachute.fullyDeployedDrag)));
Expand All @@ -334,7 +334,7 @@ private void SetParachuteInfo()

private void SetRcsInfo()
{
var moduleRcs = selectedPart.GetModule<ModuleRCS>();
var moduleRcs = PartExtensions.GetModule<ModuleRCS>(selectedPart);
if (moduleRcs != null)
{
infoItems.Add(PartInfoItem.Create("Thruster Power", moduleRcs.thrusterPower.ToForce()));
Expand All @@ -344,7 +344,7 @@ private void SetRcsInfo()

private void SetReactionWheelInfo()
{
var moduleReactionWheel = selectedPart.GetModule<ModuleReactionWheel>();
var moduleReactionWheel = PartExtensions.GetModule<ModuleReactionWheel>(selectedPart);
if (moduleReactionWheel != null)
{
infoItems.Add(PartInfoItem.Create("Reaction Wheel Torque"));
Expand Down Expand Up @@ -380,8 +380,8 @@ private void SetResourceItems()

if (partResource.hideFlow == false)
{
infoItems.Add(partResource.GetDensity() > 0
? PartInfoItem.Create("\t" + partResource.info.name, "(" + partResource.GetMass().ToMass() + ") " + partResource.amount.ToString("F1"))
infoItems.Add(PartResourceExtensions.GetDensity(partResource) > 0
? PartInfoItem.Create("\t" + partResource.info.name, "(" + PartResourceExtensions.GetMass(partResource).ToMass() + ") " + partResource.amount.ToString("F1"))
: PartInfoItem.Create("\t" + partResource.info.name, partResource.amount.ToString("F1")));
}
}
Expand All @@ -390,23 +390,23 @@ private void SetResourceItems()

private void SetSasInfo()
{
if (selectedPart.HasModule<ModuleSAS>())
if (PartExtensions.HasModule<ModuleSAS>(selectedPart))
{
infoItems.Add(PartInfoItem.Create("SAS Equiped"));
}
}

private void SetScienceContainerInfo()
{
if (selectedPart.HasModule<ModuleScienceContainer>())
if (PartExtensions.HasModule<ModuleScienceContainer>(selectedPart))
{
infoItems.Add(PartInfoItem.Create("Science Container"));
}
}

private void SetScienceExperimentInfo()
{
var moduleScienceExperiment = selectedPart.GetModule<ModuleScienceExperiment>();
var moduleScienceExperiment = PartExtensions.GetModule<ModuleScienceExperiment>(selectedPart);
if (moduleScienceExperiment != null)
{
infoItems.Add(PartInfoItem.Create("Science Experiment", moduleScienceExperiment.experimentActionName));
Expand All @@ -420,15 +420,15 @@ private void SetScienceExperimentInfo()

private void SetSingleActivationInfo()
{
if (selectedPart.HasModule<ModuleAnimateGeneric>(m => m.isOneShot))
if (PartExtensions.HasModule<ModuleAnimateGeneric>(selectedPart, m => m.isOneShot))
{
infoItems.Add(PartInfoItem.Create("Single Activation"));
}
}

private void SetSolarPanelInfo()
{
var moduleDeployableSolarPanel = selectedPart.GetModule<ModuleDeployableSolarPanel>();
var moduleDeployableSolarPanel = PartExtensions.GetModule<ModuleDeployableSolarPanel>(selectedPart);
if (moduleDeployableSolarPanel != null)
{
infoItems.Add(PartInfoItem.Create("Charge Rate", moduleDeployableSolarPanel.chargeRate.ToRate()));
Expand All @@ -446,7 +446,7 @@ private void SetSolarPanelInfo()

private void SetTransmitterInfo()
{
var moduleDataTransmitter = selectedPart.GetModule<ModuleDataTransmitter>();
var moduleDataTransmitter = PartExtensions.GetModule<ModuleDataTransmitter>(selectedPart);
if (moduleDataTransmitter != null)
{
infoItems.Add(PartInfoItem.Create("Packet Size", moduleDataTransmitter.packetSize.ToString("F2") + " Mits"));
Expand Down
2 changes: 1 addition & 1 deletion KerbalEngineer/Editor/ResourceInfoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ResourceInfoItem

public ResourceInfoItem(PartResource resource)
{
this.Definition = resource.GetDefinition();
this.Definition = PartResourceExtensions.GetDefinition(resource);
this.Name = this.Definition.name;
this.Amount = resource.amount;
}
Expand Down
2 changes: 1 addition & 1 deletion KerbalEngineer/EngineerGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class EngineerGlobals
/// <summary>
/// Current version of the Kerbal Engineer assembly.
/// </summary>
public const string ASSEMBLY_VERSION = "1.1.8.4";
public const string ASSEMBLY_VERSION = "1.1.9.0";

private static string assemblyFile;
private static string assemblyName;
Expand Down
52 changes: 19 additions & 33 deletions KerbalEngineer/Extensions/OrbitExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
//
// Kerbal Engineer Redux
//
// Copyright (C) 2014 CYBUTEK
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
// Extensions methods are bad.

#region Using Directives

Expand All @@ -39,22 +25,22 @@ public static class OrbitExtensions

#region Methods: public

public static double GetAngleToAscendingNode(this Orbit orbit)
public static double GetAngleToAscendingNode(Orbit orbit)
{
return GetAngleToTrueAnomaly(orbit, GetTrueAnomalyOfAscendingNode(orbit));
}

public static double GetAngleToDescendingNode(this Orbit orbit)
public static double GetAngleToDescendingNode(Orbit orbit)
{
return GetAngleToTrueAnomaly(orbit, GetTrueAnomalyOfDescendingNode(orbit));
}

public static double GetAngleToPrograde(this Orbit orbit)
public static double GetAngleToPrograde(Orbit orbit)
{
return GetAngleToPrograde(orbit, Planetarium.GetUniversalTime());
}

public static double GetAngleToPrograde(this Orbit orbit, double universalTime)
public static double GetAngleToPrograde(Orbit orbit, double universalTime)
{
if (orbit.referenceBody == CelestialBodies.SystemBody.CelestialBody)
{
Expand All @@ -72,12 +58,12 @@ public static double GetAngleToPrograde(this Orbit orbit, double universalTime)
return AngleHelper.Clamp360(orbit.inclination < 90.0 ? angle : 360.0 - angle);
}

public static double GetAngleToRetrograde(this Orbit orbit)
public static double GetAngleToRetrograde(Orbit orbit)
{
return GetAngleToRetrograde(orbit, Planetarium.GetUniversalTime());
}

public static double GetAngleToRetrograde(this Orbit orbit, double universalTime)
public static double GetAngleToRetrograde(Orbit orbit, double universalTime)
{
if (orbit.referenceBody == CelestialBodies.SystemBody.CelestialBody)
{
Expand All @@ -95,59 +81,59 @@ public static double GetAngleToRetrograde(this Orbit orbit, double universalTime
return AngleHelper.Clamp360(orbit.inclination < 90.0 ? angle : 360.0 - angle);
}

public static double GetAngleToTrueAnomaly(this Orbit orbit, double trueAnomaly)
public static double GetAngleToTrueAnomaly(Orbit orbit, double trueAnomaly)
{
return AngleHelper.Clamp360(trueAnomaly - (orbit.trueAnomaly * Units.RAD_TO_DEG));
}

public static double GetAngleToVector(this Orbit orbit, Vector3d vector)
public static double GetAngleToVector(Orbit orbit, Vector3d vector)
{
return GetAngleToTrueAnomaly(orbit, GetTrueAnomalyFromVector(orbit, Vector3d.Exclude(orbit.GetOrbitNormal(), vector)));
}

public static double GetPhaseAngle(this Orbit orbit, Orbit target)
public static double GetPhaseAngle(Orbit orbit, Orbit target)
{
var angle = AngleHelper.GetAngleBetweenVectors(Vector3d.Exclude(orbit.GetOrbitNormal(), target.pos), orbit.pos);
return (orbit.semiMajorAxis < target.semiMajorAxis) ? angle : angle - 360.0;
}

public static double GetRelativeInclination(this Orbit orbit, Orbit target)
public static double GetRelativeInclination(Orbit orbit, Orbit target)
{
return Vector3d.Angle(orbit.GetOrbitNormal(), target.GetOrbitNormal());
}

public static double GetTimeToAscendingNode(this Orbit orbit)
public static double GetTimeToAscendingNode(Orbit orbit)
{
return GetTimeToTrueAnomaly(orbit, GetTrueAnomalyOfAscendingNode(orbit));
}

public static double GetTimeToDescendingNode(this Orbit orbit)
public static double GetTimeToDescendingNode(Orbit orbit)
{
return GetTimeToTrueAnomaly(orbit, GetTrueAnomalyOfDescendingNode(orbit));
}

public static double GetTimeToTrueAnomaly(this Orbit orbit, double trueAnomaly)
public static double GetTimeToTrueAnomaly(Orbit orbit, double trueAnomaly)
{
var time = orbit.GetDTforTrueAnomaly(trueAnomaly * Mathf.Deg2Rad, orbit.period);
return time < 0.0 ? time + orbit.period : time;
}

public static double GetTimeToVector(this Orbit orbit, Vector3d vector)
public static double GetTimeToVector(Orbit orbit, Vector3d vector)
{
return GetTimeToTrueAnomaly(orbit, GetTrueAnomalyFromVector(orbit, vector));
}

public static double GetTrueAnomalyFromVector(this Orbit orbit, Vector3d vector)
public static double GetTrueAnomalyFromVector(Orbit orbit, Vector3d vector)
{
return orbit.GetTrueAnomalyOfZupVector(vector) * Mathf.Rad2Deg;
}

public static double GetTrueAnomalyOfAscendingNode(this Orbit orbit)
public static double GetTrueAnomalyOfAscendingNode(Orbit orbit)
{
return 360.0 - orbit.argumentOfPeriapsis;
}

public static double GetTrueAnomalyOfDescendingNode(this Orbit orbit)
public static double GetTrueAnomalyOfDescendingNode(Orbit orbit)
{
return 180.0 - orbit.argumentOfPeriapsis;
}
Expand Down
Loading

1 comment on commit 4da62d4

@jrbudda
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should fix #76

Please sign in to comment.