diff --git a/FilterExtension/Categoriser/PartType.cs b/FilterExtension/Categoriser/PartType.cs index d64f1304..b286c31a 100644 --- a/FilterExtension/Categoriser/PartType.cs +++ b/FilterExtension/Categoriser/PartType.cs @@ -140,22 +140,20 @@ internal static bool checkPropellant(AvailablePart part, string value) if (categoryCheck(part)) return false; - List propellants = new List(); - if (part.partPrefab.GetModuleEngines() != null) - { - propellants = part.partPrefab.GetModuleEngines().propellants; - } - else if (part.partPrefab.GetModuleEnginesFx() != null) - { - propellants = part.partPrefab.GetModuleEnginesFx().propellants; - } - else - return false; + List> propellants = new List>(); + + foreach (ModuleEngines e in part.partPrefab.GetModuleEngines()) + propellants.Add(e.propellants); + foreach (ModuleEnginesFX ex in part.partPrefab.GetModuleEnginesFx()) + propellants.Add(ex.propellants); - foreach (string s in value.Split(',')) + foreach (List Lp in propellants) { - if (propellants.Any(p => p.name == s.Trim())) - return true; + foreach (string s in value.Split(',')) + { + if (Lp.Any(p => p.name == s.Trim())) + return true; + } } return false; } @@ -310,19 +308,24 @@ public static bool isWing(AvailablePart part) return false; } + public static List GetModules(this Part part) where T : PartModule + { + return part.Modules.OfType().ToList(); + } + public static T GetModule(this Part part) where T : PartModule { return part.Modules.OfType().FirstOrDefault(); } - public static ModuleEngines GetModuleEngines(this Part part) + public static List GetModuleEngines(this Part part) { - return part.GetModule(); + return part.GetModules(); } - public static ModuleEnginesFX GetModuleEnginesFx(this Part part) + public static List GetModuleEnginesFx(this Part part) { - return part.GetModule(); + return part.GetModules(); } } } diff --git a/FilterExtension/Core.cs b/FilterExtension/Core.cs index 8336e86e..7b0cddc4 100644 --- a/FilterExtension/Core.cs +++ b/FilterExtension/Core.cs @@ -20,12 +20,17 @@ public class Core : MonoBehaviour // mod folder for each part by internal name public static Dictionary partFolderDict = new Dictionary(); + + // store all the "All parts" subcategories until all subcategories have been processed + internal Dictionary categoryAllSub = new Dictionary(); // store the config node for the "all" subcategories until all filters have been added + + // state is set on initialisation starting and finishing. This way we know whether a problem was encountered and if it was a problem related to FE internal static int state = 0; // 0 = we haven't started yet, 1 = processing started, -1 = processing finished, 2 = processing reattempted // Dictionary of icons created on entering the main menu public static Dictionary iconDict = new Dictionary(); - public static Core Instance + public static Core Instance // Reminder to self, don't be abusing static { get { @@ -36,7 +41,7 @@ public static Core Instance void Awake() { instance = this; - Log("Version 1.13"); + Log("Version 1.14"); // Add event for when the Editor GUI becomes active. This is never removed because we need it to fire every time GameEvents.onGUIEditorToolbarReady.Add(editor); @@ -85,6 +90,24 @@ void Awake() subCategories.Add(sC); } } + + foreach (KeyValuePair kvp in categoryAllSub) + { + ConfigNode sC = kvp.Value; + if (folderToCategoryDict.ContainsKey(kvp.Key)) + { + foreach (ConfigNode node in sC.GetNodes("FILTER")) + { + ConfigNode nodeCheck = new ConfigNode("CHECK"); + nodeCheck.AddValue("type", "folder"); + nodeCheck.AddValue("value", folderToCategoryDict[kvp.Key]); + node.AddNode(nodeCheck); + } + } + + subCategories.Insert(0, new customSubCategory(sC, kvp.Key)); + } + checkForEmptySubCategories(); loadIcons(); } diff --git a/FilterExtension/customCategory.cs b/FilterExtension/customCategory.cs index 7ca700b2..10be1e29 100644 --- a/FilterExtension/customCategory.cs +++ b/FilterExtension/customCategory.cs @@ -30,8 +30,19 @@ public customCategory(ConfigNode node) type = node.GetValue("type"); value = node.GetValue("value"); - // not hooked up to anything - bool.TryParse(node.GetValue("all"), out all); + if (bool.TryParse(node.GetValue("all"), out all)) + { + if (!Core.Instance.categoryAllSub.ContainsKey(categoryTitle)) + { + // create confignode for an "All parts" subcategory + ConfigNode c = new ConfigNode("SUBCATEGORY"); + c.AddValue("name", "All Parts in Category"); + c.AddValue("category", categoryTitle); + c.AddValue("icon", iconName); + // add it to the dictionary + Core.Instance.categoryAllSub.Add(categoryTitle, c); + } + } typeSwitch(); } diff --git a/FilterExtension/customSubCategory.cs b/FilterExtension/customSubCategory.cs index edf1cb9e..04e0079d 100644 --- a/FilterExtension/customSubCategory.cs +++ b/FilterExtension/customSubCategory.cs @@ -27,6 +27,10 @@ public customSubCategory(ConfigNode node, string Category) foreach (ConfigNode subNode in node.GetNodes("FILTER")) { filters.Add(new Filter(subNode)); + + // if there's an "All parts" subcategory, add the filters to it + if (Core.Instance.categoryAllSub.ContainsKey(category)) + Core.Instance.categoryAllSub[category].AddNode(subNode); } filter = filters.Count > 0; } diff --git a/GameData/000_FilterExtensions/Configs/003_Category_ModFolders/Near Future Technologies.cfg b/GameData/000_FilterExtensions/Configs/003_Category_ModFolders/Near Future Technologies.cfg index f0d04f4d..8ed7f087 100644 --- a/GameData/000_FilterExtensions/Configs/003_Category_ModFolders/Near Future Technologies.cfg +++ b/GameData/000_FilterExtensions/Configs/003_Category_ModFolders/Near Future Technologies.cfg @@ -5,4 +5,5 @@ CATEGORY:NEEDS[NearFuturePropulsion|NearFutureElectrical|NearFutureConstruction| colour = #FFF0F0F0 type = mod value = NearFuturePropulsion, NearFutureElectrical, NearFutureConstruction, NearFutureSolar, NearFutureSpacecraft + all = true } \ No newline at end of file diff --git a/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/003_EngineJet.cfg b/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/003_EngineJet.cfg index 550d62f8..11f289f5 100644 --- a/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/003_EngineJet.cfg +++ b/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/003_EngineJet.cfg @@ -13,8 +13,7 @@ SUBCATEGORY CHECK { type = propellant - value = Oxidizer - invert = true + value = IntakeAir } } } \ No newline at end of file diff --git a/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/051_Solar Panels.cfg b/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/051_Solar Panels.cfg index 59964149..90b86d09 100644 --- a/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/051_Solar Panels.cfg +++ b/GameData/000_FilterExtensions/Configs/Category_Filter_by_Function/051_Solar Panels.cfg @@ -11,4 +11,12 @@ SUBCATEGORY value = ModuleDeployableSolarPanel } } + FILTER + { + CHECK + { + type = moduleName + value = ModuleCurvedSolarPanel + } + } } \ No newline at end of file diff --git a/GameData/000_FilterExtensions/Configs/Category_Filter_by_Module/Connected Living Space.cfg b/GameData/000_FilterExtensions/Configs/Category_Filter_by_Module/Connected Living Space.cfg index e4f1c07d..0b020330 100644 --- a/GameData/000_FilterExtensions/Configs/Category_Filter_by_Module/Connected Living Space.cfg +++ b/GameData/000_FilterExtensions/Configs/Category_Filter_by_Module/Connected Living Space.cfg @@ -1,4 +1,4 @@ -SUBCATEGORY +SUBCATEGORY:NEEDS[ConnectedLivingSpace] { category = Filter by Module name = Connected Living Space diff --git a/GameData/000_FilterExtensions/FilterCreator.dll b/GameData/000_FilterExtensions/FilterCreator.dll index f547898d..38a90626 100644 Binary files a/GameData/000_FilterExtensions/FilterCreator.dll and b/GameData/000_FilterExtensions/FilterCreator.dll differ diff --git a/GameData/000_FilterExtensions/FilterExtensions.dll b/GameData/000_FilterExtensions/FilterExtensions.dll index 7249730e..10924479 100644 Binary files a/GameData/000_FilterExtensions/FilterExtensions.dll and b/GameData/000_FilterExtensions/FilterExtensions.dll differ