Пример #1
0
        /// <summary>
        /// create the subcategories for each unique propellant combination found
        /// </summary>
        private void GenerateEngineTypes()
        {
            var engines = new List <SubCategoryItem>();

            foreach (List <string> ls in propellantCombos)
            {
                string propList = string.Join(",", ls.ToArray());
                string name     = propList;
                string icon     = propList;
                SetName(ref name);

                if (!string.IsNullOrEmpty(name) && !subCategoriesDict.ContainsKey(name))
                {
                    var checks = new List <ConfigNode>()
                    {
                        CheckNodeFactory.MakeCheckNode(CheckPropellant.ID, propList, exact: true)
                    };
                    var filters = new List <ConfigNode>()
                    {
                        FilterNode.MakeFilterNode(false, checks)
                    };
                    var sC = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode(name, icon, false, filters), this);
                    subCategoriesDict.Add(name, sC);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// create the subcategories for filter by manufacturer by discovered GameData folder
        /// </summary>
        /// <param name="modNames"></param>
        private void ProcessFilterByManufacturer(List <string> modNames)
        {
            // define the mod subcategories
            var subCatNames = new List <string>();

            foreach (string s in modNames)
            {
                string name = s;
                if (subCategoriesDict.ContainsKey(name))
                {
                    name = "mod_" + name;
                }
                string icon = name;
                SetName(ref name);

                if (!subCategoriesDict.ContainsKey(name))
                {
                    subCatNames.Add(name);
                    var checks = new List <ConfigNode>()
                    {
                        CheckNodeFactory.MakeCheckNode(CheckFolder.ID, name)
                    };
                    var filters = new List <ConfigNode>()
                    {
                        FilterNode.MakeFilterNode(false, checks)
                    };
                    var sC = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode(name, icon, false, filters), this);
                    subCategoriesDict.Add(name, sC);
                }
            }

            var manufacturerSubs = new ConfigNode("SUBCATEGORIES");

            for (int i = 0; i < subCatNames.Count; i++)
            {
                manufacturerSubs.AddValue("list", i.ToString() + "," + subCatNames[i]);
            }

            var filterByManufacturer = new ConfigNode("CATEGORY");

            filterByManufacturer.AddValue("name", "Filter by Manufacturer");
            filterByManufacturer.AddValue("type", "stock");
            filterByManufacturer.AddValue("value", "replace");
            filterByManufacturer.AddNode(manufacturerSubs);
            FilterByManufacturer = new CategoryNode(filterByManufacturer, this);
            CategoryNodes.Add(FilterByManufacturer);
        }
Пример #3
0
        /// <summary>
        /// turn the loaded category and subcategory nodes into useable data
        /// </summary>
        private void ProcessFilterDefinitions()
        {
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("CATEGORY"))
            {
                var C = new CategoryNode(node, this);
                if (C.SubCategories == null)
                {
                    Logger.Log($"no subcategories present in {C.CategoryName}", Logger.LogLevel.Error);
                    continue;
                }
                CategoryNodes.AddUnique(C);
            }
            //load all subCategory configs
            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("SUBCATEGORY"))
            {
                var sC = new SubcategoryNode(node, this);
                if (!sC.HasFilters || string.IsNullOrEmpty(sC.SubCategoryTitle))
                {
                    Logger.Log($"subcategory format error: {sC.SubCategoryTitle}", Logger.LogLevel.Error);
                    continue;
                }
                else if (subCategoriesDict.ContainsKey(sC.SubCategoryTitle)) // if something does have the same title
                {
                    Logger.Log($"subcategory name duplicated: {sC.SubCategoryTitle}", Logger.LogLevel.Error);
                    continue;
                }
                else // if nothing else has the same title
                {
                    subCategoriesDict.Add(sC.SubCategoryTitle, sC);
                }
            }

            CategoryNode Cat = CategoryNodes.Find(C => C.CategoryName == "Filter by Resource");

            if (Cat != null && Cat.Type == CategoryNode.CategoryType.STOCK)
            {
                foreach (string s in resources)
                {
                    // add spaces before each capital letter
                    string name = System.Text.RegularExpressions.Regex.Replace(s, @"\B([A-Z])", " $1");
                    if (subCategoriesDict.ContainsKey(name))
                    {
                        Logger.Log($"resource name already exists, abandoning generation for {name}", Logger.LogLevel.Debug);
                        continue;
                    }
                    else if (!string.IsNullOrEmpty(name))
                    {
                        ConfigNode checkNode = CheckNodeFactory.MakeCheckNode(CheckResource.ID, s);
                        ConfigNode filtNode  = FilterNode.MakeFilterNode(false, new List <ConfigNode>()
                        {
                            checkNode
                        });
                        ConfigNode subcatNode = SubcategoryNode.MakeSubcategoryNode(name, name, false, new List <ConfigNode>()
                        {
                            filtNode
                        });
                        subCategoriesDict.Add(name, new SubcategoryNode(subcatNode, this));
                        Cat.SubCategories.AddUnique(new SubCategoryItem(name));
                    }
                }
            }

            foreach (CategoryNode C in CategoryNodes)
            {
                if (!C.All)
                {
                    continue;
                }
                var filterList = new List <FilterNode>();
                if (C.SubCategories != null)
                {
                    foreach (SubCategoryItem s in C.SubCategories)
                    {
                        if (subCategoriesDict.TryGetValue(s.SubcategoryName, out SubcategoryNode subcategory))
                        {
                            filterList.AddUniqueRange(subcategory.Filters);
                        }
                    }
                }
                var filternodes = new List <ConfigNode>();
                foreach (FilterNode f in filterList)
                {
                    filternodes.Add(f.ToConfigNode());
                }
                var newSub = new SubcategoryNode(SubcategoryNode.MakeSubcategoryNode("All parts in " + C.CategoryName, C.IconName, false, filternodes), this);
                subCategoriesDict.Add(newSub.SubCategoryTitle, newSub);
                C.SubCategories.Insert(0, new SubCategoryItem(newSub.SubCategoryTitle));
            }
        }