NorbiPeti
89d32956d9
And store delegates of dynamic methods invoking constructors Tested with the automated tests
83 lines
2 KiB
C#
83 lines
2 KiB
C#
using System;
|
|
|
|
using RobocraftX.Blocks;
|
|
using RobocraftX.Common;
|
|
using Svelto.ECS;
|
|
using Unity.Mathematics;
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
{
|
|
public class Motor : Block
|
|
{
|
|
public Motor(EGID id) : base(id)
|
|
{
|
|
if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
|
|
{
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
}
|
|
}
|
|
|
|
public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP))
|
|
{
|
|
if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
|
|
{
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
}
|
|
}
|
|
|
|
// custom motor properties
|
|
|
|
/// <summary>
|
|
/// The motor's maximum rotational velocity.
|
|
/// </summary>
|
|
public float TopSpeed
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxVelocity;
|
|
}
|
|
|
|
set
|
|
{
|
|
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
|
|
motor.maxVelocity = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The motor's maximum rotational force.
|
|
/// </summary>
|
|
public float Torque
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxForce;
|
|
}
|
|
|
|
set
|
|
{
|
|
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
|
|
motor.maxForce = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The motor's direction.
|
|
/// </summary>
|
|
public bool Reverse
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).reverse;
|
|
}
|
|
|
|
set
|
|
{
|
|
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
|
|
motor.reverse = value;
|
|
}
|
|
}
|
|
}
|
|
}
|