Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CC3 1.0.0.2 bug. #507

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Nautilus/Crafting/ModCraftTreeLinkingNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Nautilus.Handlers;
using Nautilus.Utility;
using UnityEngine;
using UnityEngine.Assertions;

Expand Down Expand Up @@ -83,16 +84,15 @@ public ModCraftTreeTab AddTabNode(string nameID)
/// <returns></returns>
public ModCraftTreeTab GetTabNode(string nameID)
{
foreach (ModCraftTreeTab node in ChildNodes)
foreach (var node in ChildNodes)
{
if (node == null)
{
continue;
}

if (node.Name == nameID && node.Action == TreeAction.Expand)
if (node.Name == nameID && node.Action == TreeAction.Expand && node is ModCraftTreeTab tab)
{
ModCraftTreeTab tab = node;
return tab;
}
}
Expand All @@ -107,16 +107,15 @@ public ModCraftTreeTab GetTabNode(string nameID)
/// <returns></returns>
public ModCraftTreeCraft GetCraftingNode(TechType techType)
{
foreach (ModCraftTreeNode node in ChildNodes)
foreach (var node in ChildNodes)
{
if (node == null)
{
continue;
}

if (node.TechType == techType && node.Action == TreeAction.Craft)
if (node.TechType == techType && node.Action == TreeAction.Craft && node is ModCraftTreeCraft craftNode)
{
ModCraftTreeCraft craftNode = (ModCraftTreeCraft)node;
return craftNode;
}
}
Expand All @@ -131,7 +130,7 @@ public ModCraftTreeCraft GetCraftingNode(TechType techType)
/// <returns></returns>
public ModCraftTreeNode GetNode(string nameID)
{
foreach (ModCraftTreeNode node in ChildNodes)
foreach (var node in ChildNodes)
{
if (node == null)
{
Expand Down
29 changes: 11 additions & 18 deletions Nautilus/Handlers/CraftTreeHandler.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace Nautilus.Handlers;

using System.Linq;
using Nautilus.Crafting;
using Nautilus.Patchers;
using Nautilus.Utility;

namespace Nautilus.Handlers;

/// <summary>
/// A handler class for creating and modifying crafting trees.
/// </summary>
public static class CraftTreeHandler
public static class CraftTreeHandler
{
/// <summary>
/// Adds a new crafting node to the root of the specified crafting tree, at the provided tab location.
Expand All @@ -23,7 +22,7 @@ public static class CraftTreeHandler
/// </param>
public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingItem, params string[] stepsToTab)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
root.AddCraftNode(craftingItem, stepsToTab.LastOrDefault());
return;
Expand All @@ -40,7 +39,7 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt

public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingItem)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
root.AddCraftNode(craftingItem);
return;
Expand All @@ -58,7 +57,7 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt
/// <param name="sprite">The sprite of the tab.</param>
public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, Atlas.Sprite sprite)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
root.AddTabNode(name, displayName, sprite);
return;
Expand All @@ -76,7 +75,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp

public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
root.AddTabNode(name, displayName, sprite);
return;
Expand All @@ -99,7 +98,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </param>
public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, Atlas.Sprite sprite, params string[] stepsToTab)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
root.AddTabNode(name, displayName, sprite, "English", stepsToTab.LastOrDefault());
return;
Expand All @@ -122,7 +121,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp
/// </param>
public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite, params string[] stepsToTab)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
root.AddTabNode(name, displayName, sprite, "English", stepsToTab.LastOrDefault());
return;
Expand Down Expand Up @@ -188,15 +187,9 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp

public static void RemoveNode(CraftTree.Type craftTree, params string[] stepsToNode)
{
if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root))
{
var tab = root.GetTabNode(stepsToNode);
if(tab == null)
{
root.GetNode(stepsToNode)?.RemoveNode();
return;
}
tab.RemoveNode();
root.GetNode(stepsToNode)?.RemoveNode();
return;
}
CraftTreePatcher.NodesToRemove.Add(new Node(stepsToNode, craftTree));
Expand Down
Loading