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.

127 lines
3.4KB

  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. try
  22. {
  23. EGID id = PlacementEngine.PlaceBlock(BlockIDs.Timer, color, darkness,
  24. position, uscale, scale, player, rotation);
  25. return new Timer(id);
  26. }
  27. catch (Exception e)
  28. {
  29. Logging.MetaDebugLog(e);
  30. }
  31. }
  32. return null;
  33. }
  34. public Timer(EGID 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. public Timer(uint id) : base(id)
  42. {
  43. if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
  44. {
  45. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  46. }
  47. }
  48. // custom timer properties
  49. /// <summary>
  50. /// The player-specified start time.
  51. /// </summary>
  52. public float Start
  53. {
  54. get
  55. {
  56. return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).startTime;
  57. }
  58. set
  59. {
  60. ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
  61. tbds.startTime = value;
  62. }
  63. }
  64. /// <summary>
  65. /// The player-specified end time.
  66. /// </summary>
  67. public float End
  68. {
  69. get
  70. {
  71. return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).endTime;
  72. }
  73. set
  74. {
  75. ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
  76. tbds.endTime = value;
  77. }
  78. }
  79. /// <summary>
  80. /// Whether to display time with millisecond precision.
  81. /// </summary>
  82. public bool DisplayMilliseconds
  83. {
  84. get
  85. {
  86. return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).outputFormatHasMS;
  87. }
  88. set
  89. {
  90. ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
  91. tbds.outputFormatHasMS = value;
  92. }
  93. }
  94. /// <summary>
  95. /// Current time (as of the last video frame), in milliseconds.
  96. /// </summary>
  97. public int CurrentTime
  98. {
  99. get
  100. {
  101. return BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id).timeLastRenderFrameMS;
  102. }
  103. set
  104. {
  105. ref TimerBlockLabelCacheEntityStruct tblces = ref BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id);
  106. tblces.timeLastRenderFrameMS = value;
  107. }
  108. }
  109. }
  110. }