Skip to content

Commit

Permalink
Fix for issue KSP-KOS#1849
Browse files Browse the repository at this point in the history
  • Loading branch information
GER-Space committed Oct 21, 2016
1 parent 4696559 commit c5c49ab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
41 changes: 17 additions & 24 deletions src/kOS/AddOns/InfernalRobotics/IRWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,25 @@ public class IRWrapper
internal static bool InstanceExists { get { return (IRController != null); } }
internal static bool APIReady { get { return isWrapped && IRController.Ready; } }

internal static Type GetType(string name)
{
Type type = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == name)
type = t;
});
return type;
}

internal static bool InitWrapper()
{
isWrapped = false;
ActualServoController = null;
IRController = null;
LogFormatted("Attempting to Grab IR Types...");

IRServoControllerType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Command.ServoController");
IRServoControllerType = GetType("InfernalRobotics.Command.ServoController");

if (IRServoControllerType == null)
{
Expand All @@ -42,54 +50,39 @@ internal static bool InitWrapper()

LogFormatted("IR Version:{0}", IRServoControllerType.Assembly.GetName().Version.ToString());

IRServoMechanismType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IMechanism");
IRServoMechanismType = GetType("InfernalRobotics.Control.IMechanism");

if (IRServoMechanismType == null)
{
LogFormatted("[IR Wrapper] Failed to grab Mechanism Type");
return false;
}

IRServoMotorType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IServoMotor");
IRServoMotorType = GetType("InfernalRobotics.Control.IServoMotor");

if (IRServoMotorType == null)
{
LogFormatted("[IR Wrapper] Failed to grab ServoMotor Type");
return false;
}

IRServoType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IServo");
IRServoType = GetType("InfernalRobotics.Control.IServo");

if (IRServoType == null)
{
LogFormatted("[IR Wrapper] Failed to grab Servo Type");
return false;
}

IRServoPartType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Control.IPart");
IRServoPartType = GetType("InfernalRobotics.Control.IPart");

if (IRServoType == null)
{
LogFormatted("[IR Wrapper] Failed to grab ServoPart Type");
return false;
}

IRControlGroupType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Command.ServoController+ControlGroup");
IRControlGroupType = GetType("InfernalRobotics.Command.ServoController+ControlGroup");

if (IRControlGroupType == null)
{
Expand Down
21 changes: 13 additions & 8 deletions src/kOS/AddOns/KerbalAlarmClock/KACWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public class KACWrapper

public static Boolean NeedUpgrade { get; private set; }

public static Type GetType(string name)
{
Type type = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == name)
type = t;
});
return type;
}

/// <summary>
/// This method will set up the KAC object and wrap all the methods/functions
/// </summary>
Expand All @@ -71,10 +82,7 @@ public static Boolean InitKACWrapper()
LogFormatted("Attempting to Grab KAC Types...");

//find the base type
KACType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "KerbalAlarmClock.KerbalAlarmClock");
KACType = GetType("KerbalAlarmClock.KerbalAlarmClock");

if (KACType == null)
{
Expand All @@ -89,10 +97,7 @@ public static Boolean InitKACWrapper()
}

//now the Alarm Type
KACAlarmType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "KerbalAlarmClock.KACAlarm");
KACAlarmType = GetType("KerbalAlarmClock.KACAlarm");

if (KACAlarmType == null)
{
Expand Down
15 changes: 10 additions & 5 deletions src/kOS/Screen/ToolbarWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,17 @@ internal ToolbarTypes() {
}

internal static Type getType(string name) {
return AssemblyLoader.loadedAssemblies
.SelectMany(a => a.assembly.GetExportedTypes())
.SingleOrDefault(t => t.FullName == name);
}
Type type = null;
AssemblyLoader.loadedAssemblies.TypeOperation(t =>
{
if (t.FullName == name)
type = t;
});
return type;
}


internal static PropertyInfo getProperty(Type type, string name) {
internal static PropertyInfo getProperty(Type type, string name) {
return type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
}

Expand Down

0 comments on commit c5c49ab

Please sign in to comment.