Browse Source

Fix block tests and add test command to toggle time mode

tags/v2.0.0
NorbiPeti 3 years ago
parent
commit
58d703f502
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
3 changed files with 12 additions and 16 deletions
  1. +4
    -5
      TechbloxModdingAPI/Blocks/BlockTests.cs
  2. +2
    -11
      TechbloxModdingAPI/Blocks/DampedSpring.cs
  3. +6
    -0
      TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs

+ 4
- 5
TechbloxModdingAPI/Blocks/BlockTests.cs View File

@@ -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<DampedSpring>(); }, "Block.Specialize<Servo>() raised an exception: ", "Block.Specialize<DampedSpring>() completed without issue.");
if (!Assert.NotNull(b, "Block.Specialize<DampedSpring>() 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;
}


+ 2
- 11
TechbloxModdingAPI/Blocks/DampedSpring.cs View File

@@ -15,24 +15,15 @@ namespace TechbloxModdingAPI.Blocks
}

/// <summary>
/// The spring's maximum force. This is known as Stiffness in-game
/// The spring frequency.
/// </summary>
public float MaxForce
public float SpringFrequency
{
get => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency;

set => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency = value;
}

/// <summary>
/// Alias of MaxForce.
/// </summary>
public float Stiffness
{
get => MaxForce;
set => MaxForce = value;
}

/// <summary>
/// The spring's maximum damping force.
/// </summary>


+ 6
- 0
TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs View File

@@ -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);


Loading…
Cancel
Save