From fb4b64a6a7c8f5561a3c17aff120e45f9adbea0b Mon Sep 17 00:00:00 2001 From: Joshua Gibbs Date: Mon, 22 Jan 2024 12:29:42 -0700 Subject: [PATCH] fix: Existing Node checks. (#532) --- Nautilus/Patchers/CraftTreePatcher.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Nautilus/Patchers/CraftTreePatcher.cs b/Nautilus/Patchers/CraftTreePatcher.cs index 41b7761b..aadf9144 100644 --- a/Nautilus/Patchers/CraftTreePatcher.cs +++ b/Nautilus/Patchers/CraftTreePatcher.cs @@ -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 removals = NodesToRemove.TryGetValue(type, out removals)? removals: new List(); + List removals = NodesToRemove.TryGetValue(type, out removals) ? removals : new List(); RemoveNodes(ref __result, ref removals); AddCustomTabs(ref __result, type); @@ -135,7 +135,7 @@ private static void AddCustomTabs(ref CraftTree tree, CraftTree.Type type) List customTabs = TabNodes.TryGetValue(type, out customTabs) ? customTabs : new List(); 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; @@ -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)}"); } } @@ -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)}"); } }