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.

89 lines
2.3KB

  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 Servo : Block
  10. {
  11. public Servo(EGID id) : base(id)
  12. {
  13. if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
  14. {
  15. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  16. }
  17. }
  18. public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP))
  19. {
  20. if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
  21. {
  22. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  23. }
  24. }
  25. // custom servo properties
  26. /// <summary>
  27. /// The servo's minimum angle.
  28. /// </summary>
  29. public float MinimumAngle
  30. {
  31. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).minDeviation;
  32. set
  33. {
  34. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  35. servo.minDeviation = value;
  36. }
  37. }
  38. /// <summary>
  39. /// The servo's maximum angle.
  40. /// </summary>
  41. public float MaximumAngle
  42. {
  43. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxDeviation;
  44. set
  45. {
  46. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  47. servo.maxDeviation = value;
  48. }
  49. }
  50. /// <summary>
  51. /// The servo's maximum force.
  52. /// </summary>
  53. public float MaximumForce
  54. {
  55. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxForce;
  56. set
  57. {
  58. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  59. servo.maxForce = value;
  60. }
  61. }
  62. /// <summary>
  63. /// The servo's direction.
  64. /// </summary>
  65. public bool Reverse
  66. {
  67. get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).reverse;
  68. set
  69. {
  70. ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
  71. servo.reverse = value;
  72. }
  73. }
  74. }
  75. }