diff --git a/TechbloxModdingAPI/Blocks/BlockTests.cs b/TechbloxModdingAPI/Blocks/BlockTests.cs index 536a819..f920631 100644 --- a/TechbloxModdingAPI/Blocks/BlockTests.cs +++ b/TechbloxModdingAPI/Blocks/BlockTests.cs @@ -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 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() { diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index 222331f..b98990b 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -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 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 diff --git a/TechbloxModdingAPI/Utility/OptionalRef.cs b/TechbloxModdingAPI/Utility/OptionalRef.cs index 8bcbe28..2410f1b 100644 --- a/TechbloxModdingAPI/Utility/OptionalRef.cs +++ b/TechbloxModdingAPI/Utility/OptionalRef.cs @@ -58,6 +58,7 @@ namespace TechbloxModdingAPI.Utility /// The value or the default value 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(); if ((state & State.Native) != State.Empty) return ref array[index]; @@ -73,7 +74,7 @@ namespace TechbloxModdingAPI.Utility /// /// Creates an instance of a struct T that can be referenced. /// - internal struct CompRefCache + private struct CompRefCache { public static T Default; }