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

Commit

Permalink
some contains standardising, fix byTag test
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Apr 23, 2016
1 parent 2df31aa commit c5b02a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
40 changes: 22 additions & 18 deletions FilterExtension/Utility/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ public static bool checkModuleTitle(AvailablePart part, string[] values, bool co
{
if (part.moduleInfos == null)
return false;

if (contains)
return part.moduleInfos.Any(m => values.Contains(m.moduleName, StringComparer.OrdinalIgnoreCase));
else
return part.moduleInfos.Any(m => !values.Contains(m.moduleName, StringComparer.OrdinalIgnoreCase));

foreach (AvailablePart.ModuleInfo mi in part.moduleInfos)
{
if (contains == values.Contains(mi.moduleName, StringComparer.OrdinalIgnoreCase))
return true;
}
return false;
}

/// <summary>
Expand All @@ -127,6 +129,7 @@ public static bool checkModuleName(AvailablePart part, string[] value, bool cont
{
if (part.partPrefab == null || part.partPrefab.Modules == null)
return false;

if (contains)
return value.Any(s => checkModuleNameType(part, s) || part.partPrefab.Modules.Contains(s));
else
Expand Down Expand Up @@ -342,10 +345,12 @@ public static bool checkResource(AvailablePart part, string[] value, bool contai
if (part.partPrefab == null || part.partPrefab.Resources == null)
return false;

if (contains)
return value.Any(s => part.partPrefab.Resources.Contains(s) && part.partPrefab.Resources[s].maxAmount > 0);
else
return value.Any(s => !part.partPrefab.Resources.Contains(s) || part.partPrefab.Resources[s].maxAmount <= 0);
foreach (PartResource r in part.partPrefab.Resources)
{
if (r.maxAmount > 0 && contains == value.Contains(r.resourceName))
return true;
}
return false;
}

/// <summary>
Expand All @@ -355,8 +360,11 @@ public static bool checkPropellant(AvailablePart part, string[] value, bool cont
{
foreach (ModuleEngines e in part.partPrefab.Modules.GetModules<ModuleEngines>())
{
if (contains && e.propellants.Any(p => value.Contains(p.name)) || (!contains && e.propellants.Any(p => !value.Contains(p.name))))
return true;
foreach (Propellant p in e.propellants)
{
if (contains == value.Contains(p.name))
return true;
}
}
return false;
}
Expand Down Expand Up @@ -588,9 +596,7 @@ public static bool checkBulkHeadProfiles(AvailablePart part, string[] value, boo

foreach (string s in part.bulkheadProfiles.Split(','))
{
if (contains && value.Contains(s.Trim()))
return true;
if (!contains && !value.Contains(s.Trim()))
if (contains == value.Contains(s.Trim()))
return true;
}
return false;
Expand All @@ -601,11 +607,9 @@ public static bool checkTags(AvailablePart part, string[] value, bool contains)
if (string.IsNullOrEmpty(part.tags))
return false;

foreach (string s in part.tags.Split(new char[4] { ' ', ',', '|', ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).Where(s => s!= string.Empty).ToArray())
foreach (string s in part.tags.Split(new char[4] { ' ', ',', '|', ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray())
{
if (contains && value.Contains(s.Trim()))
return true;
if (!contains && !value.Contains(s.Trim()))
if (contains == value.Contains(s))
return true;
}
return false;
Expand Down
Binary file modified GameData/000_FilterExtensions/FilterExtensions.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Testing/ByTag.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SUBCATEGORY
CHECK
{
type = tag
value = mk2
value = (more
}
}
}
Expand All @@ -19,7 +19,7 @@ SUBCATEGORY
CHECK
{
type = tag
value = mk2, mk1
value = (more, moar
contains = false
}
}
Expand Down

0 comments on commit c5b02a3

Please sign in to comment.