-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - restructure code into separate classes, working towards getting…
… full astrogator view data
- Loading branch information
1 parent
1617ad5
commit eac28f7
Showing
12 changed files
with
245 additions
and
197 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"VERSION": { | ||
"MAJOR": 0, | ||
"MINOR": 1, | ||
"PATCH": 1 | ||
"PATCH": 2 | ||
}, | ||
"KSP_VERSION_MIN": { | ||
"MAJOR": 1, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using kOS.Safe.Utilities; | ||
using kOS.Safe.Encapsulation; | ||
using kOS.Safe.Encapsulation.Suffixes; | ||
using kOS.Suffixed; | ||
using Astrogator; | ||
|
||
namespace kOS.AddOns.kOSAstrogator | ||
{ | ||
using transfer; | ||
using info; | ||
/// <summary> | ||
/// kOS integration for Astrogator | ||
/// </summary> | ||
[kOSAddon("ASTROGATOR")] | ||
[KOSNomenclature("AstrogatorAddon")] | ||
public class KOSAstrogatorAddon : Addon | ||
{ | ||
|
||
/// <summary> | ||
/// The class initializer | ||
/// </summary> | ||
/// <param name="shared">The shared objects</param> | ||
public KOSAstrogatorAddon(SharedObjects shared) : base(shared) | ||
{ | ||
InitializeSuffixes(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override BooleanValue Available() => Util.IsModInstalled("Astrogator"); | ||
|
||
private void InitializeSuffixes() | ||
{ | ||
// info | ||
AddSuffix("help", new NoArgsVoidSuffix(() => Help.PrintHelp(shared))); | ||
AddSuffix("version", new NoArgsSuffix<StringValue>(() => Version.GetVersion())); | ||
|
||
// creating transfers and info | ||
AddSuffix("create", new OptionalArgsSuffix<Node>(CreateTransfer, new Safe.Encapsulation.Structure[] { null, BooleanValue.True })); | ||
AddSuffix("calculateBurns", new OneArgsSuffix<ListValue, BodyTarget>(CalculateBurns)); | ||
|
||
// physics | ||
AddSuffix("deltaVToOrbit", new OneArgsSuffix<ScalarDoubleValue, BodyTarget>(DeltaVToOrbit)); | ||
AddSuffix("speedAtPeriapsis", new ThreeArgsSuffix<ScalarDoubleValue, BodyTarget, ScalarValue, ScalarValue>(SpeedAtPeriapsis)); | ||
AddSuffix("speedAtApoapsis", new ThreeArgsSuffix<ScalarDoubleValue, BodyTarget, ScalarValue, ScalarValue>(SpeedAtApoapsis)); | ||
AddSuffix("shipSpeedAtPeriapsis", new NoArgsSuffix<ScalarDoubleValue>(ShipSpeedAtPeriapsis)); | ||
AddSuffix("shipSpeedAtApoapsis", new NoArgsSuffix<ScalarDoubleValue>(ShipSpeedAtApoapsis)); | ||
|
||
} | ||
|
||
#region suffix_functions | ||
// I don't know how to move these directly into the above, or make the above call different classes. Haven't learned enough about delegates yet. | ||
|
||
private Node CreateTransfer(params Safe.Encapsulation.Structure[] args) => Transfers.CreateManeuverNodes(shared, args); | ||
private ListValue CalculateBurns(BodyTarget dest) => Transfers.CalculateBurns(shared, dest); | ||
private ScalarDoubleValue DeltaVToOrbit(BodyTarget body) => PhysicsTools.DeltaVToOrbit(body.Body); | ||
private ScalarDoubleValue SpeedAtPeriapsis(BodyTarget body, ScalarValue apopapsis, ScalarValue periapsis) => PhysicsTools.SpeedAtPeriapsis(body.Body, apopapsis.GetDoubleValue(), periapsis.GetDoubleValue()); | ||
private ScalarDoubleValue SpeedAtApoapsis(BodyTarget body, ScalarValue apopapsis, ScalarValue periapsis) => PhysicsTools.SpeedAtApoapsis(body.Body, apopapsis.GetDoubleValue(), periapsis.GetDoubleValue()); | ||
private ScalarDoubleValue ShipSpeedAtPeriapsis() => PhysicsTools.SpeedAtPeriapsis(shared.Vessel.mainBody, shared.Vessel.orbit.ApR, shared.Vessel.orbit.PeR); | ||
private ScalarDoubleValue ShipSpeedAtApoapsis() => PhysicsTools.SpeedAtApoapsis(shared.Vessel.mainBody, shared.Vessel.orbit.ApR, shared.Vessel.orbit.PeR); | ||
#endregion | ||
|
||
#region internal_function | ||
#endregion | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace kOS.AddOns.kOSAstrogator | ||
{ | ||
/// <summary> | ||
/// Everyone needs a util class | ||
/// </summary> | ||
public class Util | ||
{ | ||
///<summary> | ||
/// checks if the mod with "assemblyName" is loaded into KSP. Taken from KOS-Scansat | ||
///</summary> | ||
public static bool IsModInstalled(string assemblyName) | ||
{ | ||
Assembly assembly = (from a in AssemblyLoader.loadedAssemblies | ||
where a.name.ToLower().Equals(assemblyName.ToLower()) | ||
select a).FirstOrDefault().assembly; | ||
return assembly != null; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace kOS.AddOns.kOSAstrogator.info | ||
{ | ||
/// <summary> | ||
/// Help command | ||
/// </summary> | ||
public static class Help | ||
{ | ||
/// <summary> | ||
/// The help command | ||
/// </summary> | ||
/// <param name="shared">The shared data</param> | ||
public static void PrintHelp(SharedObjects shared) | ||
{ | ||
shared.Screen.Print("--------------------------------------------"); | ||
shared.Screen.Print("kOS-Astrogator"); | ||
shared.Screen.Print("Usage: addons:astrogator:<cmd>"); | ||
shared.Screen.Print("See https://github.com/markjfisher/kOS-Astrogator/blob/master/GameData/kOS-Astrogator/README.md"); | ||
shared.Screen.Print("for full command details."); | ||
shared.Screen.Print("--------------------------------------------"); | ||
} | ||
} | ||
} |
Oops, something went wrong.