diff --git a/FilterExtension/Categoriser/PartType.cs b/FilterExtension/Categoriser/PartType.cs index c8dcf39d..83309f3f 100644 --- a/FilterExtension/Categoriser/PartType.cs +++ b/FilterExtension/Categoriser/PartType.cs @@ -9,6 +9,9 @@ static class PartType { internal static bool checkCustom(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + bool val; switch (value) { @@ -37,15 +40,31 @@ internal static bool checkCustom(AvailablePart part, string value) return val; } - internal static bool checkModule(AvailablePart part, string value) + internal static bool checkModuleTitle(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + bool moduleCheck = part.moduleInfos.Any(m => m.moduleName == value); return moduleCheck; } + internal static bool checkModuleName(AvailablePart part, string value) + { + if (part.category == PartCategories.none) + return false; + + bool moduleCheck = part.partPrefab.Modules.Contains(value); + + return moduleCheck; + } + internal static bool checkCategory(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + switch (value) { case "Pod": @@ -91,6 +110,9 @@ internal static bool checkCategory(AvailablePart part, string value) internal static bool checkName(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + bool nameCheck = part.name == value; return nameCheck; @@ -98,6 +120,9 @@ internal static bool checkName(AvailablePart part, string value) internal static bool checkTitle(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + bool titleCheck = part.title.Contains(value); return titleCheck; @@ -105,6 +130,9 @@ internal static bool checkTitle(AvailablePart part, string value) internal static bool checkResource(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + bool resourceCheck = part.resourceInfos.Any(r => r.resourceName == value); return resourceCheck; @@ -112,6 +140,9 @@ internal static bool checkResource(AvailablePart part, string value) internal static bool checkTech(AvailablePart part, string value) { + if (part.category == PartCategories.none) + return false; + bool techCheck = part.TechRequired == value; return techCheck; @@ -119,28 +150,29 @@ internal static bool checkTech(AvailablePart part, string value) internal static bool checkManufacturer(AvailablePart part, string value) { - bool manuCheck = part.manufacturer == value; + if (part.category == PartCategories.none) + return false; + + bool manuCheck = (part.manufacturer == value); return manuCheck; } internal static bool checkFolder(AvailablePart part, string value) { - if (part.name == "PotatoRoid") + if (part.category == PartCategories.none) return false; bool folderCheck = false; if (Core.partFolderDict.ContainsKey(part.name)) folderCheck = Core.partFolderDict[part.name] == value; - else - Debug.Log("[Filter Extensions] Unable to assign a mod to the part " + part.title); return folderCheck; } internal static bool checkFolder(AvailablePart part, string[] values) { - if (part.name == "PotatoRoid") + if (part.category == PartCategories.none) return false; if (Core.partFolderDict.ContainsKey(part.name)) @@ -151,7 +183,6 @@ internal static bool checkFolder(AvailablePart part, string[] values) return true; } } - Debug.Log("[Filter Extensions] Unable to assign a mod to the part " + part.title); return false; } diff --git a/FilterExtension/Check.cs b/FilterExtension/Check.cs index da9ad3c7..cf116424 100644 --- a/FilterExtension/Check.cs +++ b/FilterExtension/Check.cs @@ -28,7 +28,10 @@ internal bool checkPart(AvailablePart partToCheck) switch (type) { case "moduleTitle": // check by module title - result = PartType.checkModule(partToCheck, value); + result = PartType.checkModuleTitle(partToCheck, value); + return (result && pass) || !(result || pass); + case "moduleName": + result = PartType.checkModuleName(partToCheck, value); return (result && pass) || !(result || pass); case "name": // check by part name (cfg name) result = PartType.checkName(partToCheck, value); diff --git a/FilterExtension/Core.cs b/FilterExtension/Core.cs index de892869..603e2801 100644 --- a/FilterExtension/Core.cs +++ b/FilterExtension/Core.cs @@ -12,7 +12,7 @@ namespace FilterExtensions public class Core : MonoBehaviour { internal static List Categories = new List(); - internal static List subCategories = new List(); + internal static List subCategories = new List(); internal static Dictionary texDict = new Dictionary(); // all the icons inside folders named filterIcon internal static Dictionary partFolderDict = new Dictionary(); // mod folder for each part by internal name @@ -33,6 +33,7 @@ void Awake() if (!modNames.Contains(name)) modNames.Add(name); + if (!partFolderDict.ContainsKey(p.name)) partFolderDict.Add(p.name, name); else @@ -56,7 +57,7 @@ void Awake() nodeSub.AddValue("icon", s); nodeSub.AddNode(nodeFilter); - subCategories.Add(new subCategory(nodeSub)); + subCategories.Add(new customSubCategory(nodeSub)); } foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("CATEGORY")) @@ -68,7 +69,7 @@ void Awake() foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("SUBCATEGORY")) { - subCategory sC = new subCategory(node); + customSubCategory sC = new customSubCategory(node); if (checkForConflicts(sC)) subCategories.Add(sC); } @@ -83,8 +84,6 @@ private void editor() { c.initialise(); } - //PartCategorizer.Instance.filters.Find(c => c.button.categoryName == "Filter by Mod").button.SetIcon( - // PartCategorizer.Instance.filters.Find(c => c.button.categoryName == "Filter by Manufacturer").button.icon); PartCategorizer.Instance.UpdateCategoryNameLabel(); @@ -93,7 +92,7 @@ private void editor() checkIcons(c); } - foreach (subCategory sC in subCategories) + foreach (customSubCategory sC in subCategories) { try { @@ -105,17 +104,7 @@ private void editor() } refreshList(); - List toDelete = new List(); - foreach (PartCategorizer.Category c in PartCategorizer.Instance.filters) - { - if (c.subcategories.Count == 0) - toDelete.Add(c); - } - foreach(PartCategorizer.Category c in toDelete) - { - PartCategorizer.Instance.filters.Remove(c); - } - + PartCategorizer.Instance.filters.RemoveAll(c => c.subcategories.Count == 0); PartCategorizer.Instance.SetAdvancedMode(); } @@ -127,22 +116,25 @@ private void refreshList() button.SetTrue(button, RUIToggleButtonTyped.ClickType.FORCED); } - private bool checkForConflicts(subCategory sCToCheck) + private bool checkForConflicts(customSubCategory sCToCheck) { - foreach (subCategory sC in subCategories) // iterate through the already added sC's + foreach (customSubCategory sC in subCategories) // iterate through the already added sC's { - if (sCToCheck.categories == sC.categories) + foreach (string s in sCToCheck.categories) { - if (compareFilterLists(sC.filters, sCToCheck.filters)) // check for duplicated filters - { - Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has duplicated the filters of " + sCToCheck.subCategoryTitle); - return false; // ignore this subCategory, only the first processed sC in a conflict will get through - } - else if (sC.subCategoryTitle == sCToCheck.subCategoryTitle) // if they have the same name, just add the new filters on (OR'd together) + if (sC.categories.Contains(s)) { - Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has multiple entries. Filters are being combined"); - sCToCheck.filters.AddRange(sC.filters); - return false; // all other elements of this list have already been check for this condition. Don't need to continue + if (compareFilterLists(sC.filters, sCToCheck.filters)) // check for duplicated filters + { + Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has duplicated the filters of " + sCToCheck.subCategoryTitle); + return false; // ignore this subCategory, only the first processed sC in a conflict will get through + } + else if (sC.subCategoryTitle == sCToCheck.subCategoryTitle) // if they have the same name, just add the new filters on (OR'd together) + { + Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has multiple entries. Filters are being combined"); + sCToCheck.filters.AddRange(sC.filters); + return false; // all other elements of this list have already been check for this condition. Don't need to continue + } } } } @@ -249,7 +241,7 @@ internal static PartCategorizer.Icon getIcon(string name) // credit to EvilReeperx for this lifesaving function private void RepairAvailablePartUrl(AvailablePart ap) { - var url = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(u => u.name == KSPUtil.SanitizeFilename(ap.name)); + var url = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(u => u.name.Replace('_', '.') == ap.name); if (url == null) return; diff --git a/FilterExtension/PartFilters.csproj b/FilterExtension/PartFilters.csproj index 79fdc709..25d1986b 100644 --- a/FilterExtension/PartFilters.csproj +++ b/FilterExtension/PartFilters.csproj @@ -49,13 +49,13 @@ - + - + diff --git a/FilterExtension/Category.cs b/FilterExtension/customCategory.cs similarity index 100% rename from FilterExtension/Category.cs rename to FilterExtension/customCategory.cs diff --git a/FilterExtension/subCategory.cs b/FilterExtension/customSubCategory.cs similarity index 93% rename from FilterExtension/subCategory.cs rename to FilterExtension/customSubCategory.cs index 6a840031..1b0019f9 100644 --- a/FilterExtension/subCategory.cs +++ b/FilterExtension/customSubCategory.cs @@ -5,7 +5,7 @@ namespace FilterExtensions { - class subCategory + class customSubCategory { internal string[] categories; // parent category internal string subCategoryTitle; // title of this subcategory @@ -14,7 +14,7 @@ class subCategory internal List filters = new List(); // Filters are OR'd together (pass if it meets this filter, or this filter) internal bool filter; - public subCategory(ConfigNode node) + public customSubCategory(ConfigNode node) { categories = node.GetValue("category").Split(','); subCategoryTitle = node.GetValue("title"); @@ -43,7 +43,6 @@ internal void initialise() { foreach (string s in categories) { - Debug.Log(s); PartCategorizer.Icon icon; if (string.IsNullOrEmpty(iconName)) { @@ -54,12 +53,9 @@ internal void initialise() { icon = Core.getIcon(iconName); } - Debug.Log("1"); if (filter) { - Debug.Log("2"); PartCategorizer.Category Filter = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.categoryName == s.Trim()); - Debug.Log("3"); PartCategorizer.AddCustomSubcategoryFilter(Filter, subCategoryTitle, icon, p => checkFilters(p)); } else if (!string.IsNullOrEmpty(oldTitle)) diff --git a/GameData/Filter Extensions/FilterExtensions.dll b/GameData/Filter Extensions/FilterExtensions.dll index f2884979..ad1e2625 100644 Binary files a/GameData/Filter Extensions/FilterExtensions.dll and b/GameData/Filter Extensions/FilterExtensions.dll differ diff --git a/GameData/Filter Extensions/FilterExtensions.version b/GameData/Filter Extensions/FilterExtensions.version index e5fe5aef..8f9ec3dd 100644 --- a/GameData/Filter Extensions/FilterExtensions.version +++ b/GameData/Filter Extensions/FilterExtensions.version @@ -1 +1 @@ -{"NAME":"Filter Extensions","URL":"http://ksp-avc.cybutek.net/version.php?id=97","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":1,"MINOR":4,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":0,"MINOR":90,"PATCH":0}} \ No newline at end of file +{"NAME":"Filter Extensions","URL":"http://ksp-avc.cybutek.net/version.php?id=97","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":1,"MINOR":6,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":0,"MINOR":90,"PATCH":0}} \ No newline at end of file