Example #1
0
        /// <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);
            });
        }
Example #2
0
 /// <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}'");
         }
     });
 }