This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first pass at part module based filtering. Needs testing
- Loading branch information
Showing
8 changed files
with
108 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FilterExtensions | ||
{ | ||
public class PartModuleFilter : PartModule | ||
{ | ||
/// <summary> | ||
/// list names of FE categories to push this part into even if it doesn't otherwise match the filters | ||
/// </summary> | ||
[KSPField] | ||
public string filterAdd; | ||
public HashSet<string> subcategoriesToAdd; | ||
|
||
/// <summary> | ||
/// list names of FE categories to never let this part be added to | ||
/// </summary> | ||
[KSPField] | ||
public string filterBlock; | ||
public HashSet<string> subcategoriesToBlock; | ||
|
||
public bool CheckForForceAdd(string subcategory) | ||
{ | ||
addStringToSet(); | ||
return subcategoriesToAdd.Contains(subcategory); | ||
} | ||
|
||
public bool CheckForForceBlock(string subcategory) | ||
{ | ||
blockStringToSet(); | ||
return subcategoriesToBlock.Contains(subcategory); | ||
} | ||
|
||
void addStringToSet() | ||
{ | ||
if (subcategoriesToAdd == null) | ||
{ | ||
subcategoriesToAdd = new HashSet<string>(); | ||
string[] temp = filterAdd.Split(','); | ||
for (int i = 0; i < temp.Length; ++i) | ||
subcategoriesToAdd.Add(temp[i].Trim()); | ||
} | ||
} | ||
|
||
void blockStringToSet() | ||
{ | ||
if (subcategoriesToBlock == null) | ||
{ | ||
subcategoriesToBlock = new HashSet<string>(); | ||
string[] temp = filterBlock.Split(','); | ||
for (int i = 0; i < temp.Length; ++i) | ||
subcategoriesToBlock.Add(temp[i].Trim()); | ||
} | ||
} | ||
|
||
public bool hasForceAdd() | ||
{ | ||
addStringToSet(); | ||
return subcategoriesToAdd.Any(); | ||
} | ||
|
||
public bool hasForceBlock() | ||
{ | ||
blockStringToSet(); | ||
return subcategoriesToBlock.Any(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.