Fix default values getting changed and add test
This commit is contained in:
parent
76faa69c74
commit
74d5a5c6b1
3 changed files with 50 additions and 6 deletions
|
@ -135,6 +135,25 @@ namespace TechbloxModdingAPI.Blocks
|
|||
Assert.Pass("Setting all possible properties of all registered API block types succeeded.");
|
||||
}
|
||||
|
||||
[APITestCase(TestType.EditMode)]
|
||||
public static IEnumerator<TaskContract> TestDefaultValue()
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{ //Tests shared defaults
|
||||
var block = Block.PlaceNew(BlockIDs.Cube, 1);
|
||||
while (!block.Exists)
|
||||
yield return Yield.It;
|
||||
block.Remove();
|
||||
while (block.Exists)
|
||||
yield return Yield.It;
|
||||
if(!Assert.Equal(block.Position, default,
|
||||
$"Block position default value {block.Position} is incorrect, should be 0.",
|
||||
$"Block position default value {block.Position} matches default."))
|
||||
yield break;
|
||||
block.Position = 4;
|
||||
}
|
||||
}
|
||||
|
||||
[APITestCase(TestType.EditMode)]
|
||||
public static void TestDampedSpring()
|
||||
{
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using DataLoader;
|
||||
using TechbloxModdingAPI.App;
|
||||
using HarmonyLib;
|
||||
using IllusionInjector;
|
||||
|
@ -14,12 +11,13 @@ using RobocraftX.FrontEnd;
|
|||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using RobocraftX.Common.Input;
|
||||
using ServiceLayer;
|
||||
using Svelto.Tasks;
|
||||
using Svelto.Tasks.Lean;
|
||||
using TechbloxModdingAPI.Blocks;
|
||||
using TechbloxModdingAPI.Commands;
|
||||
using TechbloxModdingAPI.Input;
|
||||
using TechbloxModdingAPI.Interface.IMGUI;
|
||||
using TechbloxModdingAPI.Players;
|
||||
using TechbloxModdingAPI.Tasks;
|
||||
using TechbloxModdingAPI.Utility;
|
||||
|
||||
namespace TechbloxModdingAPI.Tests
|
||||
|
@ -288,6 +286,32 @@ namespace TechbloxModdingAPI.Tests
|
|||
{
|
||||
Game.CurrentGame().EnableScreenshotTaker();
|
||||
}).Build();
|
||||
|
||||
CommandBuilder.Builder("testPositionDefault", "Tests the Block.Position property's default value.")
|
||||
.Action(() =>
|
||||
{
|
||||
IEnumerator<TaskContract> Loop()
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Console.WriteLine("A");
|
||||
var block = Block.PlaceNew(BlockIDs.Cube, 1);
|
||||
Console.WriteLine("B");
|
||||
while (!block.Exists)
|
||||
yield return Yield.It;
|
||||
Console.WriteLine("C");
|
||||
block.Remove();
|
||||
Console.WriteLine("D");
|
||||
while (block.Exists)
|
||||
yield return Yield.It;
|
||||
Console.WriteLine("E - Pos: " + block.Position);
|
||||
block.Position = 4;
|
||||
Console.WriteLine("F - Pos: " + block.Position);
|
||||
}
|
||||
}
|
||||
|
||||
Loop().RunOn(Scheduler.leanRunner);
|
||||
}).Build();
|
||||
#if TEST
|
||||
TestRoot.RunTests();
|
||||
#endif
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace TechbloxModdingAPI.Utility
|
|||
/// <returns>The value or the default value</returns>
|
||||
public ref T Get()
|
||||
{
|
||||
CompRefCache.Default = default; //The default value can be changed by mods
|
||||
if (state == State.Empty) return ref CompRefCache.Default;
|
||||
if ((state & State.Initializer) != State.Empty) return ref initializer.GetOrCreate<T>();
|
||||
if ((state & State.Native) != State.Empty) return ref array[index];
|
||||
|
@ -73,7 +74,7 @@ namespace TechbloxModdingAPI.Utility
|
|||
/// <summary>
|
||||
/// Creates an instance of a struct T that can be referenced.
|
||||
/// </summary>
|
||||
internal struct CompRefCache
|
||||
private struct CompRefCache
|
||||
{
|
||||
public static T Default;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue