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

Commit

Permalink
Merge pull request #13 from Crzyrndm/master
Browse files Browse the repository at this point in the history
Update from parent.
  • Loading branch information
Kerbas-ad-astra committed Feb 16, 2016
2 parents 8b9b27d + 7a5b24b commit b794418
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 112 deletions.
24 changes: 18 additions & 6 deletions FilterExtension/ConfigNodes/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum Equality
GreaterThan
}
public CheckType type { get; set; }
public string value { get; set; }
public string[] value { get; set; }
public bool invert { get; set; }
public bool contains { get; set; }
public Equality equality { get; set; }
Expand All @@ -50,7 +50,14 @@ public enum Equality
public Check(ConfigNode node)
{
type = getType(node.GetValue("type"));
value = node.GetValue("value");

string tmpVal = node.GetValue("value");
if (tmpVal != null)
{
value = tmpVal.Split(',');
for (int i = 0; i < this.value.Length; ++i)
value[i] = value[i].Trim();
}

bool tmp;
bool.TryParse(node.GetValue("invert"), out tmp);
Expand All @@ -60,7 +67,7 @@ public Check(ConfigNode node)
contains = tmp;
else
contains = true;

checks = new List<Check>();
if (type == CheckType.check)
{
Expand All @@ -87,7 +94,7 @@ public Check(ConfigNode node)
public Check(Check c)
{
type = c.type;
value = c.value;
value = (string[])c.value.Clone();
invert = c.invert;
contains = c.contains;

Expand All @@ -99,7 +106,10 @@ 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.value = value;
this.value = value.Split(',');
for (int i = 0; i < this.value.Length; ++i)
this.value[i] = this.value[i].Trim();

this.invert = invert;
this.contains = contains;
equality = compare;
Expand All @@ -110,7 +120,9 @@ public ConfigNode toConfigNode()
{
ConfigNode node = new ConfigNode("CHECK");
node.AddValue("type", getTypeString(type));
node.AddValue("value", this.value);

if (value != null)
node.AddValue("value", string.Join(",", value));
if (invert)
node.AddValue("invert", this.invert.ToString());
if (!contains && checkUsesContains())
Expand Down
4 changes: 3 additions & 1 deletion FilterExtension/ConfigNodes/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public Filter(ConfigNode node)
{
checks.Add(new Check(subNode));
}
checks.RemoveAll(c => c.value == null);

bool tmp;
bool.TryParse(node.GetValue("invert"), out tmp);
Expand All @@ -28,7 +29,8 @@ public Filter(Filter f)
checks = new List<Check>();
for (int i = 0; i < f.checks.Count; i++)
{
checks.Add(new Check(f.checks[i]));
if (f.checks[i].value != null)
checks.Add(new Check(f.checks[i]));
}

invert = f.invert;
Expand Down
17 changes: 2 additions & 15 deletions FilterExtension/ConfigNodes/customCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,8 @@ public void initialise()
}

customSubCategory sC = new customSubCategory(subcategory.toConfigNode());
if (subcategoryItem.applyTemplate && templates != null && templates.Any())
{
List<Filter> baseSubCatFilters = new List<Filter>();
foreach (Filter f in sC.filters)
baseSubCatFilters.Add(new Filter(f)); // create independent copies
sC.filters.Clear(); // create them from scratch
foreach (Filter templateFilter in templates)
{
foreach (Filter f in baseSubCatFilters)
{
sC.filters.Add(new Filter(f));
sC.filters.Last().checks.AddRange(templateFilter.checks);
}
}
}
if (subcategoryItem.applyTemplate)
sC.template = templates;

try
{
Expand Down
15 changes: 6 additions & 9 deletions FilterExtension/ConfigNodes/customSubCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ public class customSubCategory
public string subCategoryTitle { get; set; } // title of this subcategory
public string iconName { get; set; } // default icon to use
public List<Filter> filters { get; set; } // Filters are OR'd together (pass if it meets this filter, or this filter)
public List<Filter> template { get; set; } // from the category, checked seperately
public bool unPurchasedOverride { get; set; } // allow unpurchased parts to be visible even if the global setting hides them

public bool hasFilters
{
get
{
return filters.Any();
return filters.Any() || template.Any();
}
}

Expand All @@ -34,11 +35,13 @@ public customSubCategory(ConfigNode node)
{
filters.Add(new Filter(subNode));
}
template = new List<Filter>();
}

public customSubCategory(string name, string icon)
{
filters = new List<Filter>();
template = new List<Filter>();
this.subCategoryTitle = name;
this.iconName = icon;
}
Expand Down Expand Up @@ -88,13 +91,7 @@ public bool checkFilters(AvailablePart part, int depth = 0)
}
if (!unPurchasedOverride && Core.Instance.hideUnpurchased && !ResearchAndDevelopment.PartModelPurchased(part) && !ResearchAndDevelopment.IsExperimentalPart(part))
return false;

foreach (Filter f in filters)
{
if (f.checkFilter(part, depth))
return true;
}
return false; // part passed no filter(s), not compatible with this subcategory
return ((!template.Any() || template.Any(t => t.checkFilter(part, depth))) && filters.Any(f => f.checkFilter(part, depth))); // part passed a template if present, and a subcategory filter
}

/// <summary>
Expand All @@ -115,7 +112,7 @@ public static bool checkForCheckMatch(customSubCategory subcategory, CheckType t
for (int k = 0; k < f.checks.Count; k++)
{
Check c = f.checks[k];
if (c.type == type && c.value == value && c.invert == invert && c.contains == contains && c.equality == equality)
if (c.type == type && c.value.Contains(value) && c.value.Length == 1 && c.invert == invert && c.contains == contains && c.equality == equality)
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions FilterExtension/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ IEnumerator editorInit()
cat.initialise();
}
}

// custom categories
// wait until the part menu is initialised
while (!PartCategorizer.Ready)
Expand Down
Loading

0 comments on commit b794418

Please sign in to comment.