Start to make code slightly more idiomatic.
This commit is contained in:
parent
13e1f9d63c
commit
2227c92377
|
@ -5,15 +5,16 @@ namespace IngameScript
|
|||
{
|
||||
public class Door
|
||||
{
|
||||
public Door()
|
||||
public Door(MyGridProgram p)
|
||||
{
|
||||
P = p;
|
||||
Hinges = new List<DoorHinge>();
|
||||
}
|
||||
|
||||
// Add a hinge to the door
|
||||
public void AddHinge(IMyMotorStator hinge)
|
||||
{
|
||||
Hinges.Add(new DoorHinge(hinge));
|
||||
Hinges.Add(new DoorHinge(P, hinge));
|
||||
}
|
||||
|
||||
public void OpenDoor()
|
||||
|
@ -47,11 +48,12 @@ namespace IngameScript
|
|||
{
|
||||
foreach (DoorHinge hinge in Hinges)
|
||||
{
|
||||
if (!hinge.Locked()) return false;
|
||||
if (!hinge.Locked) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<DoorHinge> Hinges;
|
||||
private MyGridProgram P {get; set; }
|
||||
private List<DoorHinge> Hinges {get; set; }
|
||||
}
|
||||
}
|
|
@ -6,9 +6,11 @@ namespace IngameScript
|
|||
{
|
||||
public class DoorHinge
|
||||
{
|
||||
public DoorHinge(IMyMotorStator hinge)
|
||||
public DoorHinge(MyGridProgram p, IMyMotorStator hinge)
|
||||
{
|
||||
P = p;
|
||||
Hinge = hinge;
|
||||
parseConfig();
|
||||
}
|
||||
|
||||
// For these two functions, IMyMotorStator.Angle reports radians, but
|
||||
|
@ -16,14 +18,14 @@ namespace IngameScript
|
|||
public void OpenDoorHinge()
|
||||
{
|
||||
Hinge.RotorLock = false;
|
||||
TargetAngle = DegToRad(OpenAngle);
|
||||
TargetAngle = degToRad(OpenAngle);
|
||||
Hinge.RotateToAngle(MyRotationDirection.AUTO, OpenAngle, Velocity);
|
||||
}
|
||||
|
||||
public void CloseDoorHinge()
|
||||
{
|
||||
Hinge.RotorLock = false;
|
||||
TargetAngle = DegToRad(ClosedAngle);
|
||||
TargetAngle = degToRad(ClosedAngle);
|
||||
Hinge.RotateToAngle(MyRotationDirection.AUTO, ClosedAngle, Velocity);
|
||||
}
|
||||
|
||||
|
@ -37,22 +39,21 @@ namespace IngameScript
|
|||
Hinge.RotorLock = true;
|
||||
}
|
||||
LastAngle = Hinge.Angle;
|
||||
return Locked();
|
||||
return Locked;
|
||||
}
|
||||
|
||||
public bool Locked()
|
||||
{
|
||||
return Hinge.RotorLock;
|
||||
}
|
||||
|
||||
private IMyMotorStator Hinge { get; set; }
|
||||
private float TargetAngle { get; set; }
|
||||
private float LastAngle { get; set; }
|
||||
private float OpenAngle { get; set; } = 90F;
|
||||
private float ClosedAngle { get; set; } = 0F;
|
||||
private float Velocity { get; set; } = 5F;
|
||||
public bool Locked { get { return Hinge.RotorLock; } }
|
||||
|
||||
private void ParseConfig()
|
||||
private MyGridProgram P;
|
||||
private IMyMotorStator Hinge;
|
||||
private float TargetAngle;
|
||||
private float LastAngle;
|
||||
private float OpenAngle = 90F;
|
||||
private float ClosedAngle = 0F;
|
||||
private float Velocity = 5F;
|
||||
|
||||
private void parseConfig()
|
||||
{
|
||||
string[] lines = Hinge.CustomData.Split('\n');
|
||||
foreach (string line in lines)
|
||||
|
@ -74,9 +75,7 @@ namespace IngameScript
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: a utility class or function would be lovely...
|
||||
// In general, the encapsulation feels a little screwy here.
|
||||
private float DegToRad(float degrees)
|
||||
private float degToRad(float degrees)
|
||||
{
|
||||
return degrees * ((float)Math.PI / 180F);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace IngameScript
|
|||
string doorName = hinge.CustomName.Split(' ')[0];
|
||||
if (!doors.ContainsKey(doorName))
|
||||
{
|
||||
doors[doorName] = new Door();
|
||||
doors[doorName] = new Door(this);
|
||||
}
|
||||
doors[doorName].AddHinge(hinge);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user