Skip to content

Commit

Permalink
Merge branch 'feature/agx' (Fix #365, fix #364)
Browse files Browse the repository at this point in the history
  • Loading branch information
djungelorm committed Dec 16, 2016
2 parents 9a80a44 + f74d3dc commit c538999
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 18 deletions.
10 changes: 6 additions & 4 deletions server/src/Utils/APILoader.cs
Expand Up @@ -19,7 +19,7 @@ public static class APILoader
/// <param name="apiName">Name of the API to load.</param>
/// <param name="requiredVersion">Required API version.</param>
[SuppressMessage ("Gendarme.Rules.Smells", "AvoidLongMethodsRule")]
public static bool Load (Type api, string assemblyName, string apiName, Version requiredVersion)
public static bool Load (Type api, string assemblyName, string apiName, Version requiredVersion = null)
{
if (api == null)
throw new ArgumentNullException ("api");
Expand All @@ -33,9 +33,11 @@ public static bool Load (Type api, string assemblyName, string apiName, Version

// Version check
var version = new Version (assembly.versionMajor, assembly.versionMinor);
if (version.CompareTo (requiredVersion) < 0) {
Error ("Failed to load " + assemblyName + "; found version " + version + " but version >= " + requiredVersion + " is required");
return false;
if (requiredVersion != null) {
if (version.CompareTo (requiredVersion) < 0) {
Error ("Failed to load " + assemblyName + "; found version " + version + " but version >= " + requiredVersion + " is required");
return false;
}
}

// Get type of APIs static class
Expand Down
1 change: 1 addition & 0 deletions service/SpaceCenter/CHANGES.txt
Expand Up @@ -12,6 +12,7 @@ v0.3.7
* Include this 'other' torque in Vessel.AvailableTorque
* Change required RemoteTech version to 1.8.0
* Change maneuver node methods and properties to use double precision values (#357)
* Add support for Action Groups Extended mod (#364, #365)

v0.3.6
* Add Part.Tag which can be used to get/set the name tag set via the NameTag mod, or kOS (#297)
Expand Down
21 changes: 21 additions & 0 deletions service/SpaceCenter/src/ExternalAPI/AGX.cs
@@ -0,0 +1,21 @@
using System;
using KRPC.Utils;

namespace KRPC.SpaceCenter.ExternalAPI
{
static class AGX
{
public static void Load ()
{
IsAvailable = APILoader.Load (typeof(AGX), "AGExt", "ActionGroupsExtended.AGExtExternal");
}

public static bool IsAvailable { get; private set; }

public static Func<uint, int, bool> AGX2VslGroupState { get; internal set; }

public static Func<uint, int, bool> AGX2VslToggleGroup { get; internal set; }

public static Func<uint, int, bool, bool> AGX2VslActivateGroup { get; internal set; }
}
}
1 change: 1 addition & 0 deletions service/SpaceCenter/src/ExternalAPIAddon.cs
Expand Up @@ -15,6 +15,7 @@ sealed public class ExternalAPIAddon : MonoBehaviour
[SuppressMessage ("Gendarme.Rules.Correctness", "MethodCanBeMadeStaticRule")]
public void Start ()
{
ExternalAPI.AGX.Load ();
ExternalAPI.FAR.Load ();
ExternalAPI.RemoteTech.Load ();
}
Expand Down
1 change: 1 addition & 0 deletions service/SpaceCenter/src/KRPC.SpaceCenter.csproj
Expand Up @@ -89,6 +89,7 @@
<Compile Include="ExtensionMethods\VesselSituationExtensions.cs" />
<Compile Include="ExtensionMethods\VesselTypeExtensions.cs" />
<Compile Include="ExternalAPIAddon.cs" />
<Compile Include="ExternalAPI\AGX.cs" />
<Compile Include="ExternalAPI\FAR.cs" />
<Compile Include="ExternalAPI\RemoteTech.cs" />
<Compile Include="PartForcesAddon.cs" />
Expand Down
58 changes: 44 additions & 14 deletions service/SpaceCenter/src/Services/Control.cs
Expand Up @@ -5,6 +5,7 @@
using KRPC.Continuations;
using KRPC.Service.Attributes;
using KRPC.SpaceCenter.ExtensionMethods;
using KRPC.SpaceCenter.ExternalAPI;
using KRPC.Utils;
using KSP.UI.Screens;

Expand Down Expand Up @@ -286,39 +287,68 @@ IList<Vessel> PostActivateStage (global::Vessel[] preVessels)
/// <summary>
/// Returns <c>true</c> if the given action group is enabled.
/// </summary>
/// <param name="group">A number between 0 and 9 inclusive.</param>
/// <param name="group">
/// A number between 0 and 9 inclusive,
/// or between 0 and 250 inclusive when the <a href="http://forum.kerbalspaceprogram.com/index.php?/topic/67235-12oct3116-action-groups-extended-250-action-groups-in-flight-editing-now-kosremotetech">Extended Action Groups mod</a> is installed.
/// </param>
[KRPCMethod]
public bool GetActionGroup (uint group)
{
if (group > 9)
throw new ArgumentException ("Action group must be between 0 and 9 inclusive");
return InternalVessel.ActionGroups.groups [BaseAction.GetGroupIndex (ActionGroupExtensions.GetActionGroup (group))];
var vessel = InternalVessel;
if (AGX.IsAvailable) {
if (group > 250)
throw new ArgumentException ("Action group must be between 0 and 250 inclusive");
return AGX.AGX2VslGroupState (vessel.rootPart.flightID, (int)group);
} else {
if (group > 9)
throw new ArgumentException ("Action group must be between 0 and 9 inclusive");
return vessel.ActionGroups.groups [BaseAction.GetGroupIndex (ActionGroupExtensions.GetActionGroup (group))];
}
}

/// <summary>
/// Sets the state of the given action group (a value between 0 and 9
/// inclusive).
/// Sets the state of the given action group.
/// </summary>
/// <param name="group">A number between 0 and 9 inclusive.</param>
/// <param name="group">
/// A number between 0 and 9 inclusive,
/// or between 0 and 250 inclusive when the <a href="http://forum.kerbalspaceprogram.com/index.php?/topic/67235-12oct3116-action-groups-extended-250-action-groups-in-flight-editing-now-kosremotetech">Extended Action Groups mod</a> is installed.
/// </param>
/// <param name="state"></param>
[KRPCMethod]
public void SetActionGroup (uint group, bool state)
{
if (group > 9)
throw new ArgumentException ("Action group must be between 0 and 9 inclusive");
InternalVessel.ActionGroups.SetGroup (ActionGroupExtensions.GetActionGroup (group), state);
var vessel = InternalVessel;
if (AGX.IsAvailable) {
if (group > 250)
throw new ArgumentException ("Action group must be between 0 and 250 inclusive");
AGX.AGX2VslActivateGroup (vessel.rootPart.flightID, (int)group, state);
} else {
if (group > 9)
throw new ArgumentException ("Action group must be between 0 and 9 inclusive");
vessel.ActionGroups.SetGroup (ActionGroupExtensions.GetActionGroup (group), state);
}
}

/// <summary>
/// Toggles the state of the given action group.
/// </summary>
/// <param name="group">A number between 0 and 9 inclusive.</param>
/// <param name="group">
/// A number between 0 and 9 inclusive,
/// or between 0 and 250 inclusive when the <a href="http://forum.kerbalspaceprogram.com/index.php?/topic/67235-12oct3116-action-groups-extended-250-action-groups-in-flight-editing-now-kosremotetech">Extended Action Groups mod</a> is installed.
/// </param>
[KRPCMethod]
public void ToggleActionGroup (uint group)
{
if (group > 9)
throw new ArgumentException ("Action group must be between 0 and 9 inclusive");
InternalVessel.ActionGroups.ToggleGroup (ActionGroupExtensions.GetActionGroup (group));
var vessel = InternalVessel;
if (AGX.IsAvailable) {
if (group > 250)
throw new ArgumentException ("Action group must be between 0 and 250 inclusive");
AGX.AGX2VslToggleGroup (vessel.rootPart.flightID, (int)group);
} else {
if (group > 9)
throw new ArgumentException ("Action group must be between 0 and 9 inclusive");
vessel.ActionGroups.ToggleGroup (ActionGroupExtensions.GetActionGroup (group));
}
}

/// <summary>
Expand Down

0 comments on commit c538999

Please sign in to comment.