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

Commit

Permalink
Typos are great fun
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Jun 8, 2017
1 parent 51d35c0 commit 2b6c409
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 29 deletions.
6 changes: 5 additions & 1 deletion FilterExtension/ConfigNodes/CategoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public CategoryNode(ConfigNode node, LoadAndProcess data)
{
CategoryName = node.GetValue("name").Trim();
IconName = node.GetValue("icon");
if (string.IsNullOrEmpty(IconName))
{
IconName = CategoryName;
}
Colour = GUIUtils.ConvertToColor(node.GetValue("colour"));

ConfigNode[] filtNodes = node.GetNodes("FILTER");
Expand Down Expand Up @@ -74,7 +78,7 @@ public CategoryNode(ConfigNode node, LoadAndProcess data)
foreach (List<string> combo in data.propellantCombos)
{
string dummy = string.Empty, subcatName = string.Join(",", combo.ToArray());
data.SetNameAndIcon(ref subcatName, ref dummy);
data.SetName(ref subcatName);
SubCategories.AddUnique(new SubCategoryItem(subcatName));
}
}
Expand Down
11 changes: 5 additions & 6 deletions FilterExtension/ConfigNodes/SubcategoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SubcategoryNode : IEquatable<SubcategoryNode>
public string IconName { get; } // default icon to use
public List<FilterNode> Filters { get; } // Filters are OR'd together (pass if it meets this filter, or this filter)
public bool UnPurchasedOverride { get; } // allow unpurchased parts to be visible even if the global setting hides them
CategoryNode Category { get; } = null;
CategoryNode Category { get; } = null; // set when subcats are cloned from the group during category instatiation

public bool HasFilters { get => (Filters?.Count ?? 0) > 0; }

Expand All @@ -24,16 +24,15 @@ public SubcategoryNode(ConfigNode node, LoadAndProcess data)
nameTemp = data.Rename[nameTemp];
}
SubCategoryTitle = nameTemp;
if (SubCategoryTitle == string.Empty)
if (string.IsNullOrEmpty(SubCategoryTitle))
{
SubCategoryTitle = node.GetValue("categoryName"); // for playing nice with stock generated subcats
}
string iconTemp = IconName = node.GetValue("icon");
if (!string.IsNullOrEmpty(SubCategoryTitle) && data.setIcon.ContainsKey(SubCategoryTitle))
IconName = node.GetValue("icon");
if (string.IsNullOrEmpty(IconName))
{
iconTemp = data.setIcon[SubCategoryTitle];
IconName = SubCategoryTitle;
}
IconName = iconTemp;

bool.TryParse(node.GetValue("showUnpurchased"), out bool tmp);
UnPurchasedOverride = tmp;
Expand Down
17 changes: 10 additions & 7 deletions FilterExtension/ConfigNodes/SubcategoryNodeModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace FilterExtensions.ConfigNodes
public static class SubcategoryNodeModifier
{
static readonly string[] splitter = new string[] { "=>" };
public static void MakeRenamers(ConfigNode node, Dictionary<string, string> renames)
public static Dictionary<string, string> MakeRenamers(ConfigNode node)
{
Debug.Assert(renames != null, $"{nameof(renames)} dictionary is assumed to never be null");
var renames = new Dictionary<string, string>();
foreach (string s in node.GetValues("name"))
{
string[] split = s.Split(splitter, StringSplitOptions.RemoveEmptyEntries)
Expand All @@ -26,11 +26,12 @@ public static void MakeRenamers(ConfigNode node, Dictionary<string, string> rena
renames.Add(split[0], split[1]);
}
}
return renames;
}

public static void MakeIconChangers(ConfigNode node, Dictionary<string, string> icons)
public static Dictionary<string, string> MakeIconChangers(ConfigNode node)
{
Debug.Assert(icons != null, $"{nameof(icons)} dictionary is assumed to never be null");
var icons = new Dictionary<string, string>();
foreach (string s in node.GetValues("icon"))
{
string[] split = s.Split(splitter, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToArray();
Expand All @@ -39,16 +40,17 @@ public static void MakeIconChangers(ConfigNode node, Dictionary<string, string>
Logger.Log($"bad length in set icon string {s}", Logger.LogLevel.Error);
continue;
}
if (icons.ContainsKey(split[0]))
if (!icons.ContainsKey(split[0]))
{
icons.Add(split[0], split[1]);
}
}
return icons;
}

public static void MakeDeleters(ConfigNode node, HashSet<string> deleters)
public static HashSet<string> MakeDeleters(ConfigNode node)
{
Debug.Assert(deleters != null, $"{nameof(deleters)} hashset is assumed to never be null");
HashSet<string> deleters = new HashSet<string>();
foreach (string s in node.GetValues("remove"))
{
string str = s.Trim();
Expand All @@ -58,6 +60,7 @@ public static void MakeDeleters(ConfigNode node, HashSet<string> deleters)
}
deleters.Add(str); // hashset doesn't need duplicate check
}
return deleters;
}
}
}
7 changes: 6 additions & 1 deletion FilterExtension/IconLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public static class IconLib
{
// Dictionary of icons created on entering the main menu
public static Dictionary<string, RUI.Icons.Selectable.Icon> IconDict = new Dictionary<string, RUI.Icons.Selectable.Icon>();
//
// if the name sent to get_icon is a key, switch with the linked name
public static Dictionary<string, string> Icon_Alias = new Dictionary<string, string>();
// if the icon isn't present, use this one
private const string fallbackIcon = "stockIcon_fallback";

Expand Down Expand Up @@ -61,6 +62,10 @@ public static RUI.Icons.Selectable.Icon GetIcon(string name)
if (!string.IsNullOrEmpty(name))
{
name = name.Trim();
if (Icon_Alias.ContainsKey(name))
{
name = Icon_Alias[name];
}
if (IconDict.TryGetValue(name, out RUI.Icons.Selectable.Icon icon)
|| PartCategorizer.Instance.iconLoader.iconDictionary.TryGetValue(name, out icon))
{
Expand Down
30 changes: 16 additions & 14 deletions FilterExtension/LoadAndProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public class LoadAndProcess : MonoBehaviour
// renaming categories
public Dictionary<string, string> Rename = new Dictionary<string, string>();

// icons for categories
public Dictionary<string, string> setIcon = new Dictionary<string, string>();

// removing categories
public HashSet<string> removeSubCategory = new HashSet<string>();

Expand Down Expand Up @@ -98,15 +95,25 @@ private void GetConfigs()
{
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("FilterRename"))
{
SubcategoryNodeModifier.MakeRenamers(node, Rename);
foreach (KeyValuePair<string, string> kvp in SubcategoryNodeModifier.MakeRenamers(node))
{
Rename.TryAdd(kvp.Key, kvp.Value);
}
}
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("FilterSetIcon"))
{
SubcategoryNodeModifier.MakeRenamers(node, setIcon);
foreach (KeyValuePair<string, string> kvp in SubcategoryNodeModifier.MakeIconChangers(node))
{
IconLib.Icon_Alias.TryAdd(kvp.Key, kvp.Value);
}
}
Logger.Dev(IconLib.Icon_Alias.Count);
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("FilterRemove"))
{
SubcategoryNodeModifier.MakeDeleters(node, removeSubCategory);
foreach (string s in SubcategoryNodeModifier.MakeDeleters(node))
{
removeSubCategory.Add(s);
}
}
}

Expand Down Expand Up @@ -285,7 +292,7 @@ private void GenerateEngineTypes()
string propList = string.Join(",", ls.ToArray());
string name = propList;
string icon = propList;
SetNameAndIcon(ref name, ref icon);
SetName(ref name);

if (!string.IsNullOrEmpty(name) && !subCategoriesDict.ContainsKey(name))
{
Expand Down Expand Up @@ -313,7 +320,7 @@ private void ProcessFilterByManufacturer(List<string> modNames)
name = "mod_" + name;
}
string icon = name;
SetNameAndIcon(ref name, ref icon);
SetName(ref name);

if (!subCategoriesDict.ContainsKey(name))
{
Expand All @@ -338,7 +345,6 @@ private void ProcessFilterByManufacturer(List<string> modNames)
filterByManufacturer.AddNode(manufacturerSubs);
FilterByManufacturer = new CategoryNode(filterByManufacturer, this);
CategoryNodes.Add(FilterByManufacturer);
Logger.Log("Filter by manufacturer");
}

/// <summary>
Expand Down Expand Up @@ -436,16 +442,12 @@ private void RepairAvailablePartUrl(AvailablePart ap)
/// </summary>
/// <param name="name"></param>
/// <param name="icon"></param>
public void SetNameAndIcon(ref string name, ref string icon)
public void SetName(ref string name)
{
if (Rename.TryGetValue(name, out string tmp))
{
name = tmp;
}
if (setIcon.TryGetValue(name, out tmp))
{
icon = tmp;
}
}
}
}
Binary file modified GameData/000_FilterExtensions/FilterExtensions.dll
Binary file not shown.
Binary file modified Testing/FE_Testing.dll
Binary file not shown.

0 comments on commit 2b6c409

Please sign in to comment.