using System;
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class Motor : Block
{
///
/// Places a new motor.
/// Any valid motor type is accepted.
/// This re-implements Block.PlaceNew(...)
///
public static new Motor PlaceNew(BlockIDs block, float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (!(block == BlockIDs.MotorS || block == BlockIDs.MotorM))
{
throw new BlockTypeException($"Block is not a {typeof(Motor).Name} block");
}
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
position, uscale, scale, player, rotation);
return new Motor(id);
}
return null;
}
public Motor(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists(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(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom motor properties
///
/// The motor's maximum rotational velocity.
///
public float TopSpeed
{
get
{
return BlockEngine.GetBlockInfo(Id).maxVelocity;
}
set
{
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo(Id);
motor.maxVelocity = value;
}
}
///
/// The motor's maximum rotational force.
///
public float Torque
{
get
{
return BlockEngine.GetBlockInfo(Id).maxForce;
}
set
{
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo(Id);
motor.maxForce = value;
}
}
///
/// The motor's direction.
///
public bool Reverse
{
get
{
return BlockEngine.GetBlockInfo(Id).reverse;
}
set
{
ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo(Id);
motor.reverse = value;
}
}
}
}