diff --git a/GamecraftModdingAPI/Blocks/Wire.cs b/GamecraftModdingAPI/Blocks/Wire.cs index 6c427f6..c29795f 100644 --- a/GamecraftModdingAPI/Blocks/Wire.cs +++ b/GamecraftModdingAPI/Blocks/Wire.cs @@ -24,6 +24,10 @@ namespace GamecraftModdingAPI.Blocks protected bool inputToOutput; + protected byte startPort; + + protected byte endPort; + public static Wire Connect(SignalingBlock start, byte startPort, SignalingBlock end, byte endPort) { WireEntityStruct wire = signalEngine.CreateNewWire(start.Id, startPort, end.Id, endPort); @@ -90,6 +94,8 @@ namespace GamecraftModdingAPI.Blocks startPortEGID = signalEngine.MatchBlockOutputToPort(start, wire.sourcePortUsage, out exists); if (!exists) throw new WireInvalidException("Wire start port not found"); inputToOutput = false; + endPort = wire.destinationPortUsage; + startPort = wire.sourcePortUsage; } else { @@ -105,6 +111,8 @@ namespace GamecraftModdingAPI.Blocks inputToOutput = true; // end is actually the source // NB: start and end are handled exactly as they're received as params. // This makes wire traversal easier, but makes logic in this class a bit more complex + endPort = wire.sourcePortUsage; + startPort = wire.destinationPortUsage; } else { @@ -142,6 +150,8 @@ namespace GamecraftModdingAPI.Blocks startPortEGID = signalEngine.MatchBlockOutputToPort(start, startPort, out exists); if (!exists) throw new WireInvalidException("Wire start port not found"); } + this.startPort = startPort; + this.endPort = endPort; } /// @@ -159,6 +169,8 @@ namespace GamecraftModdingAPI.Blocks if (!exists) throw new WireInvalidException("Wire end port not found"); startPortEGID = signalEngine.MatchBlockOutputToPort(wire.sourceBlockEGID, wire.sourcePortUsage, out exists); if (!exists) throw new WireInvalidException("Wire start port not found"); + this.endPort = wire.destinationPortUsage; + this.startPort = wire.sourcePortUsage; } internal Wire(WireEntityStruct wire) @@ -171,6 +183,8 @@ namespace GamecraftModdingAPI.Blocks if (!exists) throw new WireInvalidException("Wire end port not found"); startPortEGID = signalEngine.MatchBlockOutputToPort(wire.sourceBlockEGID, wire.sourcePortUsage, out exists); if (!exists) throw new WireInvalidException("Wire start port not found"); + this.endPort = wire.destinationPortUsage; + this.startPort = wire.sourcePortUsage; } /// @@ -275,15 +289,7 @@ namespace GamecraftModdingAPI.Blocks /// public byte StartPort { - get - { - WireEntityStruct wire = signalEngine.GetWire(wireEGID); - if (inputToOutput) - { - return wire.destinationPortUsage; - } - return wire.sourcePortUsage; - } + get => startPort; } /// @@ -299,15 +305,7 @@ namespace GamecraftModdingAPI.Blocks /// public byte EndPort { - get - { - WireEntityStruct wire = signalEngine.GetWire(wireEGID); - if (inputToOutput) - { - return wire.sourcePortUsage; - } - return wire.destinationPortUsage; - } + get => endPort; } /// @@ -322,7 +320,7 @@ namespace GamecraftModdingAPI.Blocks /// /// Convert the wire object to the direction the signal flows. - /// Signals on wires always flows from a block output port to a block input port. + /// Signals on wires always flow from a block output port to a block input port. /// This is simply a different memory configuration and does not affect the in-game wire (which is always output -> input). /// public void OutputToInputInPlace() @@ -337,6 +335,9 @@ namespace GamecraftModdingAPI.Blocks temp = endPortEGID; endPortEGID = startPortEGID; startPortEGID = temp; + byte tempPortNumber = endPort; + endPort = startPort; + startPort = tempPortNumber; } } @@ -346,7 +347,7 @@ namespace GamecraftModdingAPI.Blocks { return $"{nameof(Id)}: {Id}, Start{nameof(Start.Id)}: {Start.Id}, End{nameof(End.Id)}: {End.Id}, ({Start.Type}::{StartPort} aka {Start.PortName(StartPort, inputToOutput)}) -> ({End.Type}::{EndPort} aka {End.PortName(EndPort, !inputToOutput)})"; } - return $"{nameof(Id)}: {Id}, Start{nameof(Start.Id)}: {Start.Id}, End{nameof(End.Id)}: {End.Id}, ({Start.Type} -> {End.Type})"; + return $"{nameof(Id)}: {Id}, Start{nameof(Start.Id)}: {Start.Id}, End{nameof(End.Id)}: {End.Id}, ({Start.Type}::{StartPort} -> {End.Type}::{EndPort})"; } internal static void Init() { }