diff --git a/FE_Testing/FE_Test_Script.cs b/FE_Testing/FE_Test_Script.cs new file mode 100644 index 00000000..9da7ab6f --- /dev/null +++ b/FE_Testing/FE_Test_Script.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Linq; +using System.Text; +using UnityEngine; +using KSP.UI.Screens; + +namespace FE_Testing +{ + [KSPAddon(KSPAddon.Startup.EditorAny, false)] + public class FE_Test_Script : MonoBehaviour + { + const string testCatName = "Testing"; + Dictionary partSubCatMap = new Dictionary() + { + { "By Category - Control", "asasmodule1-2" }, + { "By Check", "fuelTank3-2" }, + { "By Cost < 100", "basicFin" }, + { "By Crash Tolerance - 6.0m/s", "fuelTank3-2" }, + { "By Crew - 1", "Mark1Cockpit" }, + { "Unpurchased", "" }, + { "By Folder - Squad", "Mark1Cockpit" }, + { "Not Squad", "" }, + { "By Manufacturer - Ionic", "ionEngine" }, + { "By Mass - 500kg", "fuelTank4-2" }, + { "By Max Temp > 2k", "nuclearEngine" }, + { "By Module Name - ModuleEngines", "nuclearEngine" }, + { "By Module Name - !contains(ModuleEnginesFX & ModuleRCS)" , "basicFin" }, + { "By Module Title - Module Engines & Module Parachute", "nuclearEngine" }, + { "By Module Title 2 - !contains(Module Engines & Module Parachute)", "asasmodule1-2" }, + { "By Name - nosecone & rtg", "pointyNoseConeA" }, + { "By Path - Squad/Parts/FuelTank/", "fuelTank4-2" }, + { "By Profile - mk2", "mk2FuselageShortMono" }, + { "By Profile 2 - !contains(mk2 & mk1)", "basicFin" }, + { "By Propellant - LF", "nuclearEngine" }, + { "By Resource - LF", "fuelTankSmallFlat" }, + { "By Resource 2 - !contains(LF - Ox)", "mk2FuselageShortMono" }, + { "By Size - 1", "nuclearEngine" }, + { "By Size 2 - !contains(0-1-3)", "fuelTank4-2" }, + { "By Subcategory - By Resource", "fuelTank4-2" }, + { "By Tag - jet", "turboJet" }, + { "By Tag 2 - !contains(jet | only)", "nuclearEngine" }, + { "By Tech - experimentalElectronics", "rtg" }, + { "By Title - PB-NUK & Aerodynamic Nose Cone", "rtg" } + }; + + public void Start() + { + StartCoroutine(CheckTestSubcategories()); + } + + IEnumerator CheckTestSubcategories() + { + yield return new WaitForSeconds(5); // wait for the editor to complete startup + + PartCategorizer.Category testCat = PartCategorizer.Instance.filters.FirstOrDefault(C => C.button.categoryName == testCatName); + if (testCat == null) + { + LogTestResult($"Category named \"{testCatName}\" found", false); + yield break; + } + + foreach (PartCategorizer.Category testingSubCat in testCat.subcategories) + { + if (partSubCatMap.ContainsKey(testingSubCat.button.categoryName)) + { + LogTestResult(testingSubCat.button.categoryName, partExistsInSubCategory(partSubCatMap[testingSubCat.button.categoryName], testingSubCat)); + partSubCatMap.Remove(testingSubCat.button.categoryName); + } + } + + // anything that didn't run gets an automatic fail + foreach (var kvp in partSubCatMap) + { + LogTestResult(kvp.Key, false); + } + } + + void LogTestResult(string test, bool result) + { + if (result) + { + Debug.Log($"[FE Testing] {test} with part \"{partSubCatMap[test]}\": {result}"); + } + else + { + Debug.LogError($"[FE Testing] {test} with part \"{partSubCatMap[test]}\": {result}"); + } + } + + bool partExistsInSubCategory(string partID, PartCategorizer.Category toCheck) + { + AvailablePart part = PartLoader.LoadedPartsList.FirstOrDefault(ap => string.Equals(ap.name, partID, StringComparison.OrdinalIgnoreCase)); + if (part == null) + { + Debug.Log($"[FE Testing] could not find any part with the ID {partID}"); + return false; + } + return toCheck.exclusionFilter.FilterCriteria.Invoke(part); + } + } +} diff --git a/FE_Testing/FE_Testing.csproj b/FE_Testing/FE_Testing.csproj new file mode 100644 index 00000000..4c9eac5d --- /dev/null +++ b/FE_Testing/FE_Testing.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {F544880B-94BB-48C7-9331-76452A1AE9B7} + Library + Properties + FE_Testing + FE_Testing + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + none + true + ..\Testing\ + TRACE + prompt + 4 + + + Always + + + + ..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\Assembly-CSharp.dll + False + + + + + + + + + ..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\UnityEngine.dll + False + + + + + + + + + set SOURCE="D:\Libraries\GitHub\FilterExtension\Testing" +set DESTINATION="D:\Libraries\Desktop\Kerbal Space Program Dev\GameData\000_FilterExtensions Configs\Testing" +xcopy %25SOURCE%25 %25DESTINATION%25 /E /C /R /I /K /Y + + + \ No newline at end of file diff --git a/FE_Testing/Properties/AssemblyInfo.cs b/FE_Testing/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c7c18106 --- /dev/null +++ b/FE_Testing/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FE_Testing")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FE_Testing")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f544880b-94bb-48c7-9331-76452a1ae9b7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FilterExtension.sln b/FilterExtension.sln index d94a900b..f72a612c 100644 --- a/FilterExtension.sln +++ b/FilterExtension.sln @@ -1,9 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilterExtensions", "FilterExtension\FilterExtensions.csproj", "{8633A568-654E-409D-A7B2-95839F2EBD3D}" + ProjectSection(ProjectDependencies) = postProject + {F544880B-94BB-48C7-9331-76452A1AE9B7} = {F544880B-94BB-48C7-9331-76452A1AE9B7} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FE_Testing", "FE_Testing\FE_Testing.csproj", "{F544880B-94BB-48C7-9331-76452A1AE9B7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +20,10 @@ Global {8633A568-654E-409D-A7B2-95839F2EBD3D}.Debug|Any CPU.Build.0 = Debug|Any CPU {8633A568-654E-409D-A7B2-95839F2EBD3D}.Release|Any CPU.ActiveCfg = Release|Any CPU {8633A568-654E-409D-A7B2-95839F2EBD3D}.Release|Any CPU.Build.0 = Release|Any CPU + {F544880B-94BB-48C7-9331-76452A1AE9B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F544880B-94BB-48C7-9331-76452A1AE9B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F544880B-94BB-48C7-9331-76452A1AE9B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F544880B-94BB-48C7-9331-76452A1AE9B7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FilterExtension/ConfigNodes/customSubCategory.cs b/FilterExtension/ConfigNodes/customSubCategory.cs index 05a010ca..99b52d77 100644 --- a/FilterExtension/ConfigNodes/customSubCategory.cs +++ b/FilterExtension/ConfigNodes/customSubCategory.cs @@ -24,6 +24,10 @@ public bool hasFilters public customSubCategory(ConfigNode node) { subCategoryTitle = node.GetValue("name"); + if (subCategoryTitle == string.Empty) + { + subCategoryTitle = node.GetValue("categoryName"); // for playing nice with stock generated subcats + } iconName = node.GetValue("icon"); bool tmp; @@ -35,6 +39,13 @@ public customSubCategory(ConfigNode node) { filters.Add(new Filter(subNode)); } + foreach (ConfigNode subNode in node.GetNodes("PARTS")) + { + Check ch = new Check("name", string.Join(",", subNode.GetValues("part"))); + Filter f = new Filter(false); + f.checks.Add(ch); + filters.Add(f); + } template = new List(); } diff --git a/FilterExtension/Core.cs b/FilterExtension/Core.cs index 5bde2307..048d9c62 100644 --- a/FilterExtension/Core.cs +++ b/FilterExtension/Core.cs @@ -14,7 +14,7 @@ namespace FilterExtensions [KSPAddon(KSPAddon.Startup.MainMenu, true)] public class Core : MonoBehaviour { - public static readonly Version version = new Version(2, 7, 0, 0); + public static readonly Version version = new Version(2, 7, 1, 0); private static Core instance; public static Core Instance diff --git a/FilterExtension/FilterExtensions.csproj b/FilterExtension/FilterExtensions.csproj index 212dd945..91d43255 100644 --- a/FilterExtension/FilterExtensions.csproj +++ b/FilterExtension/FilterExtensions.csproj @@ -77,10 +77,6 @@ set SOURCE="D:\Libraries\GitHub\FilterExtension\GameData" set DESTINATION="D:\Libraries\Desktop\Kerbal Space Program Dev\GameData" -xcopy %25SOURCE%25 %25DESTINATION%25 /E /C /R /I /K /Y - -set SOURCE="D:\Libraries\GitHub\FilterExtension\Testing" -set DESTINATION="D:\Libraries\Desktop\Kerbal Space Program Dev\GameData\000_FilterExtensions Configs\Testing" xcopy %25SOURCE%25 %25DESTINATION%25 /E /C /R /I /K /Y