Пример #1
0
    /// <summary>
    /// Add a new node to the build-end of of the branch.
    /// New nodes automatically become the new InNode unless the NODE_DIRECTION
    /// passed is a multi-direction. In this case the branch is "closed" and no
    /// more nodes can be added.
    /// </summary>
    /// <param name="direction"></param>
    public NODE_DIRECTION[] Add(NODE_DIRECTION direction)
    {
        if (Open)
        {
            if (direction.IsMulti())
            {
                // close the branch
                Open = false;
                InNode.InDirection = direction;
                return(direction.GetDirections().ToArray());
            }
            else
            {
                Vector2Int newLocation = InNode.Next(direction);
                Node       nextNode    = new Node(newLocation.x, newLocation.y, this);
                InNode.InNode    = nextNode;
                nextNode.OutNode = InNode;
                InNode           = nextNode;
                _nodeDirectory.Add(nextNode.VectorLocation, nextNode);

                if (Parent != null)
                {
                    Parent.SetNodeDirectoryData(nextNode);
                }

                return(new NODE_DIRECTION[] { direction });
            }
        }
        else
        {
            throw new BranchException(BRANCH_EXCEPTION_TYPE.BRANCH_NOT_OPEN);
        }
    }
Пример #2
0
    public void Test_Path_Init_GetNodesAt()
    {
        NODE_DIRECTION initDir = NODE_DIRECTION.UP_LEFT_RIGHT;
        Path           path    = new Path(origin, initDir);

        foreach (int id in path.OuterBranchIDs)
        {
            Branch outerBranch = path.Branches[id];
            switch (origin.DirectionOf(outerBranch.InNode))
            {
            case NODE_DIRECTION.LEFT:
                outerBranch.Add(NODE_DIRECTION.UP);
                outerBranch.Add(NODE_DIRECTION.RIGHT);
                break;

            case NODE_DIRECTION.RIGHT:
                outerBranch.Add(NODE_DIRECTION.UP);
                outerBranch.Add(NODE_DIRECTION.LEFT);
                break;

            default:
                break;
            }
        }

        Assert.That(path.GetNodesAt(2, 3).Length, Is.EqualTo(initDir.GetDirections().ToArray().Length));
    }
Пример #3
0
    public Path(Node origin, NODE_DIRECTION initialDirections)
    {
        Origin         = origin;
        Branches       = new Dictionary <int, Branch>();
        OuterBranchIDs = new List <int>();

        _branchId      = 1;
        _nodeDirectory = new Dictionary <Vector2Int, List <Node> >();
        SetNodeDirectoryData(Origin);

        // Set in-direction of the Origin
        Origin.InDirection = initialDirections;

        // Create initial outer branches
        foreach (NODE_DIRECTION direction in initialDirections.GetDirections())
        {
            Branch outerBranch = new Branch(_branchId++, origin, direction, this);
            Add(outerBranch);
        }
    }