-
-
Save artwhaley/f5bb453b8ed18fa89b53e47ffde46407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MJWrapper | |
{ | |
public static System.Type CoreType; //holds the mechjeb core type | |
public static System.Object core; //holds the core itself | |
public static bool Initialized = false; //keeps from reinitializing | |
public static Vessel vessel { get { return FlightGlobals.ActiveVessel; } } //shortcut to grab active vessel | |
public static bool Initialize() //Startup function to grab the core type and core | |
{ | |
if (Initialized) | |
return true; | |
AssemblyLoader.loadedAssemblies.TypeOperation(t =>{if (t.FullName == "MuMech.MechJebCore"){CoreType = t;}}); | |
if (CoreType == null) {return false;} | |
if (!GetCore()){ return false;} | |
Initialized = true; | |
return true; | |
} | |
public static bool GetCore() | |
{ | |
foreach (Part p in vessel.parts) | |
{ | |
foreach (PartModule module in p.Modules) | |
{ | |
if (module.GetType() == CoreType) | |
{ | |
core = module; | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
public static System.Type FindMechJebModule(string module) // Used to load mechjeb modules. | |
{ | |
Type type = null; | |
AssemblyLoader.loadedAssemblies.TypeOperation(t => | |
{ | |
if (t.FullName == module) | |
{ | |
type = t; | |
} | |
}); | |
return type; | |
} | |
#region Public Functions | |
public static Vector3d Circularize(double UT) //This part works great- grabbing a static method. | |
{ | |
System.Type OrbitalManeuverCalculatorType = FindMechJebModule("MuMech.OrbitalManeuverCalculator"); | |
MethodInfo MPMethod = OrbitalManeuverCalculatorType.GetMethod("DeltaVToCircularize", BindingFlags.Public | BindingFlags.Static); | |
return (Vector3d)MPMethod.Invoke(null, new object[] { vessel.orbit, UT }); | |
} | |
public static void ExecuteOne() | |
{ | |
} | |
public static bool ExecStatus | |
{ | |
get {return true; } //Placeholder to make this compile! Obviously doesn't work! | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment