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

Commit

Permalink
dramatically simplified category templating implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Jan 14, 2016
1 parent f5ec739 commit 7a5b24b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
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
13 changes: 5 additions & 8 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 Down
Binary file modified GameData/000_FilterExtensions/FilterExtensions.dll
Binary file not shown.

0 comments on commit 7a5b24b

Please sign in to comment.