diff --git a/scenes/StreamContainer.cs b/scenes/StreamContainer.cs index f9e52d1..8227dcc 100644 --- a/scenes/StreamContainer.cs +++ b/scenes/StreamContainer.cs @@ -14,7 +14,7 @@ public class StreamContainer : Spatial private MeshInstance _bounds; private Spatial _activeTiles; private Queue _unusedTiles; - private TileWorld _tileWorld; + public TileWorld TileWorld; private MultiMeshInstance _tileMultiMesh; // resources @@ -47,7 +47,7 @@ public class StreamContainer : Spatial public void SetWorld(TileWorld tileWorld) { - _tileWorld = tileWorld; + TileWorld = tileWorld; } // Called when the node enters the scene tree for the first time. @@ -71,7 +71,7 @@ public class StreamContainer : Spatial boundsTransform = boundsTransform.Scaled(new Vector3(Dimensions.x, 1, Dimensions.y)); _bounds.Transform = boundsTransform; - _tileWorld = GetNode(World); + TileWorld = GetNode(World); } @@ -186,9 +186,9 @@ public class StreamContainer : Spatial { HexTile3D tile3D = _unusedTiles.Dequeue(); tile3D.OffsetCoords = coord; - tile3D.Type = _tileWorld.GetTileTypeAtOffset(coord); + tile3D.Type = TileWorld.GetTileTypeAtOffset(coord); Transform tileTransform = tile3D.Transform; - tileTransform.origin.y = _tileWorld.GetHeightAtOffset(coord); + tileTransform.origin.y = TileWorld.GetHeightAtOffset(coord); tile3D.Transform = tileTransform; OnTileActivate(tile3D); @@ -217,9 +217,9 @@ public class StreamContainer : Spatial } Transform tileTransform = tile3D.Transform; - tileTransform.origin.y = _tileWorld.GetHeightAtOffset(offsetCoords); + tileTransform.origin.y = TileWorld.GetHeightAtOffset(offsetCoords); tile3D.Transform = tileTransform; - tile3D.Type = _tileWorld.GetTileTypeAtOffset(offsetCoords); + tile3D.Type = TileWorld.GetTileTypeAtOffset(offsetCoords); _tileToInstanceIndex[tile3D] = _tileToInstanceIndex.Count; @@ -291,7 +291,7 @@ public class StreamContainer : Spatial } Transform tileTransform = tile.GlobalTransform; - tileTransform.origin.y = _tileWorld.GetHeightAtOffset(tile.OffsetCoords); + tileTransform.origin.y = TileWorld.GetHeightAtOffset(tile.OffsetCoords); tile.GlobalTransform = tileTransform; OnTileActivate(tile); diff --git a/tests/StreamContainerTests.cs b/tests/StreamContainerTests.cs new file mode 100644 index 0000000..0ad7715 --- /dev/null +++ b/tests/StreamContainerTests.cs @@ -0,0 +1,60 @@ +using System; +using Godot; +using GodotComponentTest.utils; +using GoDotTest; +using Xunit; + +namespace GodotComponentTest.tests; + +public class StreamContainerTests : TestClass +{ + private Node _testScene = null; + private TileWorld _tileWorld; + private StreamContainer _streamContainer; + + private PackedScene _tileWorldScene = GD.Load("res://scenes/TileWorld.tscn"); + private PackedScene _streamContainerScene = GD.Load("res://scenes/StreamContainer.tscn"); + + public StreamContainerTests(Node testScene) : base(testScene) + { + _testScene = testScene; + } + + [Setup] + public void Setup() + { + _tileWorld = (TileWorld) _tileWorldScene.Instance(); + _tileWorld.HexGrid = new HexGrid(); + _testScene.AddChild(_tileWorld); + _streamContainer = (StreamContainer) _streamContainerScene.Instance(); + + foreach (Node node in _testScene.GetChildren()) + { + if (node is TileWorld) + { + _streamContainer.World = node.GetPath(); + } + } + + _testScene.AddChild(_streamContainer); + } + + [Cleanup] + public void Cleanup() + { + foreach (Node node in _testScene.GetChildren()) + { + node.QueueFree(); + } + + _streamContainer.QueueFree(); + _tileWorld.QueueFree(); + } + + [Test] + public void Plane2DDistSimple() + { +// _streamContainer.UpdateRects(new Vector2(0, 0)); +// _streamContainer.UpdateRects(new Vector2(1, 0)); + } +} \ No newline at end of file