public void OffsetShapeShouldReturn0WhenNoConnections()
        {
            AdjacencyMap   adjacencyMap = new AdjacencyMap();
            AdjacencyShape result       = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.O);
        }
        public void OffsetShapeShouldReturn0WhenHasOnlyDiagonalConnections()
        {
            AdjacencyMap adjacencyMap = new AdjacencyMap();

            adjacencyMap.SetConnection(Direction.NorthEast, existingConnection);
            adjacencyMap.SetConnection(Direction.SouthWest, existingConnection);

            AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.O);
        }
        public void OffsetShapeShouldReturnTNorthEastWestWhenMissingWestConnection()
        {
            AdjacencyMap adjacencyMap = new AdjacencyMap();

            adjacencyMap.SetConnection(Direction.North, existingConnection);
            adjacencyMap.SetConnection(Direction.East, existingConnection);
            adjacencyMap.SetConnection(Direction.South, existingConnection);

            AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.TNorthEastWest);
        }
        public void OffsetShapeShouldReturnLSouthEastWhenHasAllSouthWestConnections()
        {
            AdjacencyMap adjacencyMap = new AdjacencyMap();

            adjacencyMap.SetConnection(Direction.West, existingConnection);
            adjacencyMap.SetConnection(Direction.SouthWest, existingConnection);
            adjacencyMap.SetConnection(Direction.South, existingConnection);

            AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap);

            Assert.IsTrue(result == AdjacencyShape.LSouthEast);
        }
        public void OffsetShapeShouldReturnUSouthWhenHasSingleConnectionSouthOrWest()
        {
            AdjacencyMap adjacencyMapSouth = new AdjacencyMap();

            adjacencyMapSouth.SetConnection(Direction.South, existingConnection);
            AdjacencyMap adjacencyMapWest = new AdjacencyMap();

            adjacencyMapWest.SetConnection(Direction.West, existingConnection);

            AdjacencyShape resultSouth = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapSouth);
            AdjacencyShape resultWest  = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapWest);

            Assert.IsTrue(resultSouth == AdjacencyShape.USouth);
            Assert.IsTrue(resultWest == AdjacencyShape.USouth);
        }
        public void OffsetShapeShouldReturnUNorthWhenHasSingleConnectionNorthOrEast()
        {
            AdjacencyMap adjacencyMapNorth = new AdjacencyMap();

            adjacencyMapNorth.SetConnection(Direction.North, existingConnection);
            AdjacencyMap adjacencyMapEast = new AdjacencyMap();

            adjacencyMapEast.SetConnection(Direction.East, existingConnection);

            AdjacencyShape resultNorth = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapNorth);
            AdjacencyShape resultEast  = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapEast);

            Assert.IsTrue(resultNorth == AdjacencyShape.UNorth);
            Assert.IsTrue(resultEast == AdjacencyShape.UNorth);
        }
        public void OffsetShapeShouldReturnIWhenHasTwoOppositeOrthogonalConnections()
        {
            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.GetOffsetShape(adjacencyMapNorthSouth);
            AdjacencyShape resultEastWest   = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapEastWest);

            Assert.IsTrue(resultNorthSouth == AdjacencyShape.I);
            Assert.IsTrue(resultEastWest == AdjacencyShape.I);
        }
Ejemplo n.º 8
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap)
        {
            // Determine rotation and mesh specially for every single case.
            float rotation = 0.0f;
            Mesh  mesh;

            AdjacencyShape shape = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap);

            switch (shape)
            {
            case AdjacencyShape.O:
                mesh        = o;
                orientation = OffsetOrientation.o;
                break;

            case AdjacencyShape.UNorth:
                mesh        = uNorth;
                orientation = OffsetOrientation.uNorth;
                rotation    = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection());
                break;

            case AdjacencyShape.USouth:
                mesh        = uSouth;
                orientation = OffsetOrientation.uSouth;
                rotation    = TileHelper.AngleBetween(Direction.South, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.I:
                mesh        = i;
                orientation = OffsetOrientation.i;
                rotation    = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East);
                break;

            case AdjacencyShape.LNorthWest:
                mesh        = lNW;
                orientation = OffsetOrientation.lNW;
                rotation    = 90;
                break;

            case AdjacencyShape.LNorthEast:
                mesh        = lNE;
                orientation = OffsetOrientation.lSE;
                rotation    = 90;
                break;

            case AdjacencyShape.LSouthEast:
                mesh        = lSE;
                orientation = OffsetOrientation.lSW;
                rotation    = 90;
                break;

            case AdjacencyShape.LSouthWest:
                mesh        = lSW;
                orientation = OffsetOrientation.lNW;
                rotation    = 90;
                break;

            case AdjacencyShape.TNorthSouthEast:
                mesh        = tNSE;
                orientation = OffsetOrientation.tSWE;
                rotation    = 90;
                break;

            case AdjacencyShape.TSouthWestEast:
                mesh        = tSWE;
                orientation = OffsetOrientation.tNSW;
                rotation    = 90;
                break;

            case AdjacencyShape.TNorthSouthWest:
                mesh        = tNSW;
                orientation = OffsetOrientation.tNEW;
                rotation    = 90;
                break;

            case AdjacencyShape.TNorthEastWest:
                mesh        = tNEW;
                orientation = OffsetOrientation.tNSE;
                rotation    = 90;
                break;

            case AdjacencyShape.X:
                mesh        = x;
                orientation = OffsetOrientation.x;
                rotation    = 90;
                break;

            default:
                Debug.LogError($"Received unexpected shape from offset shape resolver: {shape}");
                mesh = o;
                break;
            }

            return(new MeshDirectionInfo {
                Mesh = mesh, Rotation = rotation
            });
        }