Пример #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
        public CategoryInstance(CategoryNode protoC, Dictionary <string, SubcategoryNode> allSubCats)
        {
            Name = Localizer.Format(protoC.CategoryName);
            if (string.IsNullOrEmpty(Name))
            {
                Logger.Log("Category name is blank", Logger.LogLevel.Warn);
                return;
            }
            Icon          = protoC.IconName;
            Colour        = protoC.Colour;
            Type          = protoC.Type;
            Behaviour     = protoC.Behaviour;
            Subcategories = new List <SubCategoryInstance>();

            foreach (SubCategoryItem sci in protoC.SubCategories)
            {
                if (allSubCats.TryGetValue(sci.SubcategoryName, out SubcategoryNode protoSC) && protoSC != null)
                {
                    var node = new SubcategoryNode(protoSC, sci.ApplyTemplate ? protoC : null);

                    var instance = new SubCategoryInstance(node, PartLoader.LoadedPartsList);
                    if (instance.Valid)
                    {
                        Subcategories.Add(instance);
                    }
                }
            }

            if (!Subcategories.Any())
            {
                throw new ArgumentException($"No subcategories valid, abandon instantiation of {Name}");
            }
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// mark all subcategories that have identical filtering
        /// </summary>
        private void CheckAndMarkConflicts()
        {
            // Can't guarantee iteration order of dict will be the same each time so need a set of elements that have been processed
            // to ensure conflicts are only checked against elements that are already checked
            // by only checking against processed elements we know we're only adding checking for collisions between each pair once
            var processedElements = new List <string>();

            foreach (KeyValuePair <string, SubcategoryNode> kvpOuter in subCategoriesDict)
            {
                foreach (string subcatName in processedElements)
                {
                    SubcategoryNode processedSubcat = subCategoriesDict[subcatName];
                    if (FilterNode.CompareFilterLists(processedSubcat.Filters, kvpOuter.Value.Filters))
                    {
                        // add conflict entry for the already entered subCategory
                        if (conflictsDict.TryGetValue(subcatName, out List <string> conflicts))
                        {
                            conflicts.Add(kvpOuter.Key);
                        }
                        else
                        {
                            conflictsDict.Add(subcatName, new List <string>()
                            {
                                kvpOuter.Key
                            });
                        }

                        // add a conflict entry for the new subcategory
                        if (conflictsDict.TryGetValue(kvpOuter.Key, out conflicts))
                        {
                            conflicts.Add(subcatName);
                        }
                        else
                        {
                            conflictsDict.Add(kvpOuter.Key, new List <string>()
                            {
                                subcatName
                            });
                        }
                    }
                }
                processedElements.Add(kvpOuter.Key);
            }
        }
Пример #5
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));
            }
        }