using System; using Gamecraft.Wires; using Svelto.ECS; using Unity.Mathematics; using GamecraftModdingAPI; using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { /// /// Common implementation for blocks that support wiring. /// public class SignalingBlock : Block { public SignalingBlock(EGID id) : base(id) { if (!BlockEngine.GetBlockInfoExists(this)) { throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); } } public SignalingBlock(uint id) : base(id) { if (!BlockEngine.GetBlockInfoExists(this)) { throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); } } /// /// Generates the input port identifiers. /// /// The input identifiers. protected EGID[] GetInputIds() { return SignalEngine.GetSignalInputs(Id); } /// /// Generates the output port identifiers. /// /// The output identifiers. protected EGID[] GetOutputIds() { return SignalEngine.GetSignalOutputs(Id); } /// /// Gets the connected wire. /// /// The connected wire. /// Port identifier. /// Whether the port has a wire connected to it. protected ref WireEntityStruct GetConnectedWire(EGID portId, out bool connected) { return ref SignalEngine.MatchPortToWire(portId, Id, out connected); } /// /// [EXPERIMENTAL] Gets the channel data. /// /// The channel data. /// Port identifier. /// Whether the channel actually exists. protected ref ChannelDataStruct GetChannelData(EGID portId, out bool exists) { return ref SignalEngine.GetChannelDataStruct(portId, out exists); } /// /// The input port count. /// public uint InputCount { get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.inputCount); } /// /// The output port count. /// public uint OutputCount { get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.outputCount); } } }