Пример #1
0
        public void AddNode(DialogueNode newNode)
        {
            //Generate flat list of all children nodes, for easier parsing
            //(only useful when adding a node with children, will not do much when adding a single node)
            var newListNodes = new List <DialogueNode>();

            ParseNodeChildren(newNode, false, ref newListNodes);

            //Resolve goto links while old IDs are still available (first resolve inside copied sequence, then link to existing nodes)
            foreach (var node in newListNodes)
            {
                if (node is DialogueNodeGoto)
                {
                    DialogueNodeGoto nodeGoto = node as DialogueNodeGoto;
                    if (nodeGoto.GotoID != DialogueNode.ID_NULL)
                    {
                        nodeGoto.Goto = newListNodes.Find(item => item.ID == nodeGoto.GotoID);
                        if (nodeGoto.Goto == null)
                        {
                            nodeGoto.Goto = GetNodeByID(nodeGoto.GotoID);
                        }
                        nodeGoto.GotoID = DialogueNode.ID_NULL;
                    }
                }
            }

            //Generate new IDs for all new nodes
            foreach (var node in newListNodes)
            {
                node.ID = GenerateID();
                ListNodes.Add(node);
            }
        }
Пример #2
0
        public void AddLast(T element)
        {
            if (CheckIsEmpty())
            {
                this.tail = this.head = new ListNodes(element);
            }
            else
            {
                var newTail = new ListNodes(element);
                newTail.PrevNode   = this.tail;
                this.tail.NextNode = newTail;
                this.tail          = newTail;
                newTail.NextNode   = default;
            }

            this.Count++;
        }
Пример #3
0
        public T RemoveLast()
        {
            if (CheckIsEmpty())
            {
                throw new InvalidOperationException();
            }

            var lastElement = this.tail.Value;

            this.tail = this.tail.PrevNode;
            if (this.tail != default)
            {
                this.tail.NextNode = default;
            }
            else
            {
                this.head = default;
            }

            Count--;
            return(lastElement);
        }
Пример #4
0
        public void RemoveNode(DialogueNode nodeToRemove)
        {
            if (nodeToRemove == null)
            {
                return;
            }

            if (nodeToRemove is DialogueNodeReply)
            {
                //Remove depending nodes
                DialogueNode next = nodeToRemove.Next;
                while (next != null)
                {
                    DialogueNode nextNext = next.Next;
                    RemoveNode(next);
                    next = nextNext;
                }
            }
            else if (nodeToRemove is DialogueNodeChoice)
            {
                //Remove all replies, and let them remove their depending nodes
                DialogueNodeChoice nodechoice = nodeToRemove as DialogueNodeChoice;
                while (nodechoice.Replies.Count > 0)
                {
                    RemoveNode(nodechoice.Replies[0]);
                }
            }
            else if (nodeToRemove is DialogueNodeBranch)
            {
                DialogueNodeBranch nodeBranch = nodeToRemove as DialogueNodeBranch;

                //Remove depending nodes
                DialogueNode next = nodeBranch.Branch;
                while (next != null)
                {
                    DialogueNode nextNext = next.Next;
                    RemoveNode(next);
                    next = nextNext;
                }
            }

            foreach (DialogueNode node in ListNodes)
            {
                //Link next node to previous node
                if (node.Next == nodeToRemove)
                {
                    node.Next = nodeToRemove.Next;
                }

                //Remove from parent choice
                if (node is DialogueNodeChoice && nodeToRemove is DialogueNodeReply)
                {
                    DialogueNodeChoice nodeChoice = node as DialogueNodeChoice;
                    DialogueNodeReply  nodeReply  = nodeToRemove as DialogueNodeReply;
                    if (nodeChoice.Replies.Contains(nodeReply))
                    {
                        nodeChoice.Replies.Remove(nodeReply);
                    }
                }

                //Remove from parent branch
                if (node is DialogueNodeBranch)
                {
                    DialogueNodeBranch nodeBranch = node as DialogueNodeBranch;
                    if (nodeBranch.Branch == nodeToRemove)
                    {
                        nodeBranch.Branch = nodeToRemove.Next;
                    }
                }

                //Clean Goto references
                if (node is DialogueNodeGoto)
                {
                    DialogueNodeGoto nodeGoto = node as DialogueNodeGoto;
                    if (nodeGoto.Goto == nodeToRemove)
                    {
                        nodeGoto.Goto = null;
                    }
                }
            }

            ListNodes.Remove(nodeToRemove);
        }
Пример #5
0
 public DialogueNode GetNodeByID(int id)
 {
     return(ListNodes.Find(item => item.ID == id));
 }
Пример #6
0
 public void AgregarNodo(NodosXbee _nodo)
 {
     ListNodes.Add(_nodo);
     NodoAgregadoEvent(_nodo);
 }