2020-05-21 19:04:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using RobocraftX.Blocks;
|
2020-07-10 22:30:58 +00:00
|
|
|
|
using RobocraftX.Common;
|
2020-05-21 19:04:55 +00:00
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
|
{
|
|
|
|
|
public class Servo : Block
|
|
|
|
|
{
|
|
|
|
|
public Servo(EGID id) : base(id)
|
|
|
|
|
{
|
|
|
|
|
if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
|
|
|
|
|
{
|
|
|
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP))
|
2020-05-21 19:04:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
|
|
|
|
|
{
|
|
|
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// custom servo properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The servo's minimum angle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float MinimumAngle
|
|
|
|
|
{
|
|
|
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).minDeviation;
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
|
|
|
servo.minDeviation = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The servo's maximum angle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float MaximumAngle
|
|
|
|
|
{
|
|
|
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxDeviation;
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
|
|
|
servo.maxDeviation = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The servo's maximum force.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float MaximumForce
|
|
|
|
|
{
|
|
|
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxForce;
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
|
|
|
servo.maxForce = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The servo's direction.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Reverse
|
|
|
|
|
{
|
|
|
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).reverse;
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
|
|
|
servo.reverse = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|