コード例 #1
0
    private void RemoveChild(ENodePosition _ePosition)
    {
        switch (_ePosition)
        {
        case ENodePosition.EAbove:
            Destroy(childAbove.gameObject);
            childAbove = null;
            break;

        case ENodePosition.ELeft:
            Destroy(childLeft.gameObject);
            childLeft = null;
            break;

        case ENodePosition.EBelow:
            Destroy(childBelow.gameObject);
            childBelow = null;
            break;

        case ENodePosition.ERight:
            Destroy(childRight.gameObject);
            childRight = null;
            break;
        }
        if (eType == ENodeType.EBase)
        {
            UpdateNodeType();
        }
        else
        {
            parentNode.UpdateNodeType();
        }
    }
コード例 #2
0
    public static ENodePosition GetOppositePosition(ENodePosition _ePosition)
    {
        switch (_ePosition)
        {
        case ENodePosition.EAbove:
            return(ENodePosition.EBelow);

        case ENodePosition.EBelow:
            return(ENodePosition.EAbove);

        case ENodePosition.ELeft:
            return(ENodePosition.ERight);

        case ENodePosition.ERight:
            return(ENodePosition.ELeft);

        default:
            return(ENodePosition.EAbove);
        }
    }
コード例 #3
0
    private Node_CellEditor GetChild(ENodePosition _ePosition)
    {
        switch (_ePosition)
        {
        case ENodePosition.EAbove:
            return(childAbove);

        case ENodePosition.ELeft:
            return(childLeft);

        case ENodePosition.EBelow:
            return(childBelow);

        case ENodePosition.ERight:
            return(childRight);

        default:
            return(null);
        }
    }
コード例 #4
0
    //-------------------------------------------------------------------------------------------//

    /** Call this after creating a new node
     * Will set all necessary member variables and assign a material
     *
     * @param _eNewType The type of node you created; Most likely normal
     * @param _eNewPositionToParent Where this node is relative to its parent
     * @param _parent The parentNode for this node
     */
    public void PostConstructor(ENodeType _eNewType, ENodePosition _eNewPositionToParent, Node_CellEditor _parent)
    {
        eType             = _eNewType;
        ePositionToParent = _eNewPositionToParent;
        parentNode        = _parent;
        InstantiateArrows();
        if (eType == ENodeType.EBase)
        {
            GetComponent <Rigidbody>().isKinematic = true;
        }
        else
        {
            connectionToParent = GetComponent <SpringJoint>();
            connectionToParent.connectedBody = parentNode.gameObject.GetComponent <Rigidbody>();
        }
        if (eType != ENodeType.EBase)
        {
            GetComponent <GB_Dragable>().allowDragging = true;
            GetComponent <GB_Dragable>().NodeDrag(_parent.gameObject);
        }
    }
コード例 #5
0
    public void CreateAndAttachChildNode(ENodePosition _ePosition)
    {
        Vector3    childPos   = Vector3.zero;
        Quaternion childRot   = Quaternion.Euler(Vector3.zero);
        ENodeType  eChildType = ENodeType.ENormal;

        if (eType != ENodeType.EBase)
        {
            List <Node_CellEditor> armNodes = GetAllNodesOfArm();
            //this node is also in there as the last node so we have to take the node at index lenth -2
            Node_CellEditor parentNode = armNodes[armNodes.Count - 2];

            if (parentNode != null)
            {
                Vector3 pos    = transform.position;
                Vector3 parPos = parentNode.transform.position;
                Vector3 dir    = (pos - parPos).normalized;
                childPos = dir * DISTANCE_AVERAGE;
                float rot = StaticMaths.FindLookAtAngle2D(pos, parPos); //maybe pos and childPos or parPos and childPos
                childRot = Quaternion.Euler(0f, rot, 0f);
                //childRot = gameObject.transform.rotation;

                if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EAbove) ||
                    (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EBelow))
                {
                    childPos = new Vector3(-childPos.z, childPos.y, childPos.x);
                }
                else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ELeft) ||
                         (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ERight))
                {
                    childPos = new Vector3(-childPos.z, childPos.y, childPos.x);
                }
                else if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EBelow) ||
                         (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EAbove))
                {
                    childPos = new Vector3(childPos.z, childPos.y, -childPos.x);
                }
                else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ERight) ||
                         (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ELeft))
                {
                    childPos = new Vector3(childPos.z, childPos.y, -childPos.x);
                }
            }
            else
            {
                Debug.Log("FATAL ERROR : non-base node doesn't have parent node. ");
            }
        }
        else
        {
            childPos   = transform.position;
            eChildType = ENodeType.ESingle;
            switch (_ePosition)
            {
            case ENodePosition.EAbove:
                childPos.z += DISTANCE_AVERAGE;
                break;

            case ENodePosition.EBelow:
                childPos.z -= DISTANCE_AVERAGE;
                break;

            case ENodePosition.ERight:
                childPos.x += DISTANCE_AVERAGE;
                break;

            case ENodePosition.ELeft:
                childPos.x -= DISTANCE_AVERAGE;
                break;
            }
        }

        childPos += transform.position;

        //These ifs make sure that you can't create a child node on the socket where a parent node is attached
        if (_ePosition == ENodePosition.EAbove && ePositionToParent != ENodePosition.EBelow)
        {
            GameObject chA = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chA.transform.parent = transform;
            childAbove           = chA.GetComponent <Node_CellEditor>();
            childAbove.PostConstructor(eChildType, _ePosition, this);
            if (arrowUp != null)
            {
                Destroy(arrowUp.gameObject);
                arrowUp = null;
            }
        }
        else if (_ePosition == ENodePosition.ERight && ePositionToParent != ENodePosition.ELeft)
        {
            GameObject chR = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chR.transform.parent = transform;
            childRight           = chR.GetComponent <Node_CellEditor>();
            childRight.PostConstructor(eChildType, _ePosition, this);

            if (arrowRight != null)
            {
                Destroy(arrowRight.gameObject);
                arrowRight = null;
            }
        }
        else if (_ePosition == ENodePosition.EBelow && ePositionToParent != ENodePosition.EAbove)
        {
            GameObject chB = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chB.transform.parent = transform;
            childBelow           = chB.GetComponent <Node_CellEditor>();
            childBelow.PostConstructor(eChildType, _ePosition, this);

            if (arrowDown != null)
            {
                Destroy(arrowDown.gameObject);
                arrowDown = null;
            }
        }
        else if (_ePosition == ENodePosition.ELeft && ePositionToParent != ENodePosition.ERight)
        {
            GameObject chL = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chL.transform.parent = transform;
            childLeft            = chL.GetComponent <Node_CellEditor>();
            childLeft.PostConstructor(eChildType, _ePosition, this);

            if (arrowLeft != null)
            {
                Destroy(arrowLeft.gameObject);
                arrowLeft = null;
            }
        }

        if (eType != ENodeType.EBase)
        {
            parentNode.UpdateNodeType();
        }
        else
        {
            UpdateNodeType();
        }
    }
コード例 #6
0
ファイル: DiffEngine.cs プロジェクト: dsisco11/xLog
        /// <summary>
        /// Compiles a list of positions and text to write at said positions
        /// </summary>
        /// <returns></returns>
        public static LinkedList <TextChunk> Compile_Transformations(StringPtr OldText, StringPtr NewText)
        {
            /* Get all of the places where we have changed */
            LinkedList <TextDiff> Diffs = Difference(OldText, NewText);

            /* Compile a list of all our CSI command blocks */
            LinkedList <CSI_BLOCK> Blocks = Terminal.Compile_Command_Blocks(NewText);

            /* Filter out any blocks which have no changes in them  */
            LinkedList <CSI_BLOCK>     Changed = new LinkedList <CSI_BLOCK>();
            LinkedListNode <CSI_BLOCK> cBlock  = Blocks.First;

            foreach (TextDiff diff in Diffs)
            {
                NodePoint dPos = new NodePoint(diff.Start, diff.End);
                if (cBlock == null)
                {
                    break;
                }
                while (cBlock != null)
                {
                    if (!cBlock.Value.CmdByte.HasValue)
                    {/* Skip blocks which do not have a command */
                        cBlock = cBlock.Next;
                        break;
                    }

                    NodePoint     bPos = new NodePoint(cBlock.Value.BlockStart, cBlock.Value.BlockEnd);
                    ENodePosition Pos  = NodePoint.Compare(dPos, bPos);
                    if (Pos == ENodePosition.CONTAINS)
                    {/* This block collides with the current diff, add it to the changed blocks if it isnt already there and then continue to the next diff */
                        if (!ReferenceEquals(cBlock, Changed.Last))
                        {
                            Changed.AddLast(cBlock.Value);
                        }
                        break;
                    }
                    else
                    {/* This block occurs before/after the current diff, move on to the next block */
                        cBlock = cBlock.Next;
                        if (cBlock == null)
                        {
                            break;
                        }
                    }
                }
            }

            /* We want a series of commands that ONLY replace text which has changed BUT which does not skip CSI commands that may apply to those differences AND which do not include redundant CSI commands */
            int Balance = 0;// Tracks the total balance of text written vs text removed
            var RetList = new LinkedList <TextChunk>();
            LinkedListNode <TextDiff> cDiff = Diffs.First;

            cBlock = Changed.First;

            foreach (TextDiff diff in Diffs)
            {
                NodePoint dPos = new NodePoint(diff.Start, diff.End);
                /* Find the Command block(if any) that goes before this diff text  */
                bool bSearching = true;
                while (bSearching && cBlock != null)
                {
                    var           block = cBlock.Value;
                    NodePoint     bPos  = new NodePoint(block.BlockStart, block.BlockEnd);
                    ENodePosition Pos   = NodePoint.Compare(dPos, bPos);
                    switch (Pos)
                    {
                    case ENodePosition.PRECEDING:
                    {        /* move to next block */
                        cBlock = cBlock.Next;
                    }
                    break;

                    case ENodePosition.CONTAINS:
                    {
                        bSearching = false;
                        cBlock     = cBlock.Next;
                        RetList.AddLast(new TextChunk(block.BlockStart, NewText.AsMemory().Slice(block.BlockStart, block.CmdLength)));
                    }
                    break;

                    case ENodePosition.FOLLOWING:
                    case ENodePosition.CONTAINED_BY:
                    default:
                    {
                        bSearching = false;
                    }
                    break;
                    }
                }
                /* In order to account for the total changes which have occured we need to ensure that any text which will be overwritten which isnt supposed to be replaced will correctly be reprinted after the overwriting text */
                switch (diff.Type)
                {
                case EDiffType.Mutation:
                {
                    //Delta += diff.Length;/* This text was only altered, it should be invisible to our balance */
                    RetList.AddLast(new TextChunk(diff.Start, NewText.AsMemory().Slice(diff.Start, diff.Length)));
                }
                break;

                case EDiffType.Insertion:
                {        /* In the case of inserted text we should insert all the text that WAS at the start of this diff but before the next as a command so it is reprinted */
                    RetList.AddLast(new TextChunk(diff.Start, NewText.AsMemory().Slice(diff.Start, diff.Length)));
                    Balance += diff.Length;
                    var next = cDiff.Next;
                    if (next != null)
                    {
                        var repeat_length = next.Value.Start - diff.Start;                                           /* The length of text we need to repeat is whatever was between our insertion pos and the start of the next diff */
                        //Delta -= available;/* This text was already present, it should be invisible to our balance */
                        RetList.AddLast(new TextChunk(diff.End, NewText.AsMemory().Slice(diff.End, repeat_length))); /* We read from this diff's end because in the new buffer the repeated text is after this diff */
                    }
                    else                                                                                             /* No next diff, insert all needed text */
                    {
                        var repeat_length = (OldText?.Length ?? 0) - diff.Start;
                        RetList.AddLast(new TextChunk(diff.End, NewText.AsMemory().Slice(diff.End, repeat_length)));        /* We read from this diff's end because in the new buffer the repeated text is after this diff */
                    }
                }
                break;

                case EDiffType.Removal:
                {        /* For removals we just want to track how much text was removed */
                    Balance -= diff.Length;
                }
                break;
                }
            }

            /* If our balance is negative then we need to erase that many characters after the end of our buffer onscreen */
            if (Balance < 0)
            {
                RetList.AddLast(new TextChunk(NewText.Length, new string('\0', -Balance)));
            }

            return(RetList);
        }