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

Commit

Permalink
unignore testing cfgs, a few fixes to check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Feb 21, 2016
1 parent 128bbaa commit 3280a3a
Show file tree
Hide file tree
Showing 26 changed files with 498 additions and 38 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,4 @@ FakesAssemblies/
*.opt

PartDatabase.cfg
Physics.cfg
Testing/
Physics.cfg
22 changes: 11 additions & 11 deletions FilterExtension/ConfigNodes/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
33 changes: 8 additions & 25 deletions FilterExtension/Utility/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -361,21 +344,21 @@ 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)
{
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;
}
Expand Down
20 changes: 20 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByCategory.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SUBCATEGORY
{
name = By Category
FILTER
{
CHECK
{
type = category
value = Control
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Category
}
}
33 changes: 33 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByCheck.cfg
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 21 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByCost.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SUBCATEGORY
{
name = By Cost
FILTER
{
CHECK
{
type = cost
value = 100
equality = lessThan // case insensitive
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Cost
}
}
20 changes: 20 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByCrashTolerance.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SUBCATEGORY
{
name = By Crash Tolerance
FILTER
{
CHECK
{
type = crash
value = 6
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Crash Tolerance
}
}
20 changes: 20 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByCrew.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SUBCATEGORY
{
name = By Crew
FILTER
{
CHECK
{
type = crew
value = 1
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Crew
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SUBCATEGORY
{
name = Unpurchased
showUnpurchased = true
FILTER
{
CHECK
{
type = custom
value = purchased
invert = true
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = Unpurchased
}
}
20 changes: 20 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByFolder.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SUBCATEGORY
{
name = By Folder
FILTER
{
CHECK
{
type = folder
value = Squad
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Folder
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SUBCATEGORY
{
name = Not Squad
FILTER
{
CHECK
{
type = folder
value = Squad
invert = true
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = Not Squad, dont template
}
}
20 changes: 20 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByManufacturer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SUBCATEGORY
{
name = By Manufacturer
FILTER
{
CHECK
{
type = manufacturer
value = Ionic Symphonic Protonic Electronics
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Manufacturer
}
}
20 changes: 20 additions & 0 deletions GameData/000_FilterExtensions Configs/Testing/ByMass.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SUBCATEGORY
{
name = By Mass
FILTER
{
CHECK
{
type = mass // dry mass
value = 0.5
}
}
}

@CATEGORY[Testing]
{
@SUBCATEGORIES
{
list = By Mass
}
}
Loading

0 comments on commit 3280a3a

Please sign in to comment.