Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
fix not finding ore tanks, add parsing of stock subcats, add test aut…
Browse files Browse the repository at this point in the history
…omation
  • Loading branch information
Crzyrndm committed Oct 14, 2016
1 parent 2aaf130 commit 0bb0970
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 17 deletions.
103 changes: 103 additions & 0 deletions FE_Testing/FE_Test_Script.cs
Original file line number Diff line number Diff line change
@@ -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<string, string> partSubCatMap = new Dictionary<string, string>()
{
{ "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);
}
}
}
69 changes: 69 additions & 0 deletions FE_Testing/FE_Testing.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F544880B-94BB-48C7-9331-76452A1AE9B7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FE_Testing</RootNamespace>
<AssemblyName>FE_Testing</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Testing\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FE_Test_Script.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>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</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions FE_Testing/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
13 changes: 11 additions & 2 deletions FilterExtension.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions FilterExtension/ConfigNodes/customSubCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Filter>();
}

Expand Down
2 changes: 1 addition & 1 deletion FilterExtension/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions FilterExtension/FilterExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
<PropertyGroup>
<PostBuildEvent>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</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
3 changes: 1 addition & 2 deletions FilterExtension/Utility/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public static bool checkResource(AvailablePart part, string[] values, bool conta
{
if (part.partPrefab.Resources == null)
return false;
return Contains(values, part.partPrefab.Resources, r => r.resourceName, r => r.amount > 0, contains, exact);
return Contains(values, part.partPrefab.Resources, r => r.resourceName, contains, exact);
}

/// <summary>
Expand Down Expand Up @@ -589,7 +589,6 @@ public static bool checkTags(AvailablePart part, string[] values, bool contains
{
if (string.IsNullOrEmpty(part.tags))
return false;

return Contains(values, part.tags.Split(new char[4] { ' ', ',', '|', ';' }, StringSplitOptions.RemoveEmptyEntries), contains, exact);
}

Expand Down
30 changes: 29 additions & 1 deletion GameData/000_FilterExtensions Configs/SubCategories_Stock.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ SUBCATEGORY
CHECK
{
type = moduleName
value = ModuleCommand, ModuleEngines, ModuleEnginesFX, ModuleGenerator, ModuleRadioisotopeGenerator
value = ModuleCommand, ModuleEngines, ModuleGenerator, ModuleRadioisotopeGenerator
invert = true
}
}
Expand Down Expand Up @@ -311,4 +311,32 @@ SUBCATEGORY
value = IntakeAir
}
}
}
SUBCATEGORY
{
name = Ablator
icon = Ablative_Shield

FILTER
{
CHECK
{
type = resource
value = XenonGas
}
}
}
SUBCATEGORY
{
name = Ore
icon = fuels_ore

FILTER
{
CHECK
{
type = resource
value = XenonGas
}
}
}
Binary file modified GameData/000_FilterExtensions/FilterExtensions.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/000_FilterExtensions/FilterExtensions.version
Original file line number Diff line number Diff line change
@@ -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":7,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":2,"PATCH":0}}
{"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":7,"PATCH":1,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":2,"PATCH":0}}
12 changes: 6 additions & 6 deletions Testing/ByTag.cfg
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
SUBCATEGORY
{
name = By Tag - mk2
name = By Tag - jet
FILTER
{
CHECK
{
type = tag
value = (more
value = jet
}
}
}

SUBCATEGORY
{
name = By Tag 2 - !contains(mk1 mk2)
name = By Tag 2 - !contains(jet | only)
FILTER
{
CHECK
{
type = tag
value = (more, moar
value = jet, only
contains = false
}
}
Expand All @@ -29,7 +29,7 @@ SUBCATEGORY
{
@SUBCATEGORIES
{
list = By Tag - mk2
list = By Tag 2 - !contains(mk1 mk2)
list = By Tag - jet
list = By Tag 2 - !contains(jet | only)
}
}
Binary file added Testing/FE_Testing.dll
Binary file not shown.

0 comments on commit 0bb0970

Please sign in to comment.