A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.0KB

  1. using System;
  2. using RobocraftX.Blocks;
  3. using RobocraftX.Common;
  4. using Svelto.ECS;
  5. using Unity.Mathematics;
  6. using GamecraftModdingAPI.Utility;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. public class Motor : Block
  10. {
  11. public Motor(EGID id) : base(id)
  12. {
  13. if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
  14. {
  15. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  16. }
  17. }
  18. public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP))
  19. {
  20. if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
  21. {
  22. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  23. }
  24. }
  25. // custom motor properties
  26. /// <summary>
  27. /// The motor's maximum rotational velocity.
  28. /// </summary>
  29. public float TopSpeed
  30. {
  31. get
  32. {
  33. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxVelocity;
  34. }
  35. set
  36. {
  37. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  38. motor.maxVelocity = value;
  39. }
  40. }
  41. /// <summary>
  42. /// The motor's maximum rotational force.
  43. /// </summary>
  44. public float Torque
  45. {
  46. get
  47. {
  48. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).maxForce;
  49. }
  50. set
  51. {
  52. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  53. motor.maxForce = value;
  54. }
  55. }
  56. /// <summary>
  57. /// The motor's direction.
  58. /// </summary>
  59. public bool Reverse
  60. {
  61. get
  62. {
  63. return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id).reverse;
  64. }
  65. set
  66. {
  67. ref MotorReadOnlyStruct motor = ref BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(Id);
  68. motor.reverse = value;
  69. }
  70. }
  71. }
  72. }