diff --git a/Filter Extensions v2.0.2.zip b/Filter Extensions v2.0.2.zip new file mode 100644 index 00000000..27e25a27 Binary files /dev/null and b/Filter Extensions v2.0.2.zip differ diff --git a/FilterExtension/ConfigNodes/customCategory.cs b/FilterExtension/ConfigNodes/customCategory.cs index 51d206d3..e548ffca 100644 --- a/FilterExtension/ConfigNodes/customCategory.cs +++ b/FilterExtension/ConfigNodes/customCategory.cs @@ -178,12 +178,9 @@ private void generateEngineTypes() checks.Add(new Check("propellant", props)); checks.Add(new Check("propellant", props, true, false)); // exact match to propellant list. Nothing extra, nothing less - string name = props.Replace(',', '/'); - string icon = props; - if (Core.Instance.proceduralNames.ContainsKey(name)) - name = Core.Instance.proceduralNames[name]; - if (Core.Instance.proceduralIcons.ContainsKey(name)) - icon = Core.Instance.proceduralIcons[name]; + string name = props.Replace(',', '/'); // can't use ',' as a delimiter in the procedural name/icon switch function + string icon = name; + Core.Instance.proceduralNameandIcon(ref name, ref icon); if (!Core.Instance.subCategoriesDict.ContainsKey(name)) { diff --git a/FilterExtension/Core.cs b/FilterExtension/Core.cs index bc93521f..14dee944 100644 --- a/FilterExtension/Core.cs +++ b/FilterExtension/Core.cs @@ -50,7 +50,7 @@ void Awake() { instance = this; DontDestroyOnLoad(this); - Log("Version 2.0"); + Log("Version 2.0.2"); config = KSP.IO.PluginConfiguration.CreateForType(); config.load(); @@ -122,10 +122,7 @@ void Awake() // add spaces before each capital letter string name = System.Text.RegularExpressions.Regex.Replace(s, @"\B([A-Z])", " $1"); string icon = ""; - if (proceduralNames.ContainsKey(name)) - name = proceduralNames[name]; - if (proceduralIcons.ContainsKey(name)) - icon = proceduralIcons[name]; + proceduralNameandIcon(ref name, ref icon); if (name != null && !subCategoriesDict.ContainsKey(name)) { customSubCategory sC = new customSubCategory(name, icon); @@ -233,10 +230,7 @@ private void processFilterByManufacturer(List modNames) { string name = modNames[i]; string icon = modNames[i]; - if (proceduralNames.ContainsKey(name)) - name = proceduralNames[name]; - if (proceduralIcons.ContainsKey(name)) - icon = proceduralIcons[name]; + proceduralNameandIcon(ref name, ref icon); Check ch = new Check("folder", modNames[i]); Filter f = new Filter(false); @@ -270,14 +264,8 @@ private void processFilterByManufacturer(List modNames) private bool stringListComparer(List propellants) { foreach (List ls in propellantCombos) - { - if (propellants.Count == ls.Count) - { - List tmp = propellants.Except(ls).ToList(); - if (!tmp.Any()) - return true; - } - } + if (propellants.Count == ls.Count && !propellants.Except(ls).Any()) + return true; return false; } @@ -285,23 +273,15 @@ internal void editor() { // Add all the categories foreach (customCategory c in Categories) - { if (!c.stockCategory) c.initialise(); - } - // icon autoloader pass foreach (PartCategorizer.Category c in PartCategorizer.Instance.filters) - { checkIcons(c); - } - // update icons setSelectedCategory(); - // Remove any category with no subCategories (causes major breakages). Removal doesn't actually prevent icon showing (>.<), just breakages PartCategorizer.Instance.filters.RemoveAll(c => c.subcategories.Count == 0); - // reveal categories because why not PartCategorizer.Instance.SetAdvancedMode(); } @@ -314,9 +294,7 @@ public void setSelectedCategory() Filter = PartCategorizer.Instance.filters.Find(f => f.button.categoryName == config.GetValue("categoryDefault", "Filter by Function")); if (Filter != null) - { Filter.button.activeButton.SetTrue(Filter.button.activeButton, RUIToggleButtonTyped.ClickType.FORCED); - } else { Filter = PartCategorizer.Instance.filters[0]; @@ -377,10 +355,7 @@ private void checkIcons(PartCategorizer.Category category) private static void loadIcons() { - List texList = GameDatabase.Instance.databaseTexture.Where(t => t.texture != null - && t.texture.height <= 40 && t.texture.width <= 40 - && t.texture.width >= 25 && t.texture.height >= 25 - ).ToList(); + List texList = GameDatabase.Instance.databaseTexture.Where(t => t.texture != null && t.texture.height <= 40 && t.texture.width <= 40 && t.texture.width >= 25 && t.texture.height >= 25).ToList(); Dictionary texDict = new Dictionary(); // using a dictionary for looking up _selected textures. Else the list has to be iterated over for every texture @@ -404,7 +379,6 @@ private static void loadIcons() foreach (GameDatabase.TextureInfo t in texList) { Texture2D selectedTex = null; - if (texDict.ContainsKey(t.name + "_selected")) selectedTex = texDict[t.name + "_selected"].texture; else @@ -421,11 +395,11 @@ private static void loadIcons() Log("Duplicated texture name \"" + t.name.Split(new char[] { '/', '\\' }).Last() + "\" at:\r\n" + t.name + "\r\n New reference is: " + name); } - PartCategorizer.Icon icon = new PartCategorizer.Icon(name, t.texture, selectedTex, false); - - // shouldn't be neccesary to check, but just in case... - if (!Instance.iconDict.ContainsKey(icon.name)) + if (!Instance.iconDict.ContainsKey(name)) + { + PartCategorizer.Icon icon = new PartCategorizer.Icon(name, t.texture, selectedTex, false); Instance.iconDict.Add(icon.name, icon); + } } } @@ -444,29 +418,32 @@ public static PartCategorizer.Icon getIcon(string name) private void RepairAvailablePartUrl(AvailablePart ap) { var url = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(u => u.name.Replace('_', '.') == ap.name); - if (url == null) return; - ap.partUrl = url.url; } public static bool checkSubCategoryHasParts(customSubCategory sC) { foreach (AvailablePart p in PartLoader.Instance.parts) - { if (sC.checkFilters(p)) - { return true; - } - } + Log(sC.subCategoryTitle + " has no valid parts and was not initialised"); return false; } + public void proceduralNameandIcon(ref string name, ref string icon) + { + if (proceduralNames.ContainsKey(name)) + name = proceduralNames[name]; + if (proceduralIcons.ContainsKey(name)) + icon = proceduralIcons[name]; + } + internal static void Log(object o) { Debug.Log("[Filter Extensions] " + o); } } -} +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions/FilterExtensions.dll b/GameData/000_FilterExtensions/FilterExtensions.dll index b4381b88..18997e84 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 31925a54..c40b064e 100644 --- a/GameData/000_FilterExtensions/FilterExtensions.version +++ b/GameData/000_FilterExtensions/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":2,"MINOR":0,"PATCH":1,"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":2,"MINOR":0,"PATCH":2,"BUILD":0},"KSP_VERSION":{"MAJOR":0,"MINOR":90,"PATCH":0}} \ No newline at end of file