Skip to content

Commit

Permalink
fix: Existing Node checks. (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPurple6411 authored Jan 22, 2024
1 parent 60cff24 commit fb4b64a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Nautilus/Patchers/CraftTreePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static void GetTreePreFix(CraftTree.Type treeType, ref CraftTree __resul

private static void PatchCraftTree(ref CraftTree __result, CraftTree.Type type)
{
List<Node> removals = NodesToRemove.TryGetValue(type, out removals)? removals: new List<Node>();
List<Node> removals = NodesToRemove.TryGetValue(type, out removals) ? removals : new List<Node>();
RemoveNodes(ref __result, ref removals);

AddCustomTabs(ref __result, type);
Expand All @@ -135,7 +135,7 @@ private static void AddCustomTabs(ref CraftTree tree, CraftTree.Type type)
List<TabNode> customTabs = TabNodes.TryGetValue(type, out customTabs) ? customTabs : new List<TabNode>();
foreach (TabNode customNode in customTabs)
{
if(!TraverseTree(tree.nodes, customNode.Path, out var currentNode))
if (!TraverseTree(tree.nodes, customNode.Path, out var currentNode))
{
InternalLogger.Error($"Cannot add tab: {customNode.Name} to {customNode.Scheme} at {string.Join("/", customNode.Path)} as the parent node could not be found.");
continue;
Expand All @@ -147,11 +147,14 @@ private static void AddCustomTabs(ref CraftTree tree, CraftTree.Type type)
continue;
}

// Add the new tab node.
currentNode.AddNode(new TreeNode[]
if (TraverseTree(currentNode, new[] { customNode.Name }, out _))
{
new CraftNode(customNode.Name, TreeAction.Expand, TechType.None)
});
// This node already exists, skip it.
continue;
}

// Add the new tab node.
currentNode.AddNode(new CraftNode(customNode.Name, TreeAction.Expand, TechType.None));
InternalLogger.Debug($"Added tab: {customNode.Name} to {customNode.Scheme} at {string.Join("/", customNode.Path)}");
}
}
Expand Down Expand Up @@ -184,11 +187,14 @@ private static void PatchNodes(ref CraftTree tree, CraftTree.Type type)
}
}

// Add the node.
currentNode.AddNode(new TreeNode[]
if (TraverseTree(currentNode, new[] { customNode.TechType.AsString(false) }, out _))
{
new CraftNode(customNode.TechType.AsString(false), TreeAction.Craft, customNode.TechType)
});
// This node already exists, skip it.
continue;
}

// Add the node.
currentNode.AddNode(new CraftNode(customNode.TechType.AsString(false), TreeAction.Craft, customNode.TechType));
InternalLogger.Debug($"Added Crafting node: {customNode.TechType.AsString()} to {customNode.Scheme} at {string.Join("/", customNode.Path)}");
}
}
Expand Down

0 comments on commit fb4b64a

Please sign in to comment.