private static void RemoveNodes(ref CraftNode nodes, List <Node> nodesToRemove, CraftTree.Type scheme) { // This method can be used to both remove single child nodes, thus removing one recipe from the tree. // Or it can remove entire tabs at once, removing the tab and all the recipes it contained in one go. foreach (Node nodeToRemove in nodesToRemove) { // Not for this fabricator. Skip. if (nodeToRemove.Scheme != scheme) { continue; } if (nodeToRemove.Path == null || nodeToRemove.Path.Length == 0) { Logger.Warn($"An empty path in {nameof(RemoveNodes)} for '{scheme}' was skipped"); continue; } // Get the names of each node in the path to traverse tree until we reach the node we want. TreeNode currentNode = default; currentNode = nodes; // Travel the path down the tree. string currentPath = null; for (int step = 0; step < nodeToRemove.Path.Length; step++) { currentPath = nodeToRemove.Path[step]; if (step > nodeToRemove.Path.Length) { break; } currentNode = currentNode[currentPath]; } // Safty checks. if (currentNode != null && currentNode.id == currentPath) { if (currentNode.parent == null) { Logger.Warn($"Skipped removing craft tree node in {nameof(RemoveNodes)} for '{scheme}'. Could not identify the parent node."); } else { currentNode.Clear(); // Remove all child nodes (if any) currentNode.parent.RemoveNode(currentNode); // Remove the node from its parent } } } }
private static void RemoveNodes(ref CraftNode nodes, List <Node> nodesToRemove, CraftTree.Type scheme) { // This method can be used to both remove single child nodes, thus removing one recipe from the tree. // Or it can remove entire tabs at once, removing the tab and all the recipes it contained in one go. foreach (Node nodeToRemove in nodesToRemove) { // Not for this fabricator. Skip. if (nodeToRemove.Scheme != scheme) { continue; } // Get the names of each node in the path to traverse tree until we reach the node we want. TreeNode currentNode = default; currentNode = nodes; // Travel the path down the tree. string currentPath = null; for (int step = 0; step < nodeToRemove.Path.Length; step++) { currentPath = nodeToRemove.Path[step]; if (step > nodeToRemove.Path.Length) { break; } currentNode = currentNode[currentPath]; } // Hold a reference to the parent node TreeNode parentNode = currentNode.parent; // Safty checks. if (currentNode != null && currentNode.id == currentPath) { currentNode.Clear(); // Remove all child nodes (if any) parentNode.RemoveNode(currentNode); // Remove the node } } }