-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
making a test for these int grid values. looks to be working so far b…
…ased on the test, found a small fix through this process
- Loading branch information
Showing
4 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
Assets/Tests/EditMode/Tests/ComponentTilesetTilesTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace LDtkUnity.Tests | ||
{ | ||
public class ComponentTilesTest | ||
{ | ||
[Test] | ||
public void TestExpectedCoordsTileset() | ||
{ | ||
//const string lvlName = "Level"; | ||
|
||
string path = "Assets/Samples/Samples/Test_file_for_API_showing_all_features.ldtk"; | ||
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path); | ||
|
||
LDtkComponentProject project = prefab.GetComponent<LDtkComponentProject>(); | ||
LDtkComponentLayer[] layers = project.Worlds[0].Levels[0].LayerInstances; | ||
|
||
foreach (LDtkComponentLayer layer in layers) | ||
{ | ||
LDtkComponentLayerIntGridValues intGrid = layer.IntGrid; | ||
|
||
if (layer.Identifier == "IntGrid_without_rules") | ||
{ | ||
Assert.NotNull(intGrid); | ||
Assert.IsNull(layer.AutoLayerTiles); | ||
Assert.IsNull(layer.GridTiles); | ||
|
||
Vector3Int[] allValidItems = new Vector3Int[] | ||
{ | ||
new Vector3Int(3,28,0), | ||
}; | ||
|
||
//test what doesnt exist | ||
TestIntGridPosition(intGrid, new Vector3Int(0,0,0), false); | ||
TestIntGridPosition(intGrid, new Vector3Int(1,0,0), false); | ||
TestIntGridPosition(intGrid, new Vector3Int(1000,9999,0), false); | ||
|
||
//test what exists | ||
|
||
} | ||
if (layer.Identifier == "IntGrid_with_rules") | ||
{ | ||
Assert.NotNull(intGrid); | ||
Assert.NotNull(layer.AutoLayerTiles); | ||
Assert.IsNull(layer.GridTiles); | ||
} | ||
if (layer.Identifier == "PureAutoLayer") | ||
{ | ||
Assert.IsNull(intGrid); | ||
Assert.NotNull(layer.AutoLayerTiles); | ||
Assert.IsNull(layer.GridTiles); | ||
} | ||
if (layer.Identifier == "Tiles") | ||
{ | ||
Assert.IsNull(intGrid); | ||
Assert.IsNull(layer.AutoLayerTiles); | ||
Assert.NotNull(layer.GridTiles); | ||
} | ||
if (layer.Identifier == "IntGrid_8px_grid") | ||
{ | ||
Assert.NotNull(intGrid); | ||
Assert.IsNull(layer.AutoLayerTiles); | ||
Assert.IsNull(layer.GridTiles); | ||
} | ||
} | ||
|
||
/*Level level = project.UnityWorlds.First().Levels.FirstOrDefault(); | ||
Assert.NotNull(level, "null level"); | ||
//LayerInstance layer = level.LayerInstances.FirstOrDefault(p => p.IsIntGridLayer); | ||
//Assert.NotNull(layer); | ||
Rect levelBounds = level.UnityWorldSpaceBounds(WorldLayout.Free, (int)16); | ||
//Debug.Log(levelBounds);*/ | ||
} | ||
|
||
private static void TestIntGridPosition(LDtkComponentLayerIntGridValues intGrid, Vector3Int pos, bool assertHas, int assertIs = -1, Vector3Int[] assertAllTilesExist = null) | ||
{ | ||
LDtkDefinitionObjectIntGridValue valueObj = intGrid.GetValueDefinition(pos); | ||
int value = intGrid.GetValue(pos); | ||
|
||
Assert.AreEqual(assertIs, value); | ||
|
||
if (assertHas) | ||
{ | ||
Assert.NotNull(valueObj); | ||
Assert.AreNotEqual(-1, value); | ||
|
||
Vector3Int[] positionsObj = intGrid.GetPositionsOfValueDefinition(valueObj); | ||
Vector3Int[] positions = intGrid.GetPositionsOfValue(value); | ||
|
||
Assert.AreEqual(valueObj.Value, value); | ||
Assert.True(positionsObj.SequenceEqual(positions)); | ||
|
||
Assert.True(ArraysContainSameValues(positionsObj, assertAllTilesExist)); | ||
} | ||
else | ||
{ | ||
Assert.IsNull(valueObj); | ||
} | ||
} | ||
|
||
public static bool ArraysContainSameValues<T>(T[] array1, T[] array2) | ||
{ | ||
return array1.Length == array2.Length && array1.All(array2.Contains) && array2.All(array1.Contains); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/Tests/EditMode/Tests/ComponentTilesetTilesTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.