Bläddra i källkod

Test fixes, block event Block property

Fixed Assert.Equal()
Changed tests to reflect changes
Added Block property to the block event args
Completely removed sync things
tags/v1.4.0
NorbiPeti NGnius (Graham) <ngniusness@gmail.com> 3 år sedan
förälder
incheckning
5264d98ce7
9 ändrade filer med 12 tillägg och 91 borttagningar
  1. +2
    -2
      GamecraftModdingAPI/Block.cs
  2. +0
    -2
      GamecraftModdingAPI/Blocks/BlockEngine.cs
  3. +3
    -34
      GamecraftModdingAPI/Blocks/BlockEventsEngine.cs
  4. +3
    -3
      GamecraftModdingAPI/Blocks/BlockTests.cs
  5. +0
    -1
      GamecraftModdingAPI/Blocks/PlacementEngine.cs
  6. +1
    -1
      GamecraftModdingAPI/SimBody.cs
  7. +2
    -22
      GamecraftModdingAPI/Tests/Assert.cs
  8. +1
    -1
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
  9. +0
    -25
      GamecraftModdingAPI/Utility/DeterministicStepCompositionRootPatch.cs

+ 2
- 2
GamecraftModdingAPI/Block.cs Visa fil

@@ -342,10 +342,10 @@ namespace GamecraftModdingAPI
public bool Remove() => RemovalEngine.RemoveBlock(Id);

/// <summary>
/// Returns the rigid body of the cluster of blocks this one belongs to during simulation.
/// Returns the rigid body of the chunk of blocks this one belongs to during simulation.
/// Can be used to apply forces or move the block around while the simulation is running.
/// </summary>
/// <returns>The SimBody of the cluster or null if the block doesn't exist.</returns>
/// <returns>The SimBody of the chunk or null if the block doesn't exist.</returns>
public SimBody GetSimBody()
{
return BlockEngine.GetBlockInfo(this,


+ 0
- 2
GamecraftModdingAPI/Blocks/BlockEngine.cs Visa fil

@@ -25,8 +25,6 @@ namespace GamecraftModdingAPI.Blocks

public bool isRemovable => false;

internal bool Synced = true;

public void Dispose()
{
}


+ 3
- 34
GamecraftModdingAPI/Blocks/BlockEventsEngine.cs Visa fil

@@ -13,14 +13,8 @@ namespace GamecraftModdingAPI.Blocks
public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
public event EventHandler<BlockPlacedRemovedEventArgs> Removed;

public BlockEventsEngine()
{
//Console.WriteLine("Creating BlockEventsEngine\n" + Environment.StackTrace);
}

public void Ready()
{
//Console.WriteLine("BlockEventsEngine registered");
}

public EntitiesDB entitiesDB { get; set; }
@@ -50,37 +44,12 @@ namespace GamecraftModdingAPI.Blocks
}
}

/*[HarmonyPatch]
public static class TestPatch
{
public static void Postfix(FasterDictionary<RefWrapper<Type>, FasterList<IEngine>> engines,
ExclusiveGroupStruct? previousGroup, in PlatformProfiler profiler, EGID egid)
{
if (!engines.TryGetValue(new RefWrapper<Type>(TypeSafeDictionary<TValue>._type), out result))
return;
}
public static MethodBase TargetMethod()
{
return AccessTools.Method("Svelto.ECS.Internal.TypeSafeDictionary:AddEntityComponentToEngines");
}
}*/
/*[HarmonyPatch]
public static class TestPatch
{
public static void Postfix(EGID basePartEGID)
{
Console.WriteLine("Patched Add method: " + basePartEGID);
}
public static MethodBase TargetMethod()
{
return AccessTools.Method("RobocraftX.CR.MachineEditing.BuildBlockAdditionalPartEngine:Add");
}
}*/

public struct BlockPlacedRemovedEventArgs
{
public EGID ID;
public BlockIDs Type;
private Block block;

public Block Block => block ?? (block = new Block(ID));
}
}

+ 3
- 3
GamecraftModdingAPI/Blocks/BlockTests.cs Visa fil

@@ -22,11 +22,11 @@ namespace GamecraftModdingAPI.Blocks
}

[APITestCase(TestType.EditMode)]
public static void TestSync()
public static void TestInitProperty()
{
Block newBlock = Block.PlaceNew(BlockIDs.AluminiumCube, Unity.Mathematics.float3.zero + 2);
if (!Assert.CloseTo(newBlock.Position, (Unity.Mathematics.float3.zero + 2), $"Newly placed block at {newBlock.Position} is expected at {Unity.Mathematics.float3.zero + 2}.", "Newly placed block position matches.")) return;
Assert.Equal(newBlock.Exists, true, "Newly placed block does not exist, possibly because Sync() skipped/missed/failed.", "Newly placed block exists, Sync() successful.");
//Assert.Equal(newBlock.Exists, true, "Newly placed block does not exist, possibly because Sync() skipped/missed/failed.", "Newly placed block exists, Sync() successful.");
}

[APITestCase(TestType.EditMode)]
@@ -34,7 +34,7 @@ namespace GamecraftModdingAPI.Blocks
{
TextBlock textBlock = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { textBlock = Block.PlaceNew<TextBlock>(BlockIDs.TextBlock, Unity.Mathematics.float3.zero + 1); }, "Block.PlaceNew<TextBlock>() raised an exception: ", "Block.PlaceNew<TextBlock>() completed without issue.");
if (!Assert.NotNull(textBlock, "Block.Specialize<TextBlock>() returned null, possibly because it failed silently.", "Specialized TextBlock is not null.")) return;
if (!Assert.NotNull(textBlock, "Block.PlaceNew<TextBlock>() returned null, possibly because it failed silently.", "Specialized TextBlock is not null.")) return;
if (!Assert.NotNull(textBlock.Text, "TextBlock.Text is null, possibly because it failed silently.", "TextBlock.Text is not null.")) return;
if (!Assert.NotNull(textBlock.TextBlockId, "TextBlock.TextBlockId is null, possibly because it failed silently.", "TextBlock.TextBlockId is not null.")) return;
}


+ 0
- 1
GamecraftModdingAPI/Blocks/PlacementEngine.cs Visa fil

@@ -107,7 +107,6 @@ namespace GamecraftModdingAPI.Blocks
ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity<PickedBlockExtraDataStruct>(playerEGID);
pickedBlock.placedBlockEntityID = structInitializer.EGID;
pickedBlock.placedBlockWasAPickedBlock = false;
Block.BlockEngine.Synced = false; // Block entities will need to be submitted before properties can be used
return structInitializer;
}



+ 1
- 1
GamecraftModdingAPI/SimBody.cs Visa fil

@@ -9,7 +9,7 @@ using RobocraftX.Physics;
namespace GamecraftModdingAPI
{
/// <summary>
/// A rigid body (like a cluster of connected blocks) during simulation.
/// A rigid body (like a chunk of connected blocks) during simulation.
/// </summary>
public class SimBody : IEquatable<SimBody>, IEquatable<EGID>
{


+ 2
- 22
GamecraftModdingAPI/Tests/Assert.cs Visa fil

@@ -83,32 +83,12 @@ namespace GamecraftModdingAPI.Tests
{
if (err == null) err = $"{nameof(T)} '{obj1}' is not equal to '{obj2}'.";
if (success == null) success = $"{nameof(T)} '{obj1}' is equal to '{obj2}'.";
if (obj1 == null && obj2 == null)
if ((obj1 == null && obj2 == null)
|| (obj1 != null && obj2 != null && obj1.Equals(obj2) && obj2.Equals(obj1)))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else if (!(obj1 == null && obj2 == null) && obj1.Equals(obj2) && obj2.Equals(obj1))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else if (obj1 != null && (obj1 != null && !obj1.Equals(obj2)))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else if (obj2 != null && !obj2.Equals(obj1))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else


+ 1
- 1
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs Visa fil

@@ -234,7 +234,7 @@ namespace GamecraftModdingAPI.Tests

CommandBuilder.Builder()
.Name("PlaceConsole")
.Description("Place a bunch of console block with a given text")
.Description("Place a bunch of console block with a given text - entering simulation with them crashes the game as the cmd doesn't exist")
.Action((float x, float y, float z) =>
{
Stopwatch sw = new Stopwatch();


+ 0
- 25
GamecraftModdingAPI/Utility/DeterministicStepCompositionRootPatch.cs Visa fil

@@ -1,25 +0,0 @@
using System;

using RobocraftX.StateSync;
using Svelto.ECS;

using HarmonyLib;

namespace GamecraftModdingAPI.Utility
{
[HarmonyPatch(typeof(DeterministicStepCompositionRoot), "ResetWorld")]
public static class DeterministicStepCompositionRootPatch
{
private static SimpleEntitiesSubmissionScheduler engineRootScheduler;
public static void Postfix(SimpleEntitiesSubmissionScheduler scheduler)
{
engineRootScheduler = scheduler;
}

internal static void SubmitEntitiesNow()
{
if (engineRootScheduler != null)
engineRootScheduler.SubmitEntities();
}
}
}

Laddar…
Avbryt
Spara