Пример #1
0
        public GameModuleNode FindChildNode(int id)
        {
            if (id == GameModule.UnspecifiedID)
            {
                return(null);
            }

            foreach (GameModuleNode item in children)
            {
                if (item.Module != null && item.Module.ID == id)
                {
                    return(item);
                }
            }

            foreach (GameModuleNode item in children)
            {
                GameModuleNode foundNode = FindChildNode(id);
                if (foundNode != null)
                {
                    return(foundNode);
                }
            }

            return(null);
        }
Пример #2
0
        public void DetachAllChildren()
        {
            if (children == null)
            {
                return;
            }

            List <GameModuleNode> temporaryChildren = children;

            if (tree != null)
            {
                for (int i = temporaryChildren.Count - 1; i >= 0; i--)
                {
                    GameModuleNode item = temporaryChildren[i];
                    tree.OnNodeDetached(this, item);
                    item.parent = null;
                }
            }
            else
            {
                for (int i = temporaryChildren.Count - 1; i >= 0; i--)
                {
                    temporaryChildren[i].parent = null;
                }
            }
        }
Пример #3
0
        public GameModuleNode FindNode(int id)
        {
            GameModuleNode foundNode = null;

            if (idNodes.TryGetValue(id, out foundNode))
            {
                return(foundNode);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        public GameModule FindChildByClassID(int classID)
        {
            GameModuleNode node = FindChildNodeByClassID(classID);

            if (node != null)
            {
                return(node.Module);
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        public GameModule FindChild(int id)
        {
            GameModuleNode node = FindChildNode(id);

            if (node != null)
            {
                return(node.Module);
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
 private static bool IsAncestor(GameModuleNode descendant, GameModuleNode ancestor)
 {
     if (descendant.parent == null)
     {
         return(false);
     }
     if (descendant.parent == ancestor)
     {
         return(true);
     }
     else
     {
         return(IsAncestor(descendant.parent, ancestor));
     }
 }
Пример #7
0
        private void ResetContainerAndRegisterID(GameModuleNode node)
        {
            node.Tree = null;

            int id = node.Module.ID;

            if (id != GameModule.UnspecifiedID)
            {
                idNodes.Remove(id);
            }

            foreach (GameModuleNode item in node.Children)
            {
                ResetContainerAndRegisterID(item);
            }
        }
Пример #8
0
        private void SetContainerAndRegisterID(GameModuleNode node)
        {
            // GameModuleTree에서 이 Method를 호출하기 전에 검사하여 예외를 던져야합니다.
            Debug.Assert(idNodes.ContainsKey(node.Module.ID));

            node.Tree = this;

            int id = node.Module.ID;

            if (id != GameModule.UnspecifiedID)
            {
                idNodes.Add(id, node);
            }

            foreach (GameModuleNode item in node.Children)
            {
                SetContainerAndRegisterID(item);
            }
        }
Пример #9
0
        public bool DetachChild(GameModuleNode item)
        {
            if (children == null || item.parent != this || item.tree != tree)
            {
                return(false);
            }

            bool removed = children.Remove(item);

            Debug.Assert(removed); // 이미 item의 부모가 this인지 확인했기 때문에 반드시 있어야합니다.

            item.parent = null;

            if (tree != null)
            {
                tree.OnNodeDetached(this, item);
            }

            return(true);
        }
Пример #10
0
        public void AttachChild(GameModuleNode item)
        {
            if (item.parent == this)
            {
                Debug.Assert(children != null && children.Contains(item));
                return;
            }

            bool treeChanged = (item.parent == null || item.parent.tree != tree);

            GameModuleNode oldParent = item.parent;

            if (oldParent != null)
            {
                // Detach를 거치지 않고 직접 제거합니다.
                item.parent.children.Remove(item);
                item.parent = null;

                // GameStructure.OnNodeDetached의 명세대로 GameStructure가 바뀌었을 때만 호출합니다.
                if (oldParent.tree != null && treeChanged)
                {
                    oldParent.tree.OnNodeDetached(oldParent, item);
                }
            }

            Debug.Assert(item.parent == null);

            item.parent = this;
            item.tree   = tree;
            if (children == null)
            {
                children = new List <GameModuleNode>();
            }
            children.Add(item);

            // GameStructure.OnNodeAttached의 명세대로 GameStructure가 바뀌었을 때만 호출합니다.
            if (tree != null && treeChanged)
            {
                tree.OnNodeAttached(this, item);
            }
        }
Пример #11
0
        public GameModuleNode FindChildNodeByClassID(int classID)
        {
            foreach (GameModuleNode item in children)
            {
                if (item.Module != null && item.Module.ClassID == classID)
                {
                    return(item);
                }
            }

            foreach (GameModuleNode item in children)
            {
                GameModuleNode foundNode = FindChildNodeByClassID(classID);
                if (foundNode != null)
                {
                    return(foundNode);
                }
            }

            return(null);
        }
Пример #12
0
 internal void OnNodeDetached(GameModuleNode parent, GameModuleNode child)
 {
     Debug.Assert(parent.Tree == this);
     ResetContainerAndRegisterID(child);
 }
Пример #13
0
 public GameModuleTree(int capacity)
 {
     Root    = new GameModuleNode();
     idNodes = new Dictionary <int, GameModuleNode>(capacity);
 }