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

Commit

Permalink
Catching all they typo's
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Mar 19, 2015
1 parent 593b894 commit dc0794f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 50 deletions.
Binary file added Filter Extensions v2.0.2.zip
Binary file not shown.
9 changes: 3 additions & 6 deletions FilterExtension/ConfigNodes/customCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,9 @@ private void generateEngineTypes()
checks.Add(new Check("propellant", props));
checks.Add(new Check("propellant", props, true, false)); // exact match to propellant list. Nothing extra, nothing less

string name = props.Replace(',', '/');
string icon = props;
if (Core.Instance.proceduralNames.ContainsKey(name))
name = Core.Instance.proceduralNames[name];
if (Core.Instance.proceduralIcons.ContainsKey(name))
icon = Core.Instance.proceduralIcons[name];
string name = props.Replace(',', '/'); // can't use ',' as a delimiter in the procedural name/icon switch function
string icon = name;
Core.Instance.proceduralNameandIcon(ref name, ref icon);

if (!Core.Instance.subCategoriesDict.ContainsKey(name))
{
Expand Down
63 changes: 20 additions & 43 deletions FilterExtension/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Awake()
{
instance = this;
DontDestroyOnLoad(this);
Log("Version 2.0");
Log("Version 2.0.2");
config = KSP.IO.PluginConfiguration.CreateForType<Core>();
config.load();

Expand Down Expand Up @@ -122,10 +122,7 @@ void Awake()
// add spaces before each capital letter
string name = System.Text.RegularExpressions.Regex.Replace(s, @"\B([A-Z])", " $1");
string icon = "";
if (proceduralNames.ContainsKey(name))
name = proceduralNames[name];
if (proceduralIcons.ContainsKey(name))
icon = proceduralIcons[name];
proceduralNameandIcon(ref name, ref icon);
if (name != null && !subCategoriesDict.ContainsKey(name))
{
customSubCategory sC = new customSubCategory(name, icon);
Expand Down Expand Up @@ -233,10 +230,7 @@ private void processFilterByManufacturer(List<string> modNames)
{
string name = modNames[i];
string icon = modNames[i];
if (proceduralNames.ContainsKey(name))
name = proceduralNames[name];
if (proceduralIcons.ContainsKey(name))
icon = proceduralIcons[name];
proceduralNameandIcon(ref name, ref icon);

Check ch = new Check("folder", modNames[i]);
Filter f = new Filter(false);
Expand Down Expand Up @@ -270,38 +264,24 @@ private void processFilterByManufacturer(List<string> modNames)
private bool stringListComparer(List<string> propellants)
{
foreach (List<string> ls in propellantCombos)
{
if (propellants.Count == ls.Count)
{
List<string> tmp = propellants.Except(ls).ToList();
if (!tmp.Any())
return true;
}
}
if (propellants.Count == ls.Count && !propellants.Except(ls).Any())
return true;
return false;
}

internal void editor()
{
// Add all the categories
foreach (customCategory c in Categories)
{
if (!c.stockCategory)
c.initialise();
}

// icon autoloader pass
foreach (PartCategorizer.Category c in PartCategorizer.Instance.filters)
{
checkIcons(c);
}

// update icons
setSelectedCategory();

// Remove any category with no subCategories (causes major breakages). Removal doesn't actually prevent icon showing (>.<), just breakages
PartCategorizer.Instance.filters.RemoveAll(c => c.subcategories.Count == 0);

// reveal categories because why not
PartCategorizer.Instance.SetAdvancedMode();
}
Expand All @@ -314,9 +294,7 @@ public void setSelectedCategory()

Filter = PartCategorizer.Instance.filters.Find(f => f.button.categoryName == config.GetValue("categoryDefault", "Filter by Function"));
if (Filter != null)
{
Filter.button.activeButton.SetTrue(Filter.button.activeButton, RUIToggleButtonTyped.ClickType.FORCED);
}
else
{
Filter = PartCategorizer.Instance.filters[0];
Expand Down Expand Up @@ -377,10 +355,7 @@ private void checkIcons(PartCategorizer.Category category)

private static void loadIcons()
{
List<GameDatabase.TextureInfo> texList = GameDatabase.Instance.databaseTexture.Where(t => t.texture != null
&& t.texture.height <= 40 && t.texture.width <= 40
&& t.texture.width >= 25 && t.texture.height >= 25
).ToList();
List<GameDatabase.TextureInfo> texList = GameDatabase.Instance.databaseTexture.Where(t => t.texture != null && t.texture.height <= 40 && t.texture.width <= 40 && t.texture.width >= 25 && t.texture.height >= 25).ToList();

Dictionary<string, GameDatabase.TextureInfo> texDict = new Dictionary<string, GameDatabase.TextureInfo>();
// using a dictionary for looking up _selected textures. Else the list has to be iterated over for every texture
Expand All @@ -404,7 +379,6 @@ private static void loadIcons()
foreach (GameDatabase.TextureInfo t in texList)
{
Texture2D selectedTex = null;

if (texDict.ContainsKey(t.name + "_selected"))
selectedTex = texDict[t.name + "_selected"].texture;
else
Expand All @@ -421,11 +395,11 @@ private static void loadIcons()
Log("Duplicated texture name \"" + t.name.Split(new char[] { '/', '\\' }).Last() + "\" at:\r\n" + t.name + "\r\n New reference is: " + name);
}

PartCategorizer.Icon icon = new PartCategorizer.Icon(name, t.texture, selectedTex, false);

// shouldn't be neccesary to check, but just in case...
if (!Instance.iconDict.ContainsKey(icon.name))
if (!Instance.iconDict.ContainsKey(name))
{
PartCategorizer.Icon icon = new PartCategorizer.Icon(name, t.texture, selectedTex, false);
Instance.iconDict.Add(icon.name, icon);
}
}
}

Expand All @@ -444,29 +418,32 @@ public static PartCategorizer.Icon getIcon(string name)
private void RepairAvailablePartUrl(AvailablePart ap)
{
var url = GameDatabase.Instance.GetConfigs("PART").FirstOrDefault(u => u.name.Replace('_', '.') == ap.name);

if (url == null)
return;

ap.partUrl = url.url;
}

public static bool checkSubCategoryHasParts(customSubCategory sC)
{
foreach (AvailablePart p in PartLoader.Instance.parts)
{
if (sC.checkFilters(p))
{
return true;
}
}

Log(sC.subCategoryTitle + " has no valid parts and was not initialised");
return false;
}

public void proceduralNameandIcon(ref string name, ref string icon)
{
if (proceduralNames.ContainsKey(name))
name = proceduralNames[name];
if (proceduralIcons.ContainsKey(name))
icon = proceduralIcons[name];
}

internal static void Log(object o)
{
Debug.Log("[Filter Extensions] " + o);
}
}
}
}
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":"http://ksp-avc.cybutek.net/version.php?id=97","DOWNLOAD":"https://github.com/Crzyrndm/FilterExtension/releases","VERSION":{"MAJOR":2,"MINOR":0,"PATCH":1,"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":2,"MINOR":0,"PATCH":2,"BUILD":0},"KSP_VERSION":{"MAJOR":0,"MINOR":90,"PATCH":0}}

0 comments on commit dc0794f

Please sign in to comment.