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

Commit

Permalink
version 2.4.1
Browse files Browse the repository at this point in the history
Patch for dissapearing subcategories
Fix for override not being copied
  • Loading branch information
Crzyrndm committed Jul 23, 2015
1 parent cd7c17a commit e0c44dd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion FilterExtension/ConfigNodes/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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 = PartType.checkCustom(part, value);
result = Editor.instance.ready ? PartType.checkCustom(part, value) : !invert;
break;
case CheckType.mass:
result = PartType.checkMass(part, value, equality);
Expand Down
4 changes: 2 additions & 2 deletions FilterExtension/ConfigNodes/customSubCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public customSubCategory(ConfigNode node)
iconName = node.GetValue("icon");

bool tmp;
bool.TryParse(node.GetValue("showUnPurchased"), out tmp);
bool.TryParse(node.GetValue("showUnpurchased"), out tmp);
unPurchasedOverride = tmp;

filters = new List<Filter>();
Expand All @@ -49,6 +49,7 @@ public ConfigNode toConfigNode()

node.AddValue("name", this.subCategoryTitle);
node.AddValue("icon", this.iconName);
node.AddValue("showUnpurchased", this.unPurchasedOverride);

foreach (Filter f in this.filters)
node.AddNode(f.toConfigNode());
Expand All @@ -65,7 +66,6 @@ public bool checkFilters(AvailablePart part)
if (!unPurchasedOverride && Core.Instance.hideUnpurchased && !ResearchAndDevelopment.PartModelPurchased(part) && !ResearchAndDevelopment.IsExperimentalPart(part))
return false;
}

foreach (Filter f in filters)
{
if (f.checkFilter(part))
Expand Down
57 changes: 29 additions & 28 deletions FilterExtension/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace FilterExtensions
class Editor : MonoBehaviour
{
public static Editor instance;
public bool ready = false;
void Start()
{
instance = this;
Expand Down Expand Up @@ -71,27 +72,27 @@ IEnumerator editorInit()
{
findPartsToBlock();
// not known until now which parts are never visible so some empty subcategories will be present
for (int i = 0; i < PartCategorizer.Instance.filters.Count; i++)
{
List<PartCategorizer.Category> subCatsToDelete = new List<PartCategorizer.Category>();
PartCategorizer.Category C = PartCategorizer.Instance.filters[i];
if (C == null)
continue;
for (int j = 0; j < C.subcategories.Count; j++)
{
PartCategorizer.Category sub = C.subcategories[j];
if (sub == null)
continue;

if (!PartLoader.Instance.parts.Any(p => sub.exclusionFilter.FilterCriteria.Invoke(p)))
subCatsToDelete.Add(sub);
}
for (int j = 0; j < subCatsToDelete.Count; j++)
{
PartCategorizer.Category sub = subCatsToDelete[j];
C.subcategories.Remove(sub);
}
}
//for (int i = 0; i < PartCategorizer.Instance.filters.Count; i++)
//{
// PartCategorizer.Category C = PartCategorizer.Instance.filters[i];
// if (C == null)
// continue;
// int j = 0;
// while (j < C.subcategories.Count)
// {
// PartCategorizer.Category sub = C.subcategories[j];
// if (sub == null)
// {
// j++;
// continue;
// }

// if (!PartLoader.Instance.parts.Any(p => sub.exclusionFilter.FilterCriteria.Invoke(p)))
// C.subcategories.RemoveAt(j);
// else
// j++;
// }
//}
}
foreach (PartCategorizer.Category c in PartCategorizer.Instance.filters)
Core.Instance.namesAndIcons(c);
Expand All @@ -117,6 +118,8 @@ IEnumerator editorInit()
if (Core.Instance.debug)
Core.Log("Refreshing parts list");
Core.setSelectedCategory();

ready = true;
}

/// <summary>
Expand All @@ -140,17 +143,15 @@ void findPartsToBlock()
subCatsSeen.Add(subCat.button.categoryName);
else // subcat created by another mod
{
// can't remove parts from a collection being looped over, need to remember the visible parts
List<AvailablePart> visibleParts = new List<AvailablePart>();
for (int j = 0; j < partsToCheck.Count; j++)
int j = 0;
while (j < partsToCheck.Count)
{
AvailablePart AP = partsToCheck[j];
if (subCat.exclusionFilter.FilterCriteria.Invoke(AP)) // if visible
visibleParts.Add(AP);
partsToCheck.RemoveAt(j);
else
j++;
}
// remove all visible parts from the list to block
foreach (AvailablePart ap in visibleParts)
partsToCheck.Remove(ap);
}
}
// add the blocked parts to a hashset for later lookup
Expand Down
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":4,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":0,"PATCH":4}}
{"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":4,"PATCH":1,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":0,"PATCH":4}}

0 comments on commit e0c44dd

Please sign in to comment.