NorbiPeti
f403feb298
Removed BlockIdentifiers.OWNED_BLOCKS as the original got replaced with an array Added the correct group for each supported functional block Removed EntityFactory property from IEntitySerializer as it is provided on deserialization
106 lines
3 KiB
C#
106 lines
3 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
|
|
{
|
|
/// <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())
|
|
{
|
|
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<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;
|
|
}
|
|
}
|
|
}
|
|
}
|