From 369cc8a9c3d5c4b1776ae54af23b3915582bc22d Mon Sep 17 00:00:00 2001 From: Metious <71298690+Metious@users.noreply.github.com> Date: Tue, 3 Sep 2024 06:37:23 +0330 Subject: [PATCH] Revert "feat: Workbench Organization (#486)" This reverts commit e992abeeb66ea26bfa5c5bef5d59759eadb3240e. --- Nautilus/Handlers/CraftTreeHandler.cs | 9 --- Nautilus/Patchers/CraftTreePatcher.cs | 88 +++------------------------ 2 files changed, 9 insertions(+), 88 deletions(-) diff --git a/Nautilus/Handlers/CraftTreeHandler.cs b/Nautilus/Handlers/CraftTreeHandler.cs index d7fbaaf3e..2a46919d3 100644 --- a/Nautilus/Handlers/CraftTreeHandler.cs +++ b/Nautilus/Handlers/CraftTreeHandler.cs @@ -29,7 +29,6 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt nodes.Add(new CraftingNode(stepsToTab, craftTree, craftingItem)); CraftTreePatcher.CraftingNodes[craftTree] = nodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } /// @@ -47,7 +46,6 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt nodes.Add(new CraftingNode(new string[0], craftTree, craftingItem)); CraftTreePatcher.CraftingNodes[craftTree] = nodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } #if SUBNAUTICA @@ -67,7 +65,6 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp craftTreeTabNodes.Add(new TabNode(new string[0], craftTree, sprite, name, displayName)); CraftTreePatcher.TabNodes[craftTree] = craftTreeTabNodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } /// @@ -87,7 +84,6 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp craftTreeTabNodes.Add(new TabNode(new string[0], craftTree, new Atlas.Sprite(sprite), name, displayName)); CraftTreePatcher.TabNodes[craftTree] = craftTreeTabNodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } /// @@ -112,7 +108,6 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp craftTreeTabNodes.Add(new TabNode(stepsToTab, craftTree, sprite, name, displayName)); CraftTreePatcher.TabNodes[craftTree] = craftTreeTabNodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } /// @@ -137,7 +132,6 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp craftTreeTabNodes.Add(new TabNode(stepsToTab, craftTree, new Atlas.Sprite(sprite), name, displayName)); CraftTreePatcher.TabNodes[craftTree] = craftTreeTabNodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } #elif BELOWZERO @@ -157,7 +151,6 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp craftTreeTabNodes.Add(new TabNode(new string[0], craftTree, sprite, name, displayName)); CraftTreePatcher.TabNodes[craftTree] = craftTreeTabNodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } /// @@ -182,7 +175,6 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp craftTreeTabNodes.Add(new TabNode(stepsToTab, craftTree, sprite, name, displayName)); CraftTreePatcher.TabNodes[craftTree] = craftTreeTabNodes; - CraftTreePatcher.CachedTrees.Remove(craftTree); } #endif @@ -209,7 +201,6 @@ public static void RemoveNode(CraftTree.Type craftTree, params string[] stepsToN nodesToRemove.Add(new Node(stepsToNode, craftTree)); CraftTreePatcher.NodesToRemove[craftTree] = nodesToRemove; - CraftTreePatcher.CachedTrees.Remove(craftTree); } /// diff --git a/Nautilus/Patchers/CraftTreePatcher.cs b/Nautilus/Patchers/CraftTreePatcher.cs index b7f5dc245..d7bd36ac6 100644 --- a/Nautilus/Patchers/CraftTreePatcher.cs +++ b/Nautilus/Patchers/CraftTreePatcher.cs @@ -18,9 +18,6 @@ internal class CraftTreePatcher internal static Dictionary> NodesToRemove = new(); internal static Dictionary> CraftingNodes = new(); internal static Dictionary> TabNodes = new(); - internal static Dictionary CachedTrees = new(); - private const string FallbackTabNode = "Modded"; - private const string VanillaRoot = "Vanilla"; #endregion @@ -28,74 +25,15 @@ internal class CraftTreePatcher internal static void Patch(Harmony harmony) { - CreateFallbackNodes(); harmony.PatchAll(typeof(CraftTreePatcher)); InternalLogger.Log($"CraftTreePatcher is done.", LogLevel.Debug); } - - private static void CreateFallbackNodes() - { - // Workbench - CreateVanillaTabNode(CraftTree.Type.Workbench, "Modification Station", TechType.Workbench, CraftTree.WorkbenchScheme().root); - CraftTreeHandler.AddTabNode(CraftTree.Type.Workbench, FallbackTabNode + CraftTree.Type.Workbench, "Mod Items", SpriteManager.Get(TechType.Workbench)); - - // Fabricator - CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, FallbackTabNode + CraftTree.Type.Fabricator, "Mod Items", SpriteManager.Get(TechType.Fabricator)); - - // Constructor - CraftTreeHandler.AddTabNode(CraftTree.Type.Constructor, FallbackTabNode + CraftTree.Type.Constructor, "Mod Items", SpriteManager.Get(TechType.Constructor)); - - // Seamoth Upgrades - CraftTreeHandler.AddTabNode(CraftTree.Type.SeamothUpgrades, FallbackTabNode + CraftTree.Type.SeamothUpgrades, "Mod Items", SpriteManager.Get(TechType.BaseUpgradeConsole)); - - // Map Room - CreateVanillaTabNode(CraftTree.Type.MapRoom, "Scanner Upgrades", TechType.BaseMapRoom, CraftTree.MapRoomSheme().root); - CraftTreeHandler.AddTabNode(CraftTree.Type.MapRoom, FallbackTabNode + CraftTree.Type.MapRoom, "Mod Items", SpriteManager.Get(TechType.BaseMapRoom)); -#if SUBNAUTICA - // Cyclops Fabricator - CreateVanillaTabNode(CraftTree.Type.CyclopsFabricator, "Cyclops Fabricator", TechType.Cyclops, CraftTree.CyclopsFabricatorScheme().root); - CraftTreeHandler.AddTabNode(CraftTree.Type.CyclopsFabricator, FallbackTabNode + CraftTree.Type.CyclopsFabricator, "Mod Items", SpriteManager.Get(TechType.Cyclops)); -#elif BELOWZERO - // SeaTruck Fabricator - CraftTreeHandler.AddTabNode(CraftTree.Type.SeaTruckFabricator, FallbackTabNode+CraftTree.Type.SeaTruckFabricator, "Mod Items", SpriteManager.Get(TechType.SeaTruckFabricator)); -#endif - } - - private static void CreateVanillaTabNode(CraftTree.Type treeType, string DisplayName, TechType spriteTechType, TreeNode root) - { - var removedNodes = new List(); - foreach (var node in root.nodes) - { - if (node is not CraftNode craftNode || craftNode.action == TreeAction.Expand) - continue; - - CraftTreeHandler.RemoveNode(treeType, new[] { node.id }); - removedNodes.Add(craftNode); - } - - if (removedNodes.Count == 0) - return; - - var vanillaTab = VanillaRoot + treeType; - CraftTreeHandler.AddTabNode(treeType, vanillaTab, DisplayName, SpriteManager.Get(spriteTechType)); - foreach (var node in removedNodes) - { - InternalLogger.Debug($"Moved {node.techType0} from {treeType} root into new {vanillaTab} tab."); - CraftTreeHandler.AddCraftingNode(treeType, node.techType0, new[] { vanillaTab }); - } - InternalLogger.Info($"Reorganized {removedNodes.Count} {treeType} nodes into new {vanillaTab} tab."); - } + [HarmonyPostfix] [HarmonyPatch(typeof(CraftTree), nameof(CraftTree.GetTree))] private static void GetTreePreFix(CraftTree.Type treeType, ref CraftTree __result) { - if (CachedTrees.TryGetValue(treeType, out var cachedTree)) - { - __result = cachedTree; - return; - } - __result ??= !CustomTrees.TryGetValue(treeType, out var customRoot) ? __result : customRoot.CustomCraftingTree; if (__result == null) @@ -107,10 +45,14 @@ private static void GetTreePreFix(CraftTree.Type treeType, ref CraftTree __resul return; } +#if BELOWZERO + if (treeType is CraftTree.Type.SeaTruckFabricator) + { + PatchCraftTree(ref __result, CraftTree.Type.Fabricator); + } +#endif PatchCraftTree(ref __result, treeType); CraftTree.AddToCraftableTech(__result); - CachedTrees.Add(treeType, __result); - return; } #endregion @@ -140,11 +82,11 @@ private static void AddCustomTabs(ref CraftTree tree, CraftTree.Type type) continue; } - if (currentNode.nodes.Any(node => node is CraftNode craftNode && craftNode.action == TreeAction.Craft)) + /*if (currentNode.nodes.Any(node => node is CraftNode craftNode && craftNode.action == TreeAction.Craft)) { InternalLogger.Error($"Cannot add tab: {customNode.Name} to {customNode.Scheme} at {string.Join("/", customNode.Path)} as it is being added to a parent node that contains crafting nodes. {string.Join(", ", currentNode.nodes.Where(node => node is CraftNode craftNode && craftNode.action == TreeAction.Craft).Select(x => x.id))} "); continue; - } + }*/ // Add the new tab node. currentNode.AddNode(new TreeNode[] @@ -166,18 +108,6 @@ private static void PatchNodes(ref CraftTree tree, CraftTree.Type type) continue; } - if (currentNode.nodes.Any(x => x is CraftNode craftNode && craftNode.action == TreeAction.Expand)) - { - InternalLogger.Warn($"Cannot add Crafting node: {customNode.TechType.AsString()} as it is being added to {currentNode.id} that contains Tab nodes. {string.Join(", ", currentNode.nodes.Where(node => node is CraftNode craftNode && craftNode.action == TreeAction.Expand).Select(x => x.id))}"); - InternalLogger.Warn($"Adding to Fallback {FallbackTabNode} node in tree root."); - - if (!TraverseTree(tree.nodes, new[] { FallbackTabNode + customNode.Scheme }, out currentNode)) - { - InternalLogger.Error($"Cannot add Crafting node: {customNode.TechType.AsString()} to {customNode.Scheme} at {string.Join("/", customNode.Path)} as the fallback node could not be found."); - continue; - } - } - // Add the node. currentNode.AddNode(new TreeNode[] {