Fix block tests and add test command to toggle time mode

This commit is contained in:
Norbi Peti 2021-05-17 14:21:55 +02:00
parent db08bf1ac0
commit 58d703f502
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 12 additions and 16 deletions

View file

@ -16,7 +16,7 @@ namespace TechbloxModdingAPI.Blocks
[APITestClass] [APITestClass]
public static class BlockTests 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() public static void TestPlaceNew()
{ {
Block newBlock = Block.PlaceNew(BlockIDs.Cube, Unity.Mathematics.float3.zero); 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); 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 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."); Assert.Errorless(() => { b = (DampedSpring) newBlock; }, "Casting block to DampedSpring raised an exception: ", "Casting block to 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.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.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, 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.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;
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; 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;
} }

View file

@ -15,24 +15,15 @@ namespace TechbloxModdingAPI.Blocks
} }
/// <summary> /// <summary>
/// The spring's maximum force. This is known as Stiffness in-game /// The spring frequency.
/// </summary> /// </summary>
public float MaxForce public float SpringFrequency
{ {
get => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency; get => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency;
set => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency = value; set => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency = value;
} }
/// <summary>
/// Alias of MaxForce.
/// </summary>
public float Stiffness
{
get => MaxForce;
set => MaxForce = value;
}
/// <summary> /// <summary>
/// The spring's maximum damping force. /// The spring's maximum damping force.
/// </summary> /// </summary>

View file

@ -316,6 +316,12 @@ namespace TechbloxModdingAPI.Tests
Block.PlaceNew((BlockIDs) 500, new float3(0, 0, 0))); Block.PlaceNew((BlockIDs) 500, new float3(0, 0, 0)));
}).Build(); }).Build();
CommandBuilder.Builder("toggleTimeMode", "Enters or exits simulation.")
.Action((float x, float y, float z) =>
{
Game.CurrentGame().ToggleTimeMode();
}).Build();
GameClient.SetDebugInfo("InstalledMods", InstalledMods); GameClient.SetDebugInfo("InstalledMods", InstalledMods);
Block.Placed += (sender, args) => Block.Placed += (sender, args) =>
Logging.MetaDebugLog("Placed block " + args.Type + " with ID " + args.ID); Logging.MetaDebugLog("Placed block " + args.Type + " with ID " + args.ID);