/// <summary> /// Safely adds a new crafting node to the custom crafting tree of this fabricator.<para/> /// If the item has not been patched yet, its <see cref="Spawnable.Patch"/> method will first be invoked. /// </summary> /// <param name="item">The <see cref="Craftable"/> item to craft from this fabricator.</param> /// <param name="parentTabId">Optional. The parent tab of this craft node.<para/> /// When this value is null, the item's <see cref="Craftable.StepsToFabricatorTab"/> property will be checked instead.<para/> /// The craft node will be added to the root of the craft tree if both are null.</param> public void AddCraftNode(Craftable item, string parentTabId = null) { Logger.Debug($"'{item.ClassID}' will be added to the custom craft tree '{this.ClassID}'"); OrderedCraftTreeActions.Add(() => { if (item.TechType == TechType.None) { Logger.Info($"'{item.ClassID} had to be patched early to obtain its TechType value for the custom craft tree '{this.ClassID}'"); item.Patch(); } string[] stepsToParent = item.StepsToFabricatorTab; if (parentTabId == null) { if (stepsToParent != null && stepsToParent.Length > 0) { int last = stepsToParent.Length - 1; parentTabId = stepsToParent[last]; } else { parentTabId = RootNode; } } ModCraftTreeLinkingNode parentTab = CraftTreeLinkingNodes[parentTabId]; parentTab.AddCraftingNode(item.TechType); }); }
/// <summary> /// Adds a new crafting node to the custom crafting tree of this fabricator. /// </summary> /// <param name="techType">The item to craft.</param> /// <param name="parentTabId">Optional. The parent tab of this craft node.<para/> /// When this value is null, the craft node will be added to the root of the craft tree.</param> public void AddCraftNode(TechType techType, string parentTabId = null) { Logger.Debug($"'{techType.AsString()}' will be added to the custom craft tree '{this.ClassID}'"); OrderedCraftTreeActions.Add(() => { ModCraftTreeLinkingNode parentTab = CraftTreeLinkingNodes[parentTabId ?? RootNode]; parentTab.AddCraftingNode(techType); }); }
/// <summary> /// Adds a new tab node to the custom crafting tree of this fabricator. /// </summary> /// <param name="tabId">The internal ID for the tab node.</param> /// <param name="displayText">The in-game text shown for the tab node.</param> /// <param name="tabSprite">The sprite used for the tab node.</param> /// <param name="parentTabId">Optional. The parent tab of this tab.<para/> /// When this value is null, the tab will be added to the root of the craft tree.</param> public void AddTabNode(string tabId, string displayText, Sprite tabSprite, string parentTabId = null) { OrderedCraftTreeActions.Add(() => { ModCraftTreeLinkingNode parentNode = CraftTreeLinkingNodes[parentTabId ?? RootNode]; ModCraftTreeTab tab = parentNode.AddTabNode(tabId, displayText, tabSprite); CraftTreeLinkingNodes[tabId] = tab; }); }
/// <summary> /// Safely attempts to add a new crafting node to the custom crafting tree of this fabricator.<para/> /// If the modded TechType is not found, the craft node will not be added. /// </summary> /// <param name="moddedTechType">The modded item to craft.</param> /// <param name="parentTabId">Optional. The parent tab of this craft node.<para/> /// When this value is null, the craft node will be added to the root of the craft tree.</param> public void AddCraftNode(string moddedTechType, string parentTabId = null) { Logger.Debug($"'{moddedTechType}' will be added to the custom craft tree '{this.ClassID}'"); OrderedCraftTreeActions.Add(() => { if (this.TechTypeHandler.TryGetModdedTechType(moddedTechType, out TechType techType)) { ModCraftTreeLinkingNode parentTab = CraftTreeLinkingNodes[parentTabId ?? RootNode]; parentTab.AddCraftingNode(techType); } else { Logger.Info($"Did not find a TechType value for '{moddedTechType}' to add to the custom craft tree '{this.ClassID}'"); } }); }
public static void LoadFabricator() { ModCraftTreeRoot Root = CraftTreeHandler.CreateCustomCraftTreeAndType("compressor", out CraftTree.Type Compressor); if (DefabricatorPresent()) { CompressTab = Root; DecompressTab = null; } else { CompressTab = Root.AddTabNode("CompressedTitaniumCompress", "Compress", TI_1000000_Sprite); DecompressTab = Root.AddTabNode("CompressedTitaniumDecompress", "Decompress", TI_1_Sprite); } new Fabricator().Patch(Compressor); }
protected void addCraftingNodeTo(ModCraftTreeLinkingNode modCraftTreeNode) => modCraftTreeNode.AddCraftingNode(TechType);