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); }
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; } } }
public GameModuleNode FindNode(int id) { GameModuleNode foundNode = null; if (idNodes.TryGetValue(id, out foundNode)) { return(foundNode); } else { return(null); } }
public GameModule FindChildByClassID(int classID) { GameModuleNode node = FindChildNodeByClassID(classID); if (node != null) { return(node.Module); } else { return(null); } }
public GameModule FindChild(int id) { GameModuleNode node = FindChildNode(id); if (node != null) { return(node.Module); } else { return(null); } }
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)); } }
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); } }
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); } }
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); }
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); } }
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); }
internal void OnNodeDetached(GameModuleNode parent, GameModuleNode child) { Debug.Assert(parent.Tree == this); ResetContainerAndRegisterID(child); }
public GameModuleTree(int capacity) { Root = new GameModuleNode(); idNodes = new Dictionary <int, GameModuleNode>(capacity); }