public void AdvancedShapeShouldReturnXOppositeWhenHasFourOrthogonalAndTwoOppositeDiagonalConnections() { AdjacencyMap adjacencyMap1 = new AdjacencyMap(); adjacencyMap1.SetConnection(Direction.North, existingConnection); adjacencyMap1.SetConnection(Direction.East, existingConnection); adjacencyMap1.SetConnection(Direction.South, existingConnection); adjacencyMap1.SetConnection(Direction.West, existingConnection); adjacencyMap1.SetConnection(Direction.NorthEast, existingConnection); adjacencyMap1.SetConnection(Direction.SouthWest, existingConnection); AdjacencyMap adjacencyMap2 = new AdjacencyMap(); adjacencyMap2.SetConnection(Direction.North, existingConnection); adjacencyMap2.SetConnection(Direction.East, existingConnection); adjacencyMap2.SetConnection(Direction.South, existingConnection); adjacencyMap2.SetConnection(Direction.West, existingConnection); adjacencyMap2.SetConnection(Direction.NorthWest, existingConnection); adjacencyMap2.SetConnection(Direction.SouthEast, existingConnection); AdjacencyShape result1 = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap1); AdjacencyShape result2 = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap2); Assert.IsTrue(result1 == AdjacencyShape.XOpposite); Assert.IsTrue(result2 == AdjacencyShape.XOpposite); }
public void AdvancedShapeShouldReturnLNoneWhenHasTwoAdjacentOrthogonalConnections() { AdjacencyMap adjacencyMapNorthEast = new AdjacencyMap(); adjacencyMapNorthEast.SetConnection(Direction.North, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.East, existingConnection); AdjacencyMap adjacencyMapSouthEast = new AdjacencyMap(); adjacencyMapSouthEast.SetConnection(Direction.South, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.East, existingConnection); AdjacencyMap adjacencyMapSouthWest = new AdjacencyMap(); adjacencyMapSouthWest.SetConnection(Direction.South, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.West, existingConnection); AdjacencyMap adjacencyMapNorthWest = new AdjacencyMap(); adjacencyMapNorthWest.SetConnection(Direction.North, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.West, existingConnection); AdjacencyShape resultNorthEast = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthEast); AdjacencyShape resultSouthEast = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapSouthEast); AdjacencyShape resultSouthWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapSouthWest); AdjacencyShape resultNorthWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthWest); Assert.IsTrue(resultNorthEast == AdjacencyShape.LNone); Assert.IsTrue(resultSouthEast == AdjacencyShape.LNone); Assert.IsTrue(resultSouthWest == AdjacencyShape.LNone); Assert.IsTrue(resultNorthWest == AdjacencyShape.LNone); }
public void AdvancedShapeShouldReturn0WhenNoConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); AdjacencyShape result = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.O); }
public void AdvancedShapeShouldReturn0WhenHasOnlyDiagonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.NorthEast, existingConnection); adjacencyMap.SetConnection(Direction.SouthWest, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.O); }
public void AdvancedShapeShouldReturnTNoneWhenHasThreeOrthogonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); adjacencyMap.SetConnection(Direction.West, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.TNone); }
public void AdvancedShapeShouldReturnIWhenHasTwoOppositeOrthogonalConnections() { AdjacencyMap adjacencyMapNorthSouth = new AdjacencyMap(); adjacencyMapNorthSouth.SetConnection(Direction.North, existingConnection); adjacencyMapNorthSouth.SetConnection(Direction.South, existingConnection); AdjacencyMap adjacencyMapEastWest = new AdjacencyMap(); adjacencyMapEastWest.SetConnection(Direction.East, existingConnection); adjacencyMapEastWest.SetConnection(Direction.West, existingConnection); AdjacencyShape resultNorthSouth = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthSouth); AdjacencyShape resultEastWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapEastWest); Assert.IsTrue(resultNorthSouth == AdjacencyShape.I); Assert.IsTrue(resultEastWest == AdjacencyShape.I); }
public void AdvancedShapeShouldReturnTNoneWhenHasThreeOrthogonalAndOneOppositeDiagonalConnection() { AdjacencyMap adjacencyMapL = new AdjacencyMap(); adjacencyMapL.SetConnection(Direction.North, existingConnection); adjacencyMapL.SetConnection(Direction.East, existingConnection); adjacencyMapL.SetConnection(Direction.West, existingConnection); adjacencyMapL.SetConnection(Direction.SouthWest, existingConnection); AdjacencyMap adjacencyMapR = new AdjacencyMap(); adjacencyMapR.SetConnection(Direction.North, existingConnection); adjacencyMapR.SetConnection(Direction.East, existingConnection); adjacencyMapR.SetConnection(Direction.West, existingConnection); adjacencyMapR.SetConnection(Direction.SouthEast, existingConnection); AdjacencyShape resultL = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapL); AdjacencyShape resultR = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapR); Assert.IsTrue(resultL == AdjacencyShape.TNone); Assert.IsTrue(resultR == AdjacencyShape.TNone); }
public void AdvancedShapeShouldReturnUWhenSingleOrthogonalConnection() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); AdjacencyShape resultN = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); adjacencyMap.SetConnection(Direction.North, missingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); AdjacencyShape resultE = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); adjacencyMap.SetConnection(Direction.East, missingConnection); adjacencyMap.SetConnection(Direction.South, existingConnection); AdjacencyShape resultS = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); adjacencyMap.SetConnection(Direction.South, missingConnection); adjacencyMap.SetConnection(Direction.West, existingConnection); AdjacencyShape resultW = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); Assert.IsTrue(resultN == AdjacencyShape.U); Assert.IsTrue(resultE == AdjacencyShape.U); Assert.IsTrue(resultS == AdjacencyShape.U); Assert.IsTrue(resultW == AdjacencyShape.U); }
public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap) { float rotation = 0.0f; Mesh mesh; AdjacencyShape shape = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); switch (shape) { case AdjacencyShape.O: mesh = o; break; case AdjacencyShape.U: mesh = u; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection()); break; case AdjacencyShape.I: mesh = i; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East); break; case AdjacencyShape.LNone: mesh = lNone; rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections()); break; case AdjacencyShape.LSingle: mesh = lSingle; rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections()); break; case AdjacencyShape.TNone: mesh = tNone; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.TSingleLeft: mesh = tSingleLeft; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.TSingleRight: mesh = tSingleRight; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.TDouble: mesh = tDouble; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.XNone: mesh = xNone; break; case AdjacencyShape.XSingle: mesh = xSingle; Direction connectingDiagonal = adjacencyMap.GetSingleConnection(false); rotation = connectingDiagonal == Direction.NorthEast ? 0f : connectingDiagonal == Direction.SouthEast ? 90f : connectingDiagonal == Direction.SouthWest ? 180f : -90f; break; case AdjacencyShape.XOpposite: mesh = xOpposite; rotation = adjacencyMap.HasConnection(Direction.NorthEast) ? 0f : 90f; break; case AdjacencyShape.XSide: mesh = xSide; rotation = TileHelper.AngleBetween(Direction.NorthWest, adjacencyMap.GetDirectionBetweenTwoConnections(false)) - 45f; break; case AdjacencyShape.XTriple: mesh = xTriple; Direction nonConnectingDiagonal = adjacencyMap.GetSingleNonConnection(false); rotation = nonConnectingDiagonal == Direction.NorthEast ? -90f : nonConnectingDiagonal == Direction.SouthEast ? 0f : nonConnectingDiagonal == Direction.SouthWest ? 90f : 180f; break; case AdjacencyShape.XQuad: mesh = xQuad; break; default: Debug.LogError($"Received unexpected shape from advanced shape resolver: {shape}"); mesh = o; break; } //If someone knows of a more elegant way to do the same without switching the same variable twice, I'd like to hear it :) if (opaque) { switch (shape) { case AdjacencyShape.U: viewObstacles[0].SetActive(false); viewObstacles[1].SetActive(false); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(false); break; case AdjacencyShape.I: viewObstacles[0].SetActive(false); viewObstacles[1].SetActive(false); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(true); break; case AdjacencyShape.LNone: case AdjacencyShape.LSingle: viewObstacles[0].SetActive(false); viewObstacles[1].SetActive(true); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(false); break; case AdjacencyShape.TNone: case AdjacencyShape.TSingleLeft: case AdjacencyShape.TSingleRight: viewObstacles[0].SetActive(true); viewObstacles[1].SetActive(true); viewObstacles[2].SetActive(false); viewObstacles[3].SetActive(true); break; case AdjacencyShape.TDouble: case AdjacencyShape.XNone: case AdjacencyShape.XSingle: case AdjacencyShape.XOpposite: case AdjacencyShape.XSide: case AdjacencyShape.XTriple: case AdjacencyShape.XQuad: viewObstacles[0].SetActive(true); viewObstacles[1].SetActive(true); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(true); break; } } return(new MeshDirectionInfo { Mesh = mesh, Rotation = rotation }); }