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.

Signals.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Svelto.ECS;
  7. using GamecraftModdingAPI.Utility;
  8. namespace GamecraftModdingAPI.Blocks
  9. {
  10. /// <summary>
  11. /// [EXPERIMENTAL] Common block signal operations
  12. /// </summary>
  13. public static class Signals
  14. {
  15. // Signal constants
  16. public static readonly float HIGH = 1.0f;
  17. public static readonly float POSITIVE_HIGH = HIGH;
  18. public static readonly float NEGATIVE_HIGH = -1.0f;
  19. public static readonly float LOW = 0.0f;
  20. private static SignalEngine signalEngine = new SignalEngine();
  21. /// <summary>
  22. /// Set the electric block's channel to a value
  23. /// </summary>
  24. /// <param name="id">The block's id</param>
  25. /// <param name="channel">The channel (1 to 99)</param>
  26. /// <param name="signal">The signal value (-1 to 1; not enforced)</param>
  27. public static void SetSignalConnectedBlocks(uint id, uint channel, float signal)
  28. {
  29. if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
  30. {
  31. signalEngine.SetSignal(id, channel, signal, out EGID _);
  32. }
  33. }
  34. /// <summary>
  35. /// Set a conductive cluster channel to a value
  36. /// </summary>
  37. /// <param name="clusterID">The channel cluster's id</param>
  38. /// <param name="signal">The signal value (-1 to 1; not enforced)</param>
  39. public static void SetSignalCluster(EGID clusterID, float signal)
  40. {
  41. if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
  42. {
  43. signalEngine.SetSignal(clusterID, signal);
  44. }
  45. }
  46. /// <summary>
  47. /// Add a value to an electric block's channel signal
  48. /// </summary>
  49. /// <param name="id">The block's id</param>
  50. /// <param name="channel">The channel (1 to 99)</param>
  51. /// <param name="signal">The signal value to add</param>
  52. /// <param name="clamp">Whether to clamp the resulting signal value between -1 and 1</param>
  53. public static void AddSignalConnectedBlocks(uint id, uint channel, float signal, bool clamp = true)
  54. {
  55. if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
  56. {
  57. signalEngine.AddSignal(id, channel, signal, out EGID _, clamp);
  58. }
  59. }
  60. /// <summary>
  61. /// Add a value to a conductive cluster channel
  62. /// </summary>
  63. /// <param name="clusterID">The channel cluster's id</param>
  64. /// <param name="signal">The signal value to add</param>
  65. /// <param name="clamp">Whether to clamp the resulting signal value between -1 and 1</param>
  66. public static void AddSignalCluster(EGID clusterID, float signal, bool clamp = true)
  67. {
  68. if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
  69. {
  70. signalEngine.AddSignal(clusterID, signal, clamp);
  71. }
  72. }
  73. /// <summary>
  74. /// Get a electric block's channel's signal value
  75. /// </summary>
  76. /// <param name="id">The block's id</param>
  77. /// <param name="channel">The channel (1 to 99)</param>
  78. /// <returns>The signal value</returns>
  79. public static float GetSignalBlock(uint id, uint channel)
  80. {
  81. if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
  82. {
  83. return signalEngine.GetSignal(id, channel, out EGID _);
  84. }
  85. return 0f;
  86. }
  87. /// <summary>
  88. /// Get a conductive cluster channel's signal value
  89. /// </summary>
  90. /// <param name="clusterID">The channel cluster's id</param>
  91. /// <returns>The signal value</returns>
  92. public static float GetSignalCluster(EGID clusterID)
  93. {
  94. if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
  95. {
  96. return signalEngine.GetSignal(clusterID);
  97. }
  98. return 0f;
  99. }
  100. /// <summary>
  101. /// Get the ID of every electricity consumer in the game world
  102. /// </summary>
  103. /// <returns>The block IDs</returns>
  104. public static uint[] GetElectricBlocks()
  105. {
  106. return signalEngine.GetElectricBlocks();
  107. }
  108. /// <summary>
  109. /// Get the conductive cluster's unique identifier for an electric block
  110. /// </summary>
  111. /// <param name="id">The block's id</param>
  112. /// <param name="channel"></param>
  113. /// <returns>The unique ID</returns>
  114. public static EGID GetClusterID(uint id, uint channel)
  115. {
  116. return signalEngine.GetClusterEGID(id, channel);
  117. }
  118. public static void Init()
  119. {
  120. GameEngineManager.AddGameEngine(signalEngine);
  121. }
  122. }
  123. }