From 58d703f502eb5cacadf69eb170b048db37ce322b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 17 May 2021 14:21:55 +0200 Subject: [PATCH] Fix block tests and add test command to toggle time mode --- TechbloxModdingAPI/Blocks/BlockTests.cs | 9 ++++----- TechbloxModdingAPI/Blocks/DampedSpring.cs | 13 ++----------- .../Tests/TechbloxModdingAPIPluginTest.cs | 6 ++++++ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/TechbloxModdingAPI/Blocks/BlockTests.cs b/TechbloxModdingAPI/Blocks/BlockTests.cs index 7a96c27..5cd32d6 100644 --- a/TechbloxModdingAPI/Blocks/BlockTests.cs +++ b/TechbloxModdingAPI/Blocks/BlockTests.cs @@ -16,7 +16,7 @@ namespace TechbloxModdingAPI.Blocks [APITestClass] public static class BlockTests { - [APITestCase(TestType.EditMode)] + [APITestCase(TestType.Game)] //At least one block must be placed for simulation to work public static void TestPlaceNew() { Block newBlock = Block.PlaceNew(BlockIDs.Cube, Unity.Mathematics.float3.zero); @@ -81,10 +81,9 @@ namespace TechbloxModdingAPI.Blocks { Block newBlock = Block.PlaceNew(BlockIDs.DampedSpring, Unity.Mathematics.float3.zero + 1); DampedSpring b = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler - Assert.Errorless(() => { b = newBlock.Specialise(); }, "Block.Specialize() raised an exception: ", "Block.Specialize() completed without issue."); - if (!Assert.NotNull(b, "Block.Specialize() returned null, possibly because it failed silently.", "Specialized DampedSpring is not null.")) return; - if (!Assert.CloseTo(b.Stiffness, 1.0f, $"DampedSpring.Stiffness {b.Stiffness} does not equal default value, possibly because it failed silently.", "DampedSpring.Stiffness is close enough to default.")) return; - if (!Assert.CloseTo(b.Damping, 0.1f, $"DampedSpring.Damping {b.Damping} does not equal default value, possibly because it failed silently.", "DampedSpring.Damping is close enough to default.")) return; + Assert.Errorless(() => { b = (DampedSpring) newBlock; }, "Casting block to DampedSpring raised an exception: ", "Casting block to DampedSpring completed without issue."); + if (!Assert.CloseTo(b.SpringFrequency, 30f, $"DampedSpring.SpringFrequency {b.SpringFrequency} does not equal default value, possibly because it failed silently.", "DampedSpring.SpringFrequency is close enough to default.")) return; + if (!Assert.CloseTo(b.Damping, 30f, $"DampedSpring.Damping {b.Damping} does not equal default value, possibly because it failed silently.", "DampedSpring.Damping is close enough to default.")) return; if (!Assert.CloseTo(b.MaxExtension, 0.3f, $"DampedSpring.MaxExtension {b.MaxExtension} does not equal default value, possibly because it failed silently.", "DampedSpring.MaxExtension is close enough to default.")) return; } diff --git a/TechbloxModdingAPI/Blocks/DampedSpring.cs b/TechbloxModdingAPI/Blocks/DampedSpring.cs index 4623d6d..7009940 100644 --- a/TechbloxModdingAPI/Blocks/DampedSpring.cs +++ b/TechbloxModdingAPI/Blocks/DampedSpring.cs @@ -15,24 +15,15 @@ namespace TechbloxModdingAPI.Blocks } /// - /// The spring's maximum force. This is known as Stiffness in-game + /// The spring frequency. /// - public float MaxForce + public float SpringFrequency { get => BlockEngine.GetBlockInfo(this).springFrequency; set => BlockEngine.GetBlockInfo(this).springFrequency = value; } - /// - /// Alias of MaxForce. - /// - public float Stiffness - { - get => MaxForce; - set => MaxForce = value; - } - /// /// The spring's maximum damping force. /// diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index f794b4d..d9cfedb 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -316,6 +316,12 @@ namespace TechbloxModdingAPI.Tests Block.PlaceNew((BlockIDs) 500, new float3(0, 0, 0))); }).Build(); + CommandBuilder.Builder("toggleTimeMode", "Enters or exits simulation.") + .Action((float x, float y, float z) => + { + Game.CurrentGame().ToggleTimeMode(); + }).Build(); + GameClient.SetDebugInfo("InstalledMods", InstalledMods); Block.Placed += (sender, args) => Logging.MetaDebugLog("Placed block " + args.Type + " with ID " + args.ID);