using System.Collections.Generic;
using Sandbox.ModAPI.Ingame;

namespace IngameScript
{
    partial class Program
    {
        public class BlockActionRotor : BlockAction
        {
            private IMyMotorStator _rotor;
            private float _angle;
            private float _velocity;
            private MyRotationDirection _direction;

            public BlockActionRotor(
                IMyMotorStator rotor,
                float angle,
                float velocity = 5f,
                MyRotationDirection direction = MyRotationDirection.AUTO
            )
            {
                _rotor = rotor;
                _angle = angle;
                _velocity = velocity;
                _direction = direction;
            }

            protected override IEnumerator<bool> onRun()
            {
                _rotor.RotorLock = false;
                _rotor.RotateToAngle(_direction, _angle, _velocity);

                float _lastAngle = -1;
                while (_rotor.Angle != _lastAngle)
                {
                    _lastAngle = _rotor.Angle;
                    yield return true;
                }

                _rotor.RotorLock = true;
            }
        }
    }
}