Skip to content

Commit

Permalink
Merge branch 'feature/wheel-is-grounded' (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
djungelorm committed Oct 3, 2016
2 parents 116c6d8 + 732c818 commit cf6c22f
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 53 deletions.
2 changes: 2 additions & 0 deletions doc/order.txt
Expand Up @@ -503,6 +503,7 @@ SpaceCenter.LandingGear.Part
SpaceCenter.LandingGear.State
SpaceCenter.LandingGear.Deployable
SpaceCenter.LandingGear.Deployed
SpaceCenter.LandingGear.IsGrounded
SpaceCenter.LandingGearState
SpaceCenter.LandingGearState.Deployed
SpaceCenter.LandingGearState.Retracted
Expand All @@ -513,6 +514,7 @@ SpaceCenter.LandingLeg
SpaceCenter.LandingLeg.Part
SpaceCenter.LandingLeg.State
SpaceCenter.LandingLeg.Deployed
SpaceCenter.LandingLeg.IsGrounded
SpaceCenter.LandingLegState
SpaceCenter.LandingLegState.Deployed
SpaceCenter.LandingLegState.Retracted
Expand Down
1 change: 1 addition & 0 deletions service/SpaceCenter/CHANGES.txt
@@ -1,6 +1,7 @@
v0.3.7
* Add custom reference frames (ReferenceFrame.CreateRelative and CreateHybrid) (#252)
* Add Vessel.BoundingBox and Part.BoundingBox (#352)
* Add LandingGear.IsGrounded and LandingLeg.IsGrounded (#352)

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
25 changes: 14 additions & 11 deletions service/SpaceCenter/src/Services/Parts/LandingGear.cs
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using KRPC.Service.Attributes;
using KRPC.SpaceCenter.ExtensionMethods;
Expand All @@ -10,8 +11,10 @@ namespace KRPC.SpaceCenter.Services.Parts
/// Landing gear with wheels. Obtained by calling <see cref="Part.LandingGear"/>.
/// </summary>
[KRPCClass (Service = "SpaceCenter")]
[SuppressMessage ("Gendarme.Rules.Maintainability", "AvoidLackOfCohesionOfMethodsRule")]
public class LandingGear : Equatable<LandingGear>
{
readonly ModuleWheelBase wheel;
readonly ModuleWheels.ModuleWheelDeployment deployment;
readonly ModuleWheels.ModuleWheelDamage damage;

Expand All @@ -30,6 +33,7 @@ internal LandingGear (Part part)
throw new ArgumentException ("Part is not landing gear");
Part = part;
var internalPart = part.InternalPart;
wheel = internalPart.Module<ModuleWheelBase> ();
deployment = internalPart.Module<ModuleWheels.ModuleWheelDeployment> ();
damage = internalPart.Module<ModuleWheels.ModuleWheelDamage> ();
}
Expand All @@ -39,24 +43,15 @@ internal LandingGear (Part part)
/// </summary>
public override bool Equals (LandingGear other)
{
return
!ReferenceEquals (other, null) &&
Part == other.Part &&
(deployment == other.deployment || deployment.Equals (other.deployment)) &&
(damage == other.damage || damage.Equals (other.damage));
return !ReferenceEquals (other, null) && Part == other.Part && wheel == other.wheel;
}

/// <summary>
/// Hash code for the object.
/// </summary>
public override int GetHashCode ()
{
var hash = Part.GetHashCode ();
if (deployment != null)
hash ^= deployment.GetHashCode ();
if (damage != null)
hash ^= damage.GetHashCode ();
return hash;
return Part.GetHashCode () ^ wheel.GetHashCode ();
}

/// <summary>
Expand Down Expand Up @@ -123,5 +118,13 @@ public override int GetHashCode ()
}
}
}

/// <summary>
/// Returns whether the gear is touching the ground.
/// </summary>
[KRPCProperty]
public bool IsGrounded {
get { return wheel.isGrounded; }
}
}
}
25 changes: 14 additions & 11 deletions service/SpaceCenter/src/Services/Parts/LandingLeg.cs
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using KRPC.Service.Attributes;
using KRPC.SpaceCenter.ExtensionMethods;
Expand All @@ -10,8 +11,10 @@ namespace KRPC.SpaceCenter.Services.Parts
/// A landing leg. Obtained by calling <see cref="Part.LandingLeg"/>.
/// </summary>
[KRPCClass (Service = "SpaceCenter")]
[SuppressMessage ("Gendarme.Rules.Maintainability", "AvoidLackOfCohesionOfMethodsRule")]
public class LandingLeg : Equatable<LandingLeg>
{
readonly ModuleWheelBase wheel;
readonly ModuleWheels.ModuleWheelDeployment deployment;
readonly ModuleWheels.ModuleWheelDamage damage;

Expand All @@ -29,6 +32,7 @@ internal LandingLeg (Part part)
throw new ArgumentException ("Part is not a landing leg");
Part = part;
var internalPart = part.InternalPart;
wheel = internalPart.Module<ModuleWheelBase> ();
deployment = internalPart.Module<ModuleWheels.ModuleWheelDeployment> ();
damage = internalPart.Module<ModuleWheels.ModuleWheelDamage> ();
}
Expand All @@ -38,24 +42,15 @@ internal LandingLeg (Part part)
/// </summary>
public override bool Equals (LandingLeg other)
{
return
!ReferenceEquals (other, null) &&
Part == other.Part &&
(deployment == other.deployment || deployment.Equals (other.deployment)) &&
(damage == other.damage || damage.Equals (other.damage));
return !ReferenceEquals (other, null) && Part == other.Part && wheel == other.wheel;
}

/// <summary>
/// Hash code for the object.
/// </summary>
public override int GetHashCode ()
{
var hash = Part.GetHashCode ();
if (deployment != null)
hash ^= deployment.GetHashCode ();
if (damage != null)
hash ^= damage.GetHashCode ();
return hash;
return Part.GetHashCode () ^ wheel.GetHashCode ();
}

/// <summary>
Expand Down Expand Up @@ -111,5 +106,13 @@ public override int GetHashCode ()
}
}
}

/// <summary>
/// Returns whether the leg is touching the ground.
/// </summary>
[KRPCProperty]
public bool IsGrounded {
get { return wheel.isGrounded; }
}
}
}
108 changes: 87 additions & 21 deletions service/SpaceCenter/test/craft/PartsLandingGear.craft 100644 → 100755
@@ -1,17 +1,17 @@
ship = PartsLandingGear
version = 1.1.2
version = 1.1.3
description =
type = VAB
size = 5.960213,8.134697,4.771303
size = 7.075258,5.934353,4.556495
PART
{
part = mk1pod_4294695196
partName = Part
pos = -0.2674481,5.573801,0.2688498
pos = -1.497117,3.409686,0.9664501
attPos = 0,0,0
attPos0 = -0.2674481,5.573801,0.2688498
rot = 0,0,0,1
attRot = 0,0,0,1
attPos0 = -1.497117,3.409686,0.9664501
rot = -0.7071068,0,0,0.7071068
attRot = -0.7071067,0,0,0.7071067
attRot0 = 0,0,0,1
mir = 1,1,1
symMethod = Radial
Expand All @@ -25,6 +25,7 @@ PART
modMass = 0
modSize = (0.0, 0.0, 0.0)
link = Mk1FuselageStructural_4294688548
link = trussPiece3x_4294460352
attN = bottom,Mk1FuselageStructural_4294688548
EVENTS
{
Expand Down Expand Up @@ -473,10 +474,10 @@ PART
{
part = Mk1FuselageStructural_4294688548
partName = Part
pos = -0.2674481,4.231263,0.2688498
pos = -1.497117,3.409685,2.308989
attPos = 0,0,0
attPos0 = 0,-1.342538,0
rot = 0,0,0,1
rot = -0.7071068,0,0,0.7071068
attRot = 0,0,0,1
attRot0 = 0,0,0,1
mir = 1,1,1
Expand All @@ -493,6 +494,7 @@ PART
link = launchClamp1_4294687422
link = GearFixed_4294679342
link = GearLarge_4294678130
link = trussPiece3x_4294416072
attN = top,mk1pod_4294695196
EVENTS
{
Expand All @@ -508,10 +510,10 @@ PART
{
part = launchClamp1_4294687422
partName = Part
pos = -1.685465,2.530511,0.2688499
pos = -2.915133,3.409685,4.009749
attPos = 0,0,0
attPos0 = -1.418016,-1.700752,1.326165E-07
rot = 0,0.7071068,0,0.7071068
rot = -0.5000001,0.5000001,-0.5000001,0.5000001
attRot = 0,0,0,1
attRot0 = 0,0.7071068,0,0.7071068
mir = 1,1,1
Expand Down Expand Up @@ -539,10 +541,10 @@ PART
{
name = LaunchClamp
isEnabled = True
scaleFactor = 1.264531
height = 3.190662
scaleFactor = 1.113044
height = 2.80843
stagingEnabled = True
towerRot = 0,-0.7071068,0,0.7071068
towerRot = 0.5,-0.5,0.5,0.5
EVENTS
{
Release
Expand Down Expand Up @@ -681,13 +683,13 @@ PART
{
part = GearFixed_4294679342
partName = Part
pos = -0.8059824,4.718889,-0.04207319
pos = -2.035651,3.098762,1.821363
attPos = 0,0,0
attPos0 = -0.5385343,0.4876261,-0.310923
rot = 0.6792079,0.1840266,0.1819932,-0.6867965
rot = 0.965911,0.2588152,-0.001437813,-0.005365878
attRot = 0,0,0,1
attRot0 = 0.6792079,0.1840266,0.1819932,-0.6867965
mir = 1,1,1
mir = 1,1,-1
symMethod = Radial
istg = 0
dstg = 0
Expand Down Expand Up @@ -881,14 +883,14 @@ PART
{
part = GearLarge_4294678130
partName = Part
pos = 0.03907868,3.45117,-0.2620699
pos = -0.9645057,3.102181,2.560117
attPos = 0,0,0
attPos0 = 0.3065267,-0.7800932,-0.5309197
rot = -0.1830128,0.6830127,0.6830127,0.1830128
attPos0 = 0.5326113,-0.2511252,-0.3075035
rot = 0.5,-0.8660255,2.384186E-07,-4.470348E-08
attRot = 0,0,0,1
attRot0 = -0.1830128,0.6830127,0.6830127,0.1830128
attRot0 = 0.3535534,-0.6123726,-0.6123723,-0.3535534
mir = 1,1,1
symMethod = Radial
symMethod = Mirror
istg = 0
dstg = 0
sidx = -1
Expand Down Expand Up @@ -1316,3 +1318,67 @@ PART
}
}
}
PART
{
part = trussPiece3x_4294460352
partName = Part
pos = -2.851487,2.055315,0.5068422
attPos = 0,0,0
attPos0 = -1.35437,0.4596078,-1.354371
rot = 0.06965673,0.1681662,-0.9084458,-0.3762905
attRot = 0,0,0,1
attRot0 = -0.2168228,0.7612796,-0.5234567,-0.3153323
mir = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sidx = -1
sqor = -1
sepI = 0
attm = 1
modCost = 0
modMass = 0
modSize = (0.0, 0.0, 0.0)
srfN = srfAttach,mk1pod_4294695196
EVENTS
{
}
ACTIONS
{
}
PARTDATA
{
}
}
PART
{
part = trussPiece3x_4294416072
partName = Part
pos = -2.904337,2.002455,3.423178
attPos = 0,0,0
attPos0 = -1.40722,-1.114186,-1.407229
rot = -0.06645189,-0.1604301,-0.9098448,-0.3768675
attRot = 0.1736482,-6.462743E-10,3.665203E-09,0.9848078
attRot0 = -0.3134742,0.5299161,-0.7567986,-0.2194971
mir = 1,1,1
symMethod = Radial
istg = 0
dstg = 0
sidx = -1
sqor = -1
sepI = 0
attm = 1
modCost = 0
modMass = 0
modSize = (0.0, 0.0, 0.0)
srfN = srfAttach,Mk1FuselageStructural_4294688548
EVENTS
{
}
ACTIONS
{
}
PARTDATA
{
}
}
25 changes: 15 additions & 10 deletions service/SpaceCenter/test/test_parts_landing_gear.py
Expand Up @@ -3,16 +3,14 @@

class TestPartsLandingGear(krpctest.TestCase):

@classmethod
def setUpClass(cls):
cls.new_save()
if cls.connect().space_center.active_vessel.name != 'PartsLandingGear':
cls.launch_vessel_from_vab('PartsLandingGear')
cls.remove_other_vessels()
parts = cls.connect().space_center.active_vessel.parts
cls.gear = parts.with_title('LY-99 Extra Large Landing Gear')[0].landing_gear
cls.fixed_gear = parts.with_title('LY-01 Fixed Landing Gear')[0].landing_gear
cls.State = cls.connect().space_center.LandingGearState
def setUp(self):
self.new_save()
self.launch_vessel_from_vab('PartsLandingGear')
self.remove_other_vessels()
self.parts = self.connect().space_center.active_vessel.parts
self.gear = self.parts.with_title('LY-99 Extra Large Landing Gear')[0].landing_gear
self.fixed_gear = self.parts.with_title('LY-01 Fixed Landing Gear')[0].landing_gear
self.State = self.connect().space_center.LandingGearState

def test_deploy_and_retract(self):
self.assertTrue(self.gear.deployable)
Expand Down Expand Up @@ -40,5 +38,12 @@ def test_fixed_gear(self):
self.assertEqual(self.State.deployed, self.fixed_gear.state)
self.assertTrue(self.fixed_gear.deployed)

def test_grounded(self):
self.assertTrue(self.gear.deployed)
self.assertFalse(self.gear.is_grounded)
self.parts.launch_clamps[0].release()
self.wait(1)
self.assertTrue(self.gear.is_grounded)

if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions service/SpaceCenter/test/test_parts_landing_leg.py
Expand Up @@ -31,6 +31,7 @@ def test_deploy_and_retract(self):
self.wait()
self.assertEqual(self.State.retracted, self.leg.state)
self.assertFalse(self.leg.deployed)
self.assertFalse(self.leg.is_grounded)

if __name__ == '__main__':
unittest.main()

0 comments on commit cf6c22f

Please sign in to comment.