diff --git a/.gitignore b/.gitignore index 9e31baec..4f78d610 100644 --- a/.gitignore +++ b/.gitignore @@ -196,5 +196,4 @@ FakesAssemblies/ *.opt PartDatabase.cfg -Physics.cfg -Testing/ \ No newline at end of file +Physics.cfg \ No newline at end of file diff --git a/FilterExtension/ConfigNodes/Check.cs b/FilterExtension/ConfigNodes/Check.cs index 66a309f2..eebef961 100644 --- a/FilterExtension/ConfigNodes/Check.cs +++ b/FilterExtension/ConfigNodes/Check.cs @@ -77,12 +77,12 @@ public Check(ConfigNode node) } } - switch (node.GetValue("equality")) + switch (node.GetValue("equality").ToLower()) { - case "LessThan": + case "lessthan": equality = Equality.LessThan; break; - case "GreaterThan": + case "greaterthan": equality = Equality.GreaterThan; break; default: @@ -105,7 +105,7 @@ public Check(Check c) public Check(string type, string value, bool invert = false, bool contains = true, Equality compare = Equality.Equals) { - this.type = getType(type); + this.type = getType(type.ToLowerInvariant()); this.value = value.Split(','); for (int i = 0; i < this.value.Length; ++i) this.value[i] = this.value[i].Trim(); @@ -181,7 +181,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 = Editor.instance.ready ? PartType.checkCustom(part, value) : !invert; + result = PartType.checkCustom(part, value); break; case CheckType.mass: result = PartType.checkMass(part, value, equality); @@ -233,9 +233,9 @@ public static CheckType getType(string type) return CheckType.partName; case "title": return CheckType.partTitle; - case "moduleName": + case "modulename": return CheckType.moduleName; - case "moduleTitle": + case "moduletitle": return CheckType.moduleTitle; case "resource": return CheckType.resource; @@ -263,7 +263,7 @@ public static CheckType getType(string type) return CheckType.cost; case "crash": return CheckType.crashTolerance; - case "maxTemp": + case "maxtemp": return CheckType.maxTemp; case "profile": return CheckType.profile; @@ -291,9 +291,9 @@ public static string getTypeString(CheckType type) case CheckType.partTitle: return "title"; case CheckType.moduleName: - return "moduleName"; + return "modulename"; case CheckType.moduleTitle: - return "moduleTitle"; + return "moduletitle"; case CheckType.resource: return "resource"; case CheckType.propellant: @@ -321,7 +321,7 @@ public static string getTypeString(CheckType type) case CheckType.crashTolerance: return "crash"; case CheckType.maxTemp: - return "maxTemp"; + return "maxtemp"; case CheckType.profile: return "profile"; case CheckType.check: diff --git a/FilterExtension/Utility/PartType.cs b/FilterExtension/Utility/PartType.cs index 035c262f..9e735286 100644 --- a/FilterExtension/Utility/PartType.cs +++ b/FilterExtension/Utility/PartType.cs @@ -41,7 +41,7 @@ public static bool checkCustom(AvailablePart part, string[] value) testVal = isMultiCoupler(part); break; case "purchased": - testVal = ResearchAndDevelopment.PartModelPurchased(part); + testVal = !Editor.instance.ready || ResearchAndDevelopment.PartModelPurchased(part); break; } if (testVal) @@ -106,16 +106,9 @@ public static bool checkModuleTitle(AvailablePart part, string[] value, bool con if (part.moduleInfos == null) return false; if (contains) - value.Any(s => part.moduleInfos.Any(m => s == m.moduleName)); + return part.moduleInfos.Any(m => value.Contains(m.moduleName)); else - { - foreach (AvailablePart.ModuleInfo i in part.moduleInfos) - { - if (!value.Contains(i.moduleName)) - return true; - } - } - return false; + return part.moduleInfos.Any(m => !value.Contains(m.moduleName)); } public static bool checkModuleName(AvailablePart part, string[] value, bool contains = true) @@ -125,17 +118,7 @@ public static bool checkModuleName(AvailablePart part, string[] value, bool cont if (contains) return value.Any(s => checkModuleNameType(part, s) || part.partPrefab.Modules.Contains(s)); else - { - foreach (PartModule module in part.partPrefab.Modules) - { - foreach (string s in value) - { - if (s != module.ClassName.Replace('.', '_')) - return true; - } - } - return false; - } + return value.Any(s => !checkModuleNameType(part, s) && !part.partPrefab.Modules.Contains(s)); } public static bool checkModuleNameType(AvailablePart part, string value) @@ -361,12 +344,12 @@ public static bool checkPropellant(AvailablePart part, string[] value, bool cont public static bool checkTech(AvailablePart part, string[] value) { - return value.Any(s => part.TechRequired == s); + return value.Contains(part.TechRequired); } public static bool checkManufacturer(AvailablePart part, string[] value) { - return value.Any(s => part.manufacturer == s); + return value.Contains(part.manufacturer); } public static bool checkFolder(AvailablePart part, string[] value) @@ -374,8 +357,8 @@ public static bool checkFolder(AvailablePart part, string[] value) string path; if (Core.Instance.partPathDict.TryGetValue(part.name, out path)) { - string folder = path.Split(new char[] { '\\', '/' })[0]; - return value.Any(s => s == folder); + string folder = path.Split(new char[] { '\\', '/' }, 2)[0]; + return value.Contains(folder); } return false; } diff --git a/GameData/000_FilterExtensions Configs/Testing/ByCategory.cfg b/GameData/000_FilterExtensions Configs/Testing/ByCategory.cfg new file mode 100644 index 00000000..a5818c16 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByCategory.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Category + FILTER + { + CHECK + { + type = category + value = Control + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Category + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByCheck.cfg b/GameData/000_FilterExtensions Configs/Testing/ByCheck.cfg new file mode 100644 index 00000000..bc844b5b --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByCheck.cfg @@ -0,0 +1,33 @@ +SUBCATEGORY +{ + name = By Check + FILTER + { + // !(part.Has(Oxidizer) && part.mass > 1) + CHECK + { + ///////////// normally doing !(A && B) or some other combinations is a little awkward/long winded. Check types group checks together to make that simpler + type = check + invert = true + CHECK + { + type = resource + value = Oxidizer + } + CHECK + { + type = mass + value = 1 + equality = greaterThan + } + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Check + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByCost.cfg b/GameData/000_FilterExtensions Configs/Testing/ByCost.cfg new file mode 100644 index 00000000..f7ca8bd7 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByCost.cfg @@ -0,0 +1,21 @@ +SUBCATEGORY +{ + name = By Cost + FILTER + { + CHECK + { + type = cost + value = 100 + equality = lessThan // case insensitive + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Cost + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByCrashTolerance.cfg b/GameData/000_FilterExtensions Configs/Testing/ByCrashTolerance.cfg new file mode 100644 index 00000000..07972c11 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByCrashTolerance.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Crash Tolerance + FILTER + { + CHECK + { + type = crash + value = 6 + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Crash Tolerance + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByCrew.cfg b/GameData/000_FilterExtensions Configs/Testing/ByCrew.cfg new file mode 100644 index 00000000..16484d94 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByCrew.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Crew + FILTER + { + CHECK + { + type = crew + value = 1 + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Crew + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByCustomUnpurchased.cfg b/GameData/000_FilterExtensions Configs/Testing/ByCustomUnpurchased.cfg new file mode 100644 index 00000000..e0111dd3 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByCustomUnpurchased.cfg @@ -0,0 +1,22 @@ +SUBCATEGORY +{ + name = Unpurchased + showUnpurchased = true + FILTER + { + CHECK + { + type = custom + value = purchased + invert = true + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = Unpurchased + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByFolder.cfg b/GameData/000_FilterExtensions Configs/Testing/ByFolder.cfg new file mode 100644 index 00000000..06c8dbe2 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByFolder.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Folder + FILTER + { + CHECK + { + type = folder + value = Squad + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Folder + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByFolderNoTemplate.cfg b/GameData/000_FilterExtensions Configs/Testing/ByFolderNoTemplate.cfg new file mode 100644 index 00000000..fd8cbed4 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByFolderNoTemplate.cfg @@ -0,0 +1,21 @@ +SUBCATEGORY +{ + name = Not Squad + FILTER + { + CHECK + { + type = folder + value = Squad + invert = true + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = Not Squad, dont template + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByManufacturer.cfg b/GameData/000_FilterExtensions Configs/Testing/ByManufacturer.cfg new file mode 100644 index 00000000..1f6597fe --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByManufacturer.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Manufacturer + FILTER + { + CHECK + { + type = manufacturer + value = Ionic Symphonic Protonic Electronics + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Manufacturer + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByMass.cfg b/GameData/000_FilterExtensions Configs/Testing/ByMass.cfg new file mode 100644 index 00000000..3e8f830d --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByMass.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Mass + FILTER + { + CHECK + { + type = mass // dry mass + value = 0.5 + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Mass + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByMaxTemp.cfg b/GameData/000_FilterExtensions Configs/Testing/ByMaxTemp.cfg new file mode 100644 index 00000000..3f064ef7 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByMaxTemp.cfg @@ -0,0 +1,21 @@ +SUBCATEGORY +{ + name = By Max Temp + FILTER + { + CHECK + { + type = maxTemp + value = 2000 + equality = greaterThan + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Max Temp + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByModuleName.cfg b/GameData/000_FilterExtensions Configs/Testing/ByModuleName.cfg new file mode 100644 index 00000000..234fae14 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByModuleName.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Module Name + FILTER + { + CHECK + { + type = moduleName + value = ModuleEngines // moduleName can find inherited modules for stock part modules (eg. ModuleEnginesFX) + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Module Name + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByModuleTitle.cfg b/GameData/000_FilterExtensions Configs/Testing/ByModuleTitle.cfg new file mode 100644 index 00000000..348c6814 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByModuleTitle.cfg @@ -0,0 +1,22 @@ +SUBCATEGORY +{ + name = By Module Title + FILTER + { + CHECK + { + ///////////////////////// type = moduleTitle + type = MoDuLeTiTlE // case doesn't matter, it just makes it horribly unreadable + value = Module Engines, Module Parachute + // Module title doesn't attempt to use inheritance, so no ModuleEnginesFX here + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Module Title + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByName.cfg b/GameData/000_FilterExtensions Configs/Testing/ByName.cfg new file mode 100644 index 00000000..debbde13 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByName.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Name + FILTER + { + CHECK + { + type = name + value = nosecone, rtg + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Name + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByPath.cfg b/GameData/000_FilterExtensions Configs/Testing/ByPath.cfg new file mode 100644 index 00000000..9d0d4c39 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByPath.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Path + FILTER + { + CHECK + { + type = path + value = Squad/Parts/FuelTank/ + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Path + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByProfile.cfg b/GameData/000_FilterExtensions Configs/Testing/ByProfile.cfg new file mode 100644 index 00000000..4e9f1338 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByProfile.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Profile + FILTER + { + CHECK + { + type = profile + value = mk2 + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Profile + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByPropellant.cfg b/GameData/000_FilterExtensions Configs/Testing/ByPropellant.cfg new file mode 100644 index 00000000..b6bfffc9 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByPropellant.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Propellant + FILTER + { + CHECK + { + type = propellant + value = LiquidFuel + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Propellant + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByResource.cfg b/GameData/000_FilterExtensions Configs/Testing/ByResource.cfg new file mode 100644 index 00000000..62945dfc --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByResource.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Resource + FILTER + { + CHECK + { + type = resource + value = LiquidFuel + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Resource + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/BySize.cfg b/GameData/000_FilterExtensions Configs/Testing/BySize.cfg new file mode 100644 index 00000000..41264d11 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/BySize.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Size + FILTER + { + CHECK + { + type = size + value = 1 + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Size + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/BySubcategory.cfg b/GameData/000_FilterExtensions Configs/Testing/BySubcategory.cfg new file mode 100644 index 00000000..385bd8e6 --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/BySubcategory.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Subcategory + FILTER + { + CHECK + { + type = subcategory + value = By Resource + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Subcategory + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByTech.cfg b/GameData/000_FilterExtensions Configs/Testing/ByTech.cfg new file mode 100644 index 00000000..8dfe2b0f --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByTech.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Tech + FILTER + { + CHECK + { + type = tech + value = experimentalElectrics + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Tech + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/ByTitle.cfg b/GameData/000_FilterExtensions Configs/Testing/ByTitle.cfg new file mode 100644 index 00000000..cc20150f --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/ByTitle.cfg @@ -0,0 +1,20 @@ +SUBCATEGORY +{ + name = By Title + FILTER + { + CHECK + { + type = title + value = PB-NUK, Aerodynamic Nose Cone + } + } +} + +@CATEGORY[Testing] +{ + @SUBCATEGORIES + { + list = By Title + } +} \ No newline at end of file diff --git a/GameData/000_FilterExtensions Configs/Testing/TestCategory.cfg b/GameData/000_FilterExtensions Configs/Testing/TestCategory.cfg new file mode 100644 index 00000000..9f90b80b --- /dev/null +++ b/GameData/000_FilterExtensions Configs/Testing/TestCategory.cfg @@ -0,0 +1,18 @@ +CATEGORY +{ + name = Testing + + FILTER + { + CHECK + { + type = folder + value = Squad + } + } + + SUBCATEGORIES + { + list = dummy + } +} \ No newline at end of file