113 lines
3.1 KiB
C#
113 lines
3.1 KiB
C#
using System;
|
|
|
|
using RobocraftX.Blocks;
|
|
using Svelto.ECS;
|
|
using Unity.Mathematics;
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
{
|
|
public class Motor : Block
|
|
{
|
|
/// <summary>
|
|
/// Places a new motor.
|
|
/// Any valid motor type is accepted.
|
|
/// This re-implements Block.PlaceNew(...)
|
|
/// </summary>
|
|
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())
|
|
{
|
|
try
|
|
{
|
|
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
|
|
position, uscale, scale, player, rotation);
|
|
Sync();
|
|
return new Motor(id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logging.MetaDebugLog(e);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
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(id)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|