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.

Timer.cs 3.3KB

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