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.

103 lines
2.7KB

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