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.

90 lines
2.6KB

  1. using System;
  2. using Gamecraft.Wires;
  3. using Svelto.ECS;
  4. using Unity.Mathematics;
  5. using GamecraftModdingAPI;
  6. using GamecraftModdingAPI.Utility;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. /// <summary>
  10. /// Common implementation for blocks that support wiring.
  11. /// </summary>
  12. public class SignalingBlock : Block
  13. {
  14. public SignalingBlock(EGID id) : base(id)
  15. {
  16. if (!BlockEngine.GetBlockInfoExists<BlockPortsStruct>(this))
  17. {
  18. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  19. }
  20. }
  21. public SignalingBlock(uint id) : base(id)
  22. {
  23. if (!BlockEngine.GetBlockInfoExists<BlockPortsStruct>(this))
  24. {
  25. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  26. }
  27. }
  28. /// <summary>
  29. /// Generates the input port identifiers.
  30. /// </summary>
  31. /// <returns>The input identifiers.</returns>
  32. protected EGID[] GetInputIds()
  33. {
  34. return SignalEngine.GetSignalInputs(Id);
  35. }
  36. /// <summary>
  37. /// Generates the output port identifiers.
  38. /// </summary>
  39. /// <returns>The output identifiers.</returns>
  40. protected EGID[] GetOutputIds()
  41. {
  42. return SignalEngine.GetSignalOutputs(Id);
  43. }
  44. /// <summary>
  45. /// Gets the connected wire.
  46. /// </summary>
  47. /// <returns>The connected wire.</returns>
  48. /// <param name="portId">Port identifier.</param>
  49. /// <param name="connected">Whether the port has a wire connected to it.</param>
  50. protected ref WireEntityStruct GetConnectedWire(EGID portId, out bool connected)
  51. {
  52. return ref SignalEngine.MatchPortToWire(portId, Id, out connected);
  53. }
  54. /// <summary>
  55. /// [EXPERIMENTAL] Gets the channel data.
  56. /// </summary>
  57. /// <returns>The channel data.</returns>
  58. /// <param name="portId">Port identifier.</param>
  59. /// <param name="exists">Whether the channel actually exists.</param>
  60. protected ref ChannelDataStruct GetChannelData(EGID portId, out bool exists)
  61. {
  62. return ref SignalEngine.GetChannelDataStruct(portId, out exists);
  63. }
  64. /// <summary>
  65. /// The input port count.
  66. /// </summary>
  67. public uint InputCount
  68. {
  69. get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.inputCount);
  70. }
  71. /// <summary>
  72. /// The output port count.
  73. /// </summary>
  74. public uint OutputCount
  75. {
  76. get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.outputCount);
  77. }
  78. }
  79. }