diff --git a/FilterExtension/ConfigNodes/Check.cs b/FilterExtension/ConfigNodes/Check.cs index 0dabd039..12d909f7 100644 --- a/FilterExtension/ConfigNodes/Check.cs +++ b/FilterExtension/ConfigNodes/Check.cs @@ -169,7 +169,7 @@ public bool checkPart(AvailablePart part, int depth = 0) result = PartType.checkCrewCapacity(part, value, equality); break; case CheckType.custom: // for when things get tricky - result = PartType.checkCustom(part, value); + result = Editor.instance.ready ? PartType.checkCustom(part, value) : !invert; break; case CheckType.mass: result = PartType.checkMass(part, value, equality); diff --git a/FilterExtension/ConfigNodes/customSubCategory.cs b/FilterExtension/ConfigNodes/customSubCategory.cs index 6792820c..2d9c4da7 100644 --- a/FilterExtension/ConfigNodes/customSubCategory.cs +++ b/FilterExtension/ConfigNodes/customSubCategory.cs @@ -26,7 +26,7 @@ public customSubCategory(ConfigNode node) iconName = node.GetValue("icon"); bool tmp; - bool.TryParse(node.GetValue("showUnPurchased"), out tmp); + bool.TryParse(node.GetValue("showUnpurchased"), out tmp); unPurchasedOverride = tmp; filters = new List(); @@ -49,6 +49,7 @@ public ConfigNode toConfigNode() node.AddValue("name", this.subCategoryTitle); node.AddValue("icon", this.iconName); + node.AddValue("showUnpurchased", this.unPurchasedOverride); foreach (Filter f in this.filters) node.AddNode(f.toConfigNode()); @@ -65,7 +66,6 @@ public bool checkFilters(AvailablePart part) if (!unPurchasedOverride && Core.Instance.hideUnpurchased && !ResearchAndDevelopment.PartModelPurchased(part) && !ResearchAndDevelopment.IsExperimentalPart(part)) return false; } - foreach (Filter f in filters) { if (f.checkFilter(part)) diff --git a/FilterExtension/Editor.cs b/FilterExtension/Editor.cs index 39e84c07..8e1c5ccd 100644 --- a/FilterExtension/Editor.cs +++ b/FilterExtension/Editor.cs @@ -13,6 +13,7 @@ namespace FilterExtensions class Editor : MonoBehaviour { public static Editor instance; + public bool ready = false; void Start() { instance = this; @@ -71,27 +72,27 @@ IEnumerator editorInit() { findPartsToBlock(); // not known until now which parts are never visible so some empty subcategories will be present - for (int i = 0; i < PartCategorizer.Instance.filters.Count; i++) - { - List subCatsToDelete = new List(); - PartCategorizer.Category C = PartCategorizer.Instance.filters[i]; - if (C == null) - continue; - for (int j = 0; j < C.subcategories.Count; j++) - { - PartCategorizer.Category sub = C.subcategories[j]; - if (sub == null) - continue; - - if (!PartLoader.Instance.parts.Any(p => sub.exclusionFilter.FilterCriteria.Invoke(p))) - subCatsToDelete.Add(sub); - } - for (int j = 0; j < subCatsToDelete.Count; j++) - { - PartCategorizer.Category sub = subCatsToDelete[j]; - C.subcategories.Remove(sub); - } - } + //for (int i = 0; i < PartCategorizer.Instance.filters.Count; i++) + //{ + // PartCategorizer.Category C = PartCategorizer.Instance.filters[i]; + // if (C == null) + // continue; + // int j = 0; + // while (j < C.subcategories.Count) + // { + // PartCategorizer.Category sub = C.subcategories[j]; + // if (sub == null) + // { + // j++; + // continue; + // } + + // if (!PartLoader.Instance.parts.Any(p => sub.exclusionFilter.FilterCriteria.Invoke(p))) + // C.subcategories.RemoveAt(j); + // else + // j++; + // } + //} } foreach (PartCategorizer.Category c in PartCategorizer.Instance.filters) Core.Instance.namesAndIcons(c); @@ -117,6 +118,8 @@ IEnumerator editorInit() if (Core.Instance.debug) Core.Log("Refreshing parts list"); Core.setSelectedCategory(); + + ready = true; } /// @@ -140,17 +143,15 @@ void findPartsToBlock() subCatsSeen.Add(subCat.button.categoryName); else // subcat created by another mod { - // can't remove parts from a collection being looped over, need to remember the visible parts - List visibleParts = new List(); - for (int j = 0; j < partsToCheck.Count; j++) + int j = 0; + while (j < partsToCheck.Count) { AvailablePart AP = partsToCheck[j]; if (subCat.exclusionFilter.FilterCriteria.Invoke(AP)) // if visible - visibleParts.Add(AP); + partsToCheck.RemoveAt(j); + else + j++; } - // remove all visible parts from the list to block - foreach (AvailablePart ap in visibleParts) - partsToCheck.Remove(ap); } } // add the blocked parts to a hashset for later lookup diff --git a/GameData/000_FilterExtensions/FilterExtensions.dll b/GameData/000_FilterExtensions/FilterExtensions.dll index 5d4ed8ad..42b42738 100644 Binary files a/GameData/000_FilterExtensions/FilterExtensions.dll and b/GameData/000_FilterExtensions/FilterExtensions.dll differ diff --git a/GameData/000_FilterExtensions/FilterExtensions.version b/GameData/000_FilterExtensions/FilterExtensions.version index 391357c6..532484f8 100644 --- a/GameData/000_FilterExtensions/FilterExtensions.version +++ b/GameData/000_FilterExtensions/FilterExtensions.version @@ -1 +1 @@ -{"NAME":"Filter Extensions","URL":"https://github.com/Crzyrndm/FilterExtension/blob/master/GameData/000_FilterExtensions/FilterExtensions.version","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":2,"MINOR":4,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":0,"PATCH":4}} \ No newline at end of file +{"NAME":"Filter Extensions","URL":"https://github.com/Crzyrndm/FilterExtension/blob/master/GameData/000_FilterExtensions/FilterExtensions.version","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":2,"MINOR":4,"PATCH":1,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":0,"PATCH":4}} \ No newline at end of file