internal ProtoPartSnapshotNode(ProtoPartSnapshot protoPart, ProtoPartSnapshotNode parentNode)
 {
     part     = protoPart;
     parent   = parentNode;
     children = new List <ProtoPartSnapshotNode>();
     if (parent != null)
     {
         parent.AddChild(this);
     }
 }
        internal ProtoPartSnapshotTree(List <ProtoPartSnapshot> snapshots)
        {
            tree = new Dictionary <uint, ProtoPartSnapshotNode>();
            protoPartSnapshots = snapshots;
            root = null;

            foreach (ProtoPartSnapshot part in protoPartSnapshots)
            {
                CreateNode(part);
            }
        }
        internal void AddBreadthFirst(List <ProtoPartSnapshot> parts, ProtoPartSnapshotNode stopAt)
        {
            parts.Add(part);
            children.Sort();

            foreach (ProtoPartSnapshotNode child in children)
            {
                if (child != stopAt)
                {
                    child.AddBreadthFirst(parts, stopAt);
                }
            }
        }
        int IComparable.CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            ProtoPartSnapshotNode otherNode = obj as ProtoPartSnapshotNode;

            if (otherNode == null)
            {
                throw new ArgumentException("Object is not a ProtoPartSnapshotNode");
            }
            return(part.partName.CompareTo(otherNode.part.partName));
        }
        internal void Split(ProtoPartSnapshot separatorPart, out List <ProtoPartSnapshot> launchVehicleParts, out List <ProtoPartSnapshot> payloadParts)
        {
            ProtoPartSnapshotNode splitAt = null;

            if (!tree.TryGetValue(separatorPart.persistentId, out splitAt))
            {
                launchVehicleParts = null;
                payloadParts       = null;
                Debug.Log(string.Format("Could not split tree, part not found {0}", separatorPart.partName));
                return;
            }

            launchVehicleParts = new List <ProtoPartSnapshot>();
            payloadParts       = new List <ProtoPartSnapshot>();

            root.AddBreadthFirst(payloadParts, splitAt);
            splitAt.AddBreadthFirst(launchVehicleParts);
        }
        internal ProtoPartSnapshotNode CreateNode(ProtoPartSnapshot part)
        {
            ProtoPartSnapshotNode node       = null;
            ProtoPartSnapshotNode parentNode = null;

            ProtoPartSnapshot parent = protoPartSnapshots[part.parentIdx];

            if (parent != part)
            {
                parentNode = CreateNode(parent);
            }
            if (!tree.TryGetValue(part.persistentId, out node))
            {
                node = new ProtoPartSnapshotNode(part, parentNode);
                tree.Add(part.persistentId, node);
            }
            if (parentNode == null)
            {
                root = node;
            }
            return(node);
        }
 internal void AddChild(ProtoPartSnapshotNode child)
 {
     children.Add(child);
 }