67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using Sandbox.ModAPI.Ingame;
|
|
using System;
|
|
using VRage.Game.ModAPI.Ingame.Utilities;
|
|
|
|
namespace IngameScript
|
|
{
|
|
partial class Program
|
|
{
|
|
public class SequenceableRotor : ISequenceable
|
|
{
|
|
public bool Running { get; private set; } = false;
|
|
public int Step { get; private set; }
|
|
|
|
private float _targetAngle;
|
|
private float _lastAngle;
|
|
|
|
private float _velocity;
|
|
private float _openAngle;
|
|
private float _closedAngle;
|
|
private IMyMotorStator _rotor;
|
|
|
|
public SequenceableRotor(
|
|
IMyMotorStator rotor,
|
|
MyIni ini,
|
|
int defaultStep = 0)
|
|
{
|
|
_rotor = rotor;
|
|
|
|
ini.TryParse(rotor.CustomData);
|
|
_openAngle = ini.Get("sequencer", "openAngle").ToSingle(90F);
|
|
_closedAngle = ini.Get("sequencer", "closedAngle").ToSingle(0F);
|
|
_velocity = ini.Get("sequencer", "velocity").ToSingle(5F);
|
|
Step = ini.Get("sequencer", "step").ToInt32(defaultStep);
|
|
}
|
|
|
|
public void Start(bool reverse)
|
|
{
|
|
float degAngle = reverse ? _closedAngle : _openAngle;
|
|
_targetAngle = degToRad(degAngle);
|
|
_rotor.RotorLock = false;
|
|
_rotor.RotateToAngle(MyRotationDirection.AUTO, degAngle, _velocity);
|
|
Running = true;
|
|
}
|
|
|
|
public bool Check()
|
|
{
|
|
if (Math.Abs(_rotor.Angle - _targetAngle) < 0.1 && _rotor.Angle == _lastAngle)
|
|
{
|
|
return false;
|
|
}
|
|
_lastAngle = _rotor.Angle;
|
|
return true;
|
|
}
|
|
|
|
public void Finish()
|
|
{
|
|
_rotor.RotorLock = true;
|
|
Running = false;
|
|
}
|
|
|
|
private float degToRad(float degrees)
|
|
{
|
|
return degrees * ((float)Math.PI / 180F);
|
|
}
|
|
}
|
|
}
|
|
} |