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

Commit

Permalink
v1.6 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Dec 28, 2014
1 parent 8c7db66 commit ebde8e0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 47 deletions.
45 changes: 38 additions & 7 deletions FilterExtension/Categoriser/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ static class PartType
{
internal static bool checkCustom(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool val;
switch (value)
{
Expand Down Expand Up @@ -37,15 +40,31 @@ internal static bool checkCustom(AvailablePart part, string value)
return val;
}

internal static bool checkModule(AvailablePart part, string value)
internal static bool checkModuleTitle(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool moduleCheck = part.moduleInfos.Any(m => m.moduleName == value);

return moduleCheck;
}

internal static bool checkModuleName(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool moduleCheck = part.partPrefab.Modules.Contains(value);

return moduleCheck;
}

internal static bool checkCategory(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

switch (value)
{
case "Pod":
Expand Down Expand Up @@ -91,56 +110,69 @@ internal static bool checkCategory(AvailablePart part, string value)

internal static bool checkName(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool nameCheck = part.name == value;

return nameCheck;
}

internal static bool checkTitle(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool titleCheck = part.title.Contains(value);

return titleCheck;
}

internal static bool checkResource(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool resourceCheck = part.resourceInfos.Any(r => r.resourceName == value);

return resourceCheck;
}

internal static bool checkTech(AvailablePart part, string value)
{
if (part.category == PartCategories.none)
return false;

bool techCheck = part.TechRequired == value;

return techCheck;
}

internal static bool checkManufacturer(AvailablePart part, string value)
{
bool manuCheck = part.manufacturer == value;
if (part.category == PartCategories.none)
return false;

bool manuCheck = (part.manufacturer == value);

return manuCheck;
}

internal static bool checkFolder(AvailablePart part, string value)
{
if (part.name == "PotatoRoid")
if (part.category == PartCategories.none)
return false;

bool folderCheck = false;
if (Core.partFolderDict.ContainsKey(part.name))
folderCheck = Core.partFolderDict[part.name] == value;
else
Debug.Log("[Filter Extensions] Unable to assign a mod to the part " + part.title);

return folderCheck;
}

internal static bool checkFolder(AvailablePart part, string[] values)
{
if (part.name == "PotatoRoid")
if (part.category == PartCategories.none)
return false;

if (Core.partFolderDict.ContainsKey(part.name))
Expand All @@ -151,7 +183,6 @@ internal static bool checkFolder(AvailablePart part, string[] values)
return true;
}
}
Debug.Log("[Filter Extensions] Unable to assign a mod to the part " + part.title);

return false;
}
Expand Down
5 changes: 4 additions & 1 deletion FilterExtension/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ internal bool checkPart(AvailablePart partToCheck)
switch (type)
{
case "moduleTitle": // check by module title
result = PartType.checkModule(partToCheck, value);
result = PartType.checkModuleTitle(partToCheck, value);
return (result && pass) || !(result || pass);
case "moduleName":
result = PartType.checkModuleName(partToCheck, value);
return (result && pass) || !(result || pass);
case "name": // check by part name (cfg name)
result = PartType.checkName(partToCheck, value);
Expand Down
52 changes: 22 additions & 30 deletions FilterExtension/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace FilterExtensions
public class Core : MonoBehaviour
{
internal static List<customCategory> Categories = new List<customCategory>();
internal static List<subCategory> subCategories = new List<subCategory>();
internal static List<customSubCategory> subCategories = new List<customSubCategory>();
internal static Dictionary<string, GameDatabase.TextureInfo> texDict = new Dictionary<string, GameDatabase.TextureInfo>(); // all the icons inside folders named filterIcon
internal static Dictionary<string, string> partFolderDict = new Dictionary<string, string>(); // mod folder for each part by internal name

Expand All @@ -33,6 +33,7 @@ void Awake()

if (!modNames.Contains(name))
modNames.Add(name);

if (!partFolderDict.ContainsKey(p.name))
partFolderDict.Add(p.name, name);
else
Expand All @@ -56,7 +57,7 @@ void Awake()
nodeSub.AddValue("icon", s);
nodeSub.AddNode(nodeFilter);

subCategories.Add(new subCategory(nodeSub));
subCategories.Add(new customSubCategory(nodeSub));
}

foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("CATEGORY"))
Expand All @@ -68,7 +69,7 @@ void Awake()

foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("SUBCATEGORY"))
{
subCategory sC = new subCategory(node);
customSubCategory sC = new customSubCategory(node);
if (checkForConflicts(sC))
subCategories.Add(sC);
}
Expand All @@ -83,8 +84,6 @@ private void editor()
{
c.initialise();
}
//PartCategorizer.Instance.filters.Find(c => c.button.categoryName == "Filter by Mod").button.SetIcon(
// PartCategorizer.Instance.filters.Find(c => c.button.categoryName == "Filter by Manufacturer").button.icon);

PartCategorizer.Instance.UpdateCategoryNameLabel();

Expand All @@ -93,7 +92,7 @@ private void editor()
checkIcons(c);
}

foreach (subCategory sC in subCategories)
foreach (customSubCategory sC in subCategories)
{
try
{
Expand All @@ -105,17 +104,7 @@ private void editor()
}
refreshList();

List<PartCategorizer.Category> toDelete = new List<PartCategorizer.Category>();
foreach (PartCategorizer.Category c in PartCategorizer.Instance.filters)
{
if (c.subcategories.Count == 0)
toDelete.Add(c);
}
foreach(PartCategorizer.Category c in toDelete)
{
PartCategorizer.Instance.filters.Remove(c);
}

PartCategorizer.Instance.filters.RemoveAll(c => c.subcategories.Count == 0);
PartCategorizer.Instance.SetAdvancedMode();
}

Expand All @@ -127,22 +116,25 @@ private void refreshList()
button.SetTrue(button, RUIToggleButtonTyped.ClickType.FORCED);
}

private bool checkForConflicts(subCategory sCToCheck)
private bool checkForConflicts(customSubCategory sCToCheck)
{
foreach (subCategory sC in subCategories) // iterate through the already added sC's
foreach (customSubCategory sC in subCategories) // iterate through the already added sC's
{
if (sCToCheck.categories == sC.categories)
foreach (string s in sCToCheck.categories)
{
if (compareFilterLists(sC.filters, sCToCheck.filters)) // check for duplicated filters
{
Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has duplicated the filters of " + sCToCheck.subCategoryTitle);
return false; // ignore this subCategory, only the first processed sC in a conflict will get through
}
else if (sC.subCategoryTitle == sCToCheck.subCategoryTitle) // if they have the same name, just add the new filters on (OR'd together)
if (sC.categories.Contains(s))
{
Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has multiple entries. Filters are being combined");
sCToCheck.filters.AddRange(sC.filters);
return false; // all other elements of this list have already been check for this condition. Don't need to continue
if (compareFilterLists(sC.filters, sCToCheck.filters)) // check for duplicated filters
{
Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has duplicated the filters of " + sCToCheck.subCategoryTitle);
return false; // ignore this subCategory, only the first processed sC in a conflict will get through
}
else if (sC.subCategoryTitle == sCToCheck.subCategoryTitle) // if they have the same name, just add the new filters on (OR'd together)
{
Debug.Log("[Filter Extensions] " + sC.subCategoryTitle + " has multiple entries. Filters are being combined");
sCToCheck.filters.AddRange(sC.filters);
return false; // all other elements of this list have already been check for this condition. Don't need to continue
}
}
}
}
Expand Down Expand Up @@ -249,7 +241,7 @@ internal static PartCategorizer.Icon getIcon(string name)
// credit to EvilReeperx for this lifesaving function
private void RepairAvailablePartUrl(AvailablePart ap)
{
var url = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(u => u.name == KSPUtil.SanitizeFilename(ap.name));
var url = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(u => u.name.Replace('_', '.') == ap.name);

if (url == null)
return;
Expand Down
4 changes: 2 additions & 2 deletions FilterExtension/PartFilters.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Category.cs" />
<Compile Include="customCategory.cs" />
<Compile Include="Check.cs" />
<Compile Include="Core.cs" />
<Compile Include="Categoriser\PartType.cs" />
<Compile Include="Filter.cs" />
<Compile Include="Monitor.cs" />
<Compile Include="subCategory.cs" />
<Compile Include="customSubCategory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FilterExtensions
{
class subCategory
class customSubCategory
{
internal string[] categories; // parent category
internal string subCategoryTitle; // title of this subcategory
Expand All @@ -14,7 +14,7 @@ class subCategory
internal List<Filter> filters = new List<Filter>(); // Filters are OR'd together (pass if it meets this filter, or this filter)
internal bool filter;

public subCategory(ConfigNode node)
public customSubCategory(ConfigNode node)
{
categories = node.GetValue("category").Split(',');
subCategoryTitle = node.GetValue("title");
Expand Down Expand Up @@ -43,7 +43,6 @@ internal void initialise()
{
foreach (string s in categories)
{
Debug.Log(s);
PartCategorizer.Icon icon;
if (string.IsNullOrEmpty(iconName))
{
Expand All @@ -54,12 +53,9 @@ internal void initialise()
{
icon = Core.getIcon(iconName);
}
Debug.Log("1");
if (filter)
{
Debug.Log("2");
PartCategorizer.Category Filter = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.categoryName == s.Trim());
Debug.Log("3");
PartCategorizer.AddCustomSubcategoryFilter(Filter, subCategoryTitle, icon, p => checkFilters(p));
}
else if (!string.IsNullOrEmpty(oldTitle))
Expand Down
Binary file modified GameData/Filter Extensions/FilterExtensions.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/Filter Extensions/FilterExtensions.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"NAME":"Filter Extensions","URL":"http://ksp-avc.cybutek.net/version.php?id=97","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":1,"MINOR":4,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":0,"MINOR":90,"PATCH":0}}
{"NAME":"Filter Extensions","URL":"http://ksp-avc.cybutek.net/version.php?id=97","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":1,"MINOR":6,"PATCH":0,"BUILD":0},"KSP_VERSION":{"MAJOR":0,"MINOR":90,"PATCH":0}}

0 comments on commit ebde8e0

Please sign in to comment.