Skip to content

Commit

Permalink
Merge pull request #65 from MagicSmokeIndustries/develop
Browse files Browse the repository at this point in the history
0.21.3 changes
  • Loading branch information
ZiwKerman committed Jun 26, 2015
2 parents a519798 + 125fc37 commit b36502f
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 158 deletions.
2 changes: 1 addition & 1 deletion InfernalRobotics.version
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"VERSION": {
"MAJOR": 0,
"MINOR": 21,
"PATCH": 2
"PATCH": 3
},
"KSP_VERSION": {
"MAJOR": 1,
Expand Down
21 changes: 12 additions & 9 deletions InfernalRobotics/InfernalRobotics/API/IRWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ internal static bool InitWrapper()
}

LogFormatted("Got Instance, Creating Wrapper Objects");
IRController = new InfernalRoboticsAPI(ActualServoController);
IRController = new InfernalRoboticsAPI();
isWrapped = true;
return true;
}
Expand All @@ -132,22 +132,24 @@ private class InfernalRoboticsAPI : IRAPI
private PropertyInfo apiReady;
private object actualServoGroups;

public InfernalRoboticsAPI(object irServoController)
public InfernalRoboticsAPI()
{
DetermineReady();
BuildServoGroups(irServoController);
BuildServoGroups();
}

private void BuildServoGroups(object irServoController)
private void BuildServoGroups()
{
LogFormatted("Getting ServoGroups Object");
var servoGroupsField = IRServoControllerType.GetField("ServoGroups");
if (servoGroupsField == null)
LogFormatted("Failed Getting ServoGroups fieldinfo");
else if (IRWrapper.ActualServoController == null)
{
LogFormatted("ServoController Instance not found");
}
else
{
actualServoGroups = servoGroupsField.GetValue(irServoController);
LogFormatted("Success: " + (actualServoGroups != null));
actualServoGroups = servoGroupsField.GetValue(IRWrapper.ActualServoController);
}
}

Expand All @@ -162,7 +164,7 @@ public bool Ready
{
get
{
if (apiReady == null)
if (apiReady == null || actualServoGroups == null)
return false;

return (bool)apiReady.GetValue(null, null);
Expand All @@ -173,6 +175,7 @@ public IList<IControlGroup> ServoGroups
{
get
{
BuildServoGroups ();
return ExtractServoGroups(actualServoGroups);
}
}
Expand All @@ -181,7 +184,7 @@ private IList<IControlGroup> ExtractServoGroups(object servoGroups)
{
var listToReturn = new List<IControlGroup>();

if(servoGroups == null)
if (servoGroups == null)
return listToReturn;

try
Expand Down
17 changes: 16 additions & 1 deletion InfernalRobotics/InfernalRobotics/Command/ServoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ private void Awake()
GameEvents.onPartAttach.Add(OnPartAttach);
GameEvents.onPartRemove.Add(OnPartRemove);
GameEvents.onEditorShipModified.Add(OnEditorShipModified);
GameEvents.onEditorLoad.Add(OnEditorLoad);
GameEvents.onEditorRestart.Add(OnEditorRestart);
ControllerInstance = this;
}
else
Expand All @@ -251,6 +253,18 @@ private void Awake()
Logger.Log("[ServoController] awake finished successfully", Logger.Level.Debug);
}

private void OnEditorRestart()
{
ServoGroups = null;
Logger.Log ("OnEditorRestart called", Logger.Level.Debug);
}

private void OnEditorLoad(ShipConstruct s, CraftBrowser.LoadType t)
{
OnEditorShipModified (s);
Logger.Log ("OnEditorLoad called", Logger.Level.Debug);
}

private void OnVesselWasModified(Vessel v)
{
if (v == FlightGlobals.ActiveVessel)
Expand All @@ -270,7 +284,8 @@ private void OnDestroy()
GameEvents.onPartRemove.Remove(OnPartRemove);
GameEvents.onVesselWasModified.Remove(OnVesselWasModified);
GameEvents.onEditorShipModified.Remove(OnEditorShipModified);

GameEvents.onEditorLoad.Remove(OnEditorLoad);
GameEvents.onEditorRestart.Remove(OnEditorRestart);
Logger.Log("[ServoController] OnDestroy finished successfully", Logger.Level.Debug);
}

Expand Down
3 changes: 3 additions & 0 deletions InfernalRobotics/InfernalRobotics/Command/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public void Init(bool motionLock, IServo servo, Interpolator interpolator)
public bool IsMotionLock { get; set; }
public float GetSpeedUnit()
{
if (servo == null)
return 0f;

return servo.Mechanism.DefaultSpeed;
}

Expand Down
5 changes: 5 additions & 0 deletions InfernalRobotics/InfernalRobotics/Control/IMechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@ public interface IMechanism
/// Used in the editor to reset a parts state to Default
/// </summary>
void Reset();

/// <summary>
/// Used in the editor to apply Servo limits to symmetry counterparts
/// </summary>
void ApplyLimitsToSymmetry();
}
}
15 changes: 15 additions & 0 deletions InfernalRobotics/InfernalRobotics/Control/Servo/MechanismBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,20 @@ public void Reconfigure()
}

public abstract void Reset();

public void ApplyLimitsToSymmetry()
{
foreach (Part counterPart in RawServo.part.symmetryCounterparts)
{
var module = ((MuMechToggle)counterPart.Modules ["MuMechToggle"]);
module.rotateMin = RawServo.rotateMin;
module.rotateMax = RawServo.rotateMax;
module.translateMin = RawServo.translateMin;
module.translateMax = RawServo.translateMax;
module.minTweak = RawServo.minTweak;
module.maxTweak = RawServo.maxTweak;
}
Logger.Log ("ApplyingSymmetry, number of counterparts: " + RawServo.part.symmetryCounterparts.Count, Logger.Level.Debug);
}
}
}
2 changes: 1 addition & 1 deletion InfernalRobotics/InfernalRobotics/Control/Servo/Servo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public string Name
}
public uint UID
{
get {return rawServo.part.flightID; }
get {return rawServo.part.craftID; }
}
public bool Highlight
{
Expand Down
15 changes: 12 additions & 3 deletions InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public void Save(bool symmetry = false)

rawServo.presetPositionsSerialized = rawServo.SerializePresets();

if (symmetry && rawServo.part.symmetryCounterparts.Count > 1)
if (symmetry && rawServo.part.symmetryCounterparts.Count >= 1)
{
foreach (Part part in rawServo.part.symmetryCounterparts)
{
((MuMechToggle)part.Modules["MuMechToggle"]).presetPositionsSerialized = rawServo.presetPositionsSerialized;
((MuMechToggle)part.Modules["MuMechToggle"]).ParsePresetPositions();
var module = ((MuMechToggle)part.Modules ["MuMechToggle"]);
module.presetPositionsSerialized = rawServo.presetPositionsSerialized;
module.ParsePresetPositions();
}
}
}
Expand Down Expand Up @@ -131,6 +132,14 @@ public void GetNearestPresets(out int floor, out int ceiling)
floor = rawServo.PresetPositions.FindLastIndex(p => p < rawServo.Position);
if (floor == -1)
floor = 0;

if(rawServo.invertAxis)
{
//if axis is inverted swap two nearest presets
var tmp = ceiling;
ceiling = floor;
floor = tmp;
}
}

public void RemoveAt(int presetIndex)
Expand Down
Loading

0 comments on commit b36502f

Please sign in to comment.