Esempio n. 1
0
        /// <summary>
        /// Populates a new ModCraftTreeRoot from a CraftNode tree.
        /// </summary>
        /// <param name="tree">The tree to create the ModCraftTreeRoot from.</param>
        /// <param name="root"></param>
        internal static void CreateFromExistingTree(CraftNode tree, ref ModCraftTreeLinkingNode root)
        {
            foreach (CraftNode node in tree)
            {
                if (node.action == TreeAction.Expand)
                {
                    ModCraftTreeTab tab   = root.AddTabNode(node.id);
                    var             thing = (ModCraftTreeLinkingNode)tab;
                    CreateFromExistingTree(node, ref thing);
                }

                if (node.action == TreeAction.Craft)
                {
                    var techType = TechType.None;
                    TechTypeExtensions.FromString(node.id, out techType, false);

                    if (node.id == "SeamothHullModule2")
                    {
                        techType = TechType.VehicleHullModule2;
                    }
                    else if (node.id == "SeamothHullModule3")
                    {
                        techType = TechType.VehicleHullModule3;
                    }

                    root.AddCraftingNode(techType);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the tab node at the specified path from the root.
        /// </summary>
        /// <param name="stepsToTab">
        /// <para>The steps to the target tab.</para>
        /// <para>These must match the id value of the CraftNode in the crafting tree you're targeting.</para>
        /// <para>Do not include "root" in this path.</para>
        /// </param>
        /// <returns>If the specified tab node is found, returns that <see cref="ModCraftTreeTab"/>; Otherwise, returns null.</returns>
        public ModCraftTreeTab GetTabNode(params string[] stepsToTab)
        {
            ModCraftTreeTab tab = base.GetTabNode(stepsToTab[0]);

            for (int i = 1; i < stepsToTab.Length && tab != null; i++)
            {
                tab = tab.GetTabNode(stepsToTab[i]);
            }

            return(tab);
        }
        /// <summary>
        /// Creates a new tab node for the crafting tree and links it to the calling node.
        /// </summary>
        /// <param name="nameID">The name/ID of this node.</param>
        /// <returns>A new tab node linked to the root node and ready to use.</returns>
        public ModCraftTreeTab AddTabNode(string nameID)
        {
            string modName = ReflectionHelper.CallingAssemblyNameByStackTrace();

            var tabNode = new ModCraftTreeTab(modName, nameID);

            tabNode.LinkToParent(this);

            ChildNodes.Add(tabNode);

            return(tabNode);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the node at the specified path from the root.
        /// </summary>
        /// <param name="stepsToNode">
        /// <para>The steps to the target tab.</para>
        /// <para>These must match the id value of the CraftNode in the crafting tree you're targeting.</para>
        /// <para>Do not include "root" in this path.</para>
        /// </param>
        /// <returns>If the specified tab node is found, returns that <see cref="ModCraftTreeNode"/>; Otherwise, returns null.</returns>
        public ModCraftTreeNode GetNode(params string[] stepsToNode)
        {
            if (stepsToNode.Length == 1)
            {
                return(base.GetNode(stepsToNode[0]));
            }

            int stepCountToTab = stepsToNode.Length - 1;

            string nodeID = stepsToNode[stepCountToTab];

            string[] stepsToTab = new string[stepCountToTab];
            Array.Copy(stepsToNode, stepsToTab, stepCountToTab);

            ModCraftTreeTab tab = GetTabNode(stepsToTab);

            return(tab?.GetNode(nodeID));
        }
Esempio n. 5
0
        /// <summary>
        /// Populates a new ModCraftTreeRoot from a CraftNode tree.
        /// </summary>
        /// <param name="tree">The tree to create the ModCraftTreeRoot from.</param>
        /// <param name="root"></param>
        internal static void CreateFromExistingTree(CraftNode tree, ref ModCraftTreeLinkingNode root)
        {
            foreach (CraftNode node in tree)
            {
                if (node.action == TreeAction.Expand)
                {
                    ModCraftTreeTab tab   = root.AddTabNode(node.id);
                    var             thing = (ModCraftTreeLinkingNode)tab;
                    CreateFromExistingTree(node, ref thing);
                }

                if (node.action == TreeAction.Craft)
                {
                    TechTypeExtensions.FromString(node.id, out TechType techType, false);

                    root.AddCraftingNode(techType);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the node at the specified path from the root.
        /// </summary>
        /// <param name="stepsToNode">
        /// <para>The steps to the target tab.</para>
        /// <para>These must match the id value of the CraftNode in the crafting tree you're targeting.</para>
        /// <para>Do not include "root" in this path.</para>
        /// </param>
        /// <returns>If the specified tab node is found, returns that <see cref="ModCraftTreeNode"/>; Otherwise, returns null.</returns>
        public ModCraftTreeNode GetNode(params string[] stepsToNode)
        {
            if (stepsToNode.Length == 1)
            {
                return(base.GetNode(stepsToNode[0]));
            }

            string nodeID = stepsToNode[stepsToNode.Length - 1];

            string[]        stepsToTab = stepsToNode.Take(stepsToNode.Length - 1).ToArray();
            ModCraftTreeTab tab        = GetTabNode(stepsToTab);

            if (tab == null)
            {
                return(null);
            }

            return(tab.GetNode(nodeID));
        }