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.

119 lines
3.2KB

  1. using System;
  2. using RobocraftX.Blocks;
  3. using Gamecraft.Blocks.TimerBlock;
  4. using Svelto.ECS;
  5. using Unity.Mathematics;
  6. using GamecraftModdingAPI;
  7. using GamecraftModdingAPI.Utility;
  8. namespace GamecraftModdingAPI.Blocks
  9. {
  10. public class Timer : Block
  11. {
  12. /// <summary>
  13. /// Places a new timer block.
  14. /// </summary>
  15. public static Timer PlaceNew(float3 position,
  16. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  17. int uscale = 1, float3 scale = default, Player player = null)
  18. {
  19. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  20. {
  21. EGID id = PlacementEngine.PlaceBlock(BlockIDs.Timer, color, darkness,
  22. position, uscale, scale, player, rotation);
  23. return new Timer(id);
  24. }
  25. return null;
  26. }
  27. public Timer(EGID id) : base(id)
  28. {
  29. if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
  30. {
  31. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  32. }
  33. }
  34. public Timer(uint id) : base(id)
  35. {
  36. if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
  37. {
  38. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  39. }
  40. }
  41. // custom timer properties
  42. /// <summary>
  43. /// The player-specified start time.
  44. /// </summary>
  45. public float Start
  46. {
  47. get
  48. {
  49. return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).startTime;
  50. }
  51. set
  52. {
  53. ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
  54. tbds.startTime = value;
  55. }
  56. }
  57. /// <summary>
  58. /// The player-specified end time.
  59. /// </summary>
  60. public float End
  61. {
  62. get
  63. {
  64. return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).endTime;
  65. }
  66. set
  67. {
  68. ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
  69. tbds.endTime = value;
  70. }
  71. }
  72. /// <summary>
  73. /// Whether to display time with millisecond precision.
  74. /// </summary>
  75. public bool DisplayMilliseconds
  76. {
  77. get
  78. {
  79. return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).outputFormatHasMS;
  80. }
  81. set
  82. {
  83. ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
  84. tbds.outputFormatHasMS = value;
  85. }
  86. }
  87. /// <summary>
  88. /// Current time (as of the last video frame), in milliseconds.
  89. /// </summary>
  90. public int CurrentTime
  91. {
  92. get
  93. {
  94. return BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id).timeLastRenderFrameMS;
  95. }
  96. set
  97. {
  98. ref TimerBlockLabelCacheEntityStruct tblces = ref BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id);
  99. tblces.timeLastRenderFrameMS = value;
  100. }
  101. }
  102. }
  103. }