From aae20579723070aaa2fba9f26e1cdd980bd8c4e5 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 23 Aug 2020 09:59:13 -0400 Subject: [PATCH] Convert relevant blocks to wireable blocks and fix wire connect during block init --- GamecraftModdingAPI/Blocks/ConsoleBlock.cs | 2 +- GamecraftModdingAPI/Blocks/Motor.cs | 2 +- GamecraftModdingAPI/Blocks/MusicBlock.cs | 2 +- GamecraftModdingAPI/Blocks/Piston.cs | 2 +- GamecraftModdingAPI/Blocks/Servo.cs | 2 +- GamecraftModdingAPI/Blocks/TextBlock.cs | 2 +- GamecraftModdingAPI/Blocks/Timer.cs | 2 +- GamecraftModdingAPI/Blocks/Wire.cs | 8 +++--- .../Tests/GamecraftModdingAPIPluginTest.cs | 27 +++++-------------- 9 files changed, 18 insertions(+), 31 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/ConsoleBlock.cs b/GamecraftModdingAPI/Blocks/ConsoleBlock.cs index edf3e76..c8982e4 100644 --- a/GamecraftModdingAPI/Blocks/ConsoleBlock.cs +++ b/GamecraftModdingAPI/Blocks/ConsoleBlock.cs @@ -10,7 +10,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { - public class ConsoleBlock : Block + public class ConsoleBlock : SignalingBlock { public ConsoleBlock(EGID id): base(id) { diff --git a/GamecraftModdingAPI/Blocks/Motor.cs b/GamecraftModdingAPI/Blocks/Motor.cs index fdadd26..3c38a52 100644 --- a/GamecraftModdingAPI/Blocks/Motor.cs +++ b/GamecraftModdingAPI/Blocks/Motor.cs @@ -9,7 +9,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { - public class Motor : Block + public class Motor : SignalingBlock { public Motor(EGID id) : base(id) { diff --git a/GamecraftModdingAPI/Blocks/MusicBlock.cs b/GamecraftModdingAPI/Blocks/MusicBlock.cs index 2128a45..185913b 100644 --- a/GamecraftModdingAPI/Blocks/MusicBlock.cs +++ b/GamecraftModdingAPI/Blocks/MusicBlock.cs @@ -14,7 +14,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { - public class MusicBlock : Block + public class MusicBlock : SignalingBlock { public MusicBlock(EGID id) : base(id) { diff --git a/GamecraftModdingAPI/Blocks/Piston.cs b/GamecraftModdingAPI/Blocks/Piston.cs index aed8c33..c3f2497 100644 --- a/GamecraftModdingAPI/Blocks/Piston.cs +++ b/GamecraftModdingAPI/Blocks/Piston.cs @@ -9,7 +9,7 @@ using RobocraftX.Common; namespace GamecraftModdingAPI.Blocks { - public class Piston : Block + public class Piston : SignalingBlock { public Piston(EGID id) : base(id) { diff --git a/GamecraftModdingAPI/Blocks/Servo.cs b/GamecraftModdingAPI/Blocks/Servo.cs index 730749a..1177fb6 100644 --- a/GamecraftModdingAPI/Blocks/Servo.cs +++ b/GamecraftModdingAPI/Blocks/Servo.cs @@ -9,7 +9,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { - public class Servo : Block + public class Servo : SignalingBlock { public Servo(EGID id) : base(id) { diff --git a/GamecraftModdingAPI/Blocks/TextBlock.cs b/GamecraftModdingAPI/Blocks/TextBlock.cs index 6096dd4..e4b4c73 100644 --- a/GamecraftModdingAPI/Blocks/TextBlock.cs +++ b/GamecraftModdingAPI/Blocks/TextBlock.cs @@ -10,7 +10,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { - public class TextBlock : Block + public class TextBlock : SignalingBlock { public TextBlock(EGID id) : base(id) { diff --git a/GamecraftModdingAPI/Blocks/Timer.cs b/GamecraftModdingAPI/Blocks/Timer.cs index 5766a41..1aeecd9 100644 --- a/GamecraftModdingAPI/Blocks/Timer.cs +++ b/GamecraftModdingAPI/Blocks/Timer.cs @@ -11,7 +11,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { - public class Timer : Block + public class Timer : SignalingBlock { public Timer(EGID id) : base(id) { diff --git a/GamecraftModdingAPI/Blocks/Wire.cs b/GamecraftModdingAPI/Blocks/Wire.cs index c29795f..e58a625 100644 --- a/GamecraftModdingAPI/Blocks/Wire.cs +++ b/GamecraftModdingAPI/Blocks/Wire.cs @@ -31,7 +31,7 @@ namespace GamecraftModdingAPI.Blocks public static Wire Connect(SignalingBlock start, byte startPort, SignalingBlock end, byte endPort) { WireEntityStruct wire = signalEngine.CreateNewWire(start.Id, startPort, end.Id, endPort); - return new Wire(wire); + return new Wire(wire, start, end); } /// @@ -173,15 +173,15 @@ namespace GamecraftModdingAPI.Blocks this.startPort = wire.sourcePortUsage; } - internal Wire(WireEntityStruct wire) + internal Wire(WireEntityStruct wire, SignalingBlock src, SignalingBlock dest) { this.wireEGID = wire.ID; this.startBlockEGID = wire.sourceBlockEGID; this.endBlockEGID = wire.destinationBlockEGID; inputToOutput = false; - endPortEGID = signalEngine.MatchBlockInputToPort(wire.destinationBlockEGID, wire.destinationPortUsage, out bool exists); + endPortEGID = signalEngine.MatchBlockInputToPort(dest, wire.destinationPortUsage, out bool exists); if (!exists) throw new WireInvalidException("Wire end port not found"); - startPortEGID = signalEngine.MatchBlockOutputToPort(wire.sourceBlockEGID, wire.sourcePortUsage, out exists); + startPortEGID = signalEngine.MatchBlockOutputToPort(src, wire.sourcePortUsage, out exists); if (!exists) throw new WireInvalidException("Wire start port not found"); this.endPort = wire.destinationPortUsage; this.startPort = wire.sourcePortUsage; diff --git a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs index 7002605..4a5547f 100644 --- a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs +++ b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs @@ -22,33 +22,29 @@ using GamecraftModdingAPI.Players; namespace GamecraftModdingAPI.Tests { +#if DEBUG // unused by design /// /// Modding API implemented as a standalone IPA Plugin. /// Ideally, GamecraftModdingAPI should be loaded by another mod; not itself /// - public class GamecraftModdingAPIPluginTest -#if DEBUG - : IllusionPlugin.IEnhancedPlugin -#endif + public class GamecraftModdingAPIPluginTest : IllusionPlugin.IEnhancedPlugin { private static Harmony harmony { get; set; } - public string[] Filter { get; } = new string[] { "Gamecraft", "GamecraftPreview" }; + public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; - public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; - - public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi"; - public void OnApplicationQuit() + public override void OnApplicationQuit() { GamecraftModdingAPI.Main.Shutdown(); } - public void OnApplicationStart() + public override void OnApplicationStart() { FileLog.Reset(); Harmony.DEBUG = true; @@ -387,16 +383,6 @@ namespace GamecraftModdingAPI.Tests } } - public void OnFixedUpdate() { } - - public void OnLateUpdate() { } - - public void OnLevelWasInitialized(int level) { } - - public void OnLevelWasLoaded(int level) { } - - public void OnUpdate() { } - [HarmonyPatch] public class MinimumSpecsPatch { @@ -411,4 +397,5 @@ namespace GamecraftModdingAPI.Tests } } } +#endif }