More idioms.
This commit is contained in:
parent
2227c92377
commit
d2952a3111
|
@ -7,19 +7,19 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
public Door(MyGridProgram p)
|
public Door(MyGridProgram p)
|
||||||
{
|
{
|
||||||
P = p;
|
_p = p;
|
||||||
Hinges = new List<DoorHinge>();
|
_hinges = new List<DoorHinge>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a hinge to the door
|
// Add a hinge to the door
|
||||||
public void AddHinge(IMyMotorStator hinge)
|
public void AddHinge(IMyMotorStator hinge)
|
||||||
{
|
{
|
||||||
Hinges.Add(new DoorHinge(P, hinge));
|
_hinges.Add(new DoorHinge(_p, hinge));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDoor()
|
public void OpenDoor()
|
||||||
{
|
{
|
||||||
foreach (DoorHinge hinge in Hinges)
|
foreach (DoorHinge hinge in _hinges)
|
||||||
{
|
{
|
||||||
hinge.OpenDoorHinge();
|
hinge.OpenDoorHinge();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace IngameScript
|
||||||
|
|
||||||
public void CloseDoor()
|
public void CloseDoor()
|
||||||
{
|
{
|
||||||
foreach (DoorHinge hinge in Hinges)
|
foreach (DoorHinge hinge in _hinges)
|
||||||
{
|
{
|
||||||
hinge.CloseDoorHinge();
|
hinge.CloseDoorHinge();
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace IngameScript
|
||||||
public bool Actuate()
|
public bool Actuate()
|
||||||
{
|
{
|
||||||
bool done = true;
|
bool done = true;
|
||||||
foreach (DoorHinge hinge in Hinges)
|
foreach (DoorHinge hinge in _hinges)
|
||||||
{
|
{
|
||||||
if (!hinge.Actuate()) done = false;
|
if (!hinge.Actuate()) done = false;
|
||||||
}
|
}
|
||||||
|
@ -46,14 +46,14 @@ namespace IngameScript
|
||||||
|
|
||||||
public bool Locked()
|
public bool Locked()
|
||||||
{
|
{
|
||||||
foreach (DoorHinge hinge in Hinges)
|
foreach (DoorHinge hinge in _hinges)
|
||||||
{
|
{
|
||||||
if (!hinge.Locked) return false;
|
if (!hinge.Locked) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MyGridProgram P {get; set; }
|
private MyGridProgram _p;
|
||||||
private List<DoorHinge> Hinges {get; set; }
|
private List<DoorHinge> _hinges;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,8 +8,8 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
public DoorHinge(MyGridProgram p, IMyMotorStator hinge)
|
public DoorHinge(MyGridProgram p, IMyMotorStator hinge)
|
||||||
{
|
{
|
||||||
P = p;
|
_p = p;
|
||||||
Hinge = hinge;
|
_hinge = hinge;
|
||||||
parseConfig();
|
parseConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,16 +17,16 @@ namespace IngameScript
|
||||||
// IMyMotorStator.RotateToAngle() expects degrees...
|
// IMyMotorStator.RotateToAngle() expects degrees...
|
||||||
public void OpenDoorHinge()
|
public void OpenDoorHinge()
|
||||||
{
|
{
|
||||||
Hinge.RotorLock = false;
|
_hinge.RotorLock = false;
|
||||||
TargetAngle = degToRad(OpenAngle);
|
_targetAngle = degToRad(_openAngle);
|
||||||
Hinge.RotateToAngle(MyRotationDirection.AUTO, OpenAngle, Velocity);
|
_hinge.RotateToAngle(MyRotationDirection.AUTO, _openAngle, _velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseDoorHinge()
|
public void CloseDoorHinge()
|
||||||
{
|
{
|
||||||
Hinge.RotorLock = false;
|
_hinge.RotorLock = false;
|
||||||
TargetAngle = degToRad(ClosedAngle);
|
_targetAngle = degToRad(_closedAngle);
|
||||||
Hinge.RotateToAngle(MyRotationDirection.AUTO, ClosedAngle, Velocity);
|
_hinge.RotateToAngle(MyRotationDirection.AUTO, _closedAngle, _velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the hinge's movement.
|
// Process the hinge's movement.
|
||||||
|
@ -34,28 +34,19 @@ namespace IngameScript
|
||||||
// TODO: Add a mechanism to determine when a door gets stuck or can't reach the target angle.
|
// TODO: Add a mechanism to determine when a door gets stuck or can't reach the target angle.
|
||||||
public bool Actuate()
|
public bool Actuate()
|
||||||
{
|
{
|
||||||
if (Math.Abs(Hinge.Angle - TargetAngle) < 0.1 && Hinge.Angle == LastAngle)
|
if (Math.Abs(_hinge.Angle - _targetAngle) < 0.1 && _hinge.Angle == _lastAngle)
|
||||||
{
|
{
|
||||||
Hinge.RotorLock = true;
|
_hinge.RotorLock = true;
|
||||||
}
|
}
|
||||||
LastAngle = Hinge.Angle;
|
_lastAngle = _hinge.Angle;
|
||||||
return Locked;
|
return Locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Locked { get { return _hinge.RotorLock; } }
|
||||||
public bool Locked { get { return Hinge.RotorLock; } }
|
|
||||||
|
|
||||||
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()
|
private void parseConfig()
|
||||||
{
|
{
|
||||||
string[] lines = Hinge.CustomData.Split('\n');
|
string[] lines = _hinge.CustomData.Split('\n');
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
string[] tokens = line.Split('=');
|
string[] tokens = line.Split('=');
|
||||||
|
@ -63,13 +54,13 @@ namespace IngameScript
|
||||||
switch (tokens[0])
|
switch (tokens[0])
|
||||||
{
|
{
|
||||||
case "OpenAngle":
|
case "OpenAngle":
|
||||||
OpenAngle = float.Parse(tokens[1]);
|
_openAngle = float.Parse(tokens[1]);
|
||||||
break;
|
break;
|
||||||
case "ClosedAngle":
|
case "ClosedAngle":
|
||||||
ClosedAngle = float.Parse(tokens[1]);
|
_closedAngle = float.Parse(tokens[1]);
|
||||||
break;
|
break;
|
||||||
case "Velocity":
|
case "Velocity":
|
||||||
Velocity = float.Parse(tokens[1]);
|
_velocity = float.Parse(tokens[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,5 +70,13 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
return degrees * ((float)Math.PI / 180F);
|
return degrees * ((float)Math.PI / 180F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MyGridProgram _p;
|
||||||
|
private IMyMotorStator _hinge;
|
||||||
|
private float _targetAngle;
|
||||||
|
private float _lastAngle;
|
||||||
|
private float _openAngle = 90F;
|
||||||
|
private float _closedAngle = 0F;
|
||||||
|
private float _velocity = 5F;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user