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

Commit

Permalink
Proper all subCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Jan 11, 2015
1 parent 25e3956 commit 760ba87
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 25 deletions.
39 changes: 21 additions & 18 deletions FilterExtension/Categoriser/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,20 @@ internal static bool checkPropellant(AvailablePart part, string value)
if (categoryCheck(part))
return false;

List<Propellant> propellants = new List<Propellant>();
if (part.partPrefab.GetModuleEngines() != null)
{
propellants = part.partPrefab.GetModuleEngines().propellants;
}
else if (part.partPrefab.GetModuleEnginesFx() != null)
{
propellants = part.partPrefab.GetModuleEnginesFx().propellants;
}
else
return false;
List<List<Propellant>> propellants = new List<List<Propellant>>();

foreach (ModuleEngines e in part.partPrefab.GetModuleEngines())
propellants.Add(e.propellants);
foreach (ModuleEnginesFX ex in part.partPrefab.GetModuleEnginesFx())
propellants.Add(ex.propellants);

foreach (string s in value.Split(','))
foreach (List<Propellant> Lp in propellants)
{
if (propellants.Any(p => p.name == s.Trim()))
return true;
foreach (string s in value.Split(','))
{
if (Lp.Any(p => p.name == s.Trim()))
return true;
}
}
return false;
}
Expand Down Expand Up @@ -310,19 +308,24 @@ public static bool isWing(AvailablePart part)
return false;
}

public static List<T> GetModules<T>(this Part part) where T : PartModule
{
return part.Modules.OfType<T>().ToList();
}

public static T GetModule<T>(this Part part) where T : PartModule
{
return part.Modules.OfType<T>().FirstOrDefault();
}

public static ModuleEngines GetModuleEngines(this Part part)
public static List<ModuleEngines> GetModuleEngines(this Part part)
{
return part.GetModule<ModuleEngines>();
return part.GetModules<ModuleEngines>();
}

public static ModuleEnginesFX GetModuleEnginesFx(this Part part)
public static List<ModuleEnginesFX> GetModuleEnginesFx(this Part part)
{
return part.GetModule<ModuleEnginesFX>();
return part.GetModules<ModuleEnginesFX>();
}
}
}
27 changes: 25 additions & 2 deletions FilterExtension/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ public class Core : MonoBehaviour

// mod folder for each part by internal name
public static Dictionary<string, string> partFolderDict = new Dictionary<string, string>();

// store all the "All parts" subcategories until all subcategories have been processed
internal Dictionary<string, ConfigNode> categoryAllSub = new Dictionary<string, ConfigNode>(); // store the config node for the "all" subcategories until all filters have been added

// state is set on initialisation starting and finishing. This way we know whether a problem was encountered and if it was a problem related to FE
internal static int state = 0; // 0 = we haven't started yet, 1 = processing started, -1 = processing finished, 2 = processing reattempted

// Dictionary of icons created on entering the main menu
public static Dictionary<string, PartCategorizer.Icon> iconDict = new Dictionary<string, PartCategorizer.Icon>();

public static Core Instance
public static Core Instance // Reminder to self, don't be abusing static
{
get
{
Expand All @@ -36,7 +41,7 @@ public static Core Instance
void Awake()
{
instance = this;
Log("Version 1.13");
Log("Version 1.14");

// Add event for when the Editor GUI becomes active. This is never removed because we need it to fire every time
GameEvents.onGUIEditorToolbarReady.Add(editor);
Expand Down Expand Up @@ -85,6 +90,24 @@ void Awake()
subCategories.Add(sC);
}
}

foreach (KeyValuePair<string, ConfigNode> kvp in categoryAllSub)
{
ConfigNode sC = kvp.Value;
if (folderToCategoryDict.ContainsKey(kvp.Key))
{
foreach (ConfigNode node in sC.GetNodes("FILTER"))
{
ConfigNode nodeCheck = new ConfigNode("CHECK");
nodeCheck.AddValue("type", "folder");
nodeCheck.AddValue("value", folderToCategoryDict[kvp.Key]);
node.AddNode(nodeCheck);
}
}

subCategories.Insert(0, new customSubCategory(sC, kvp.Key));
}

checkForEmptySubCategories();
loadIcons();
}
Expand Down
15 changes: 13 additions & 2 deletions FilterExtension/customCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ public customCategory(ConfigNode node)
type = node.GetValue("type");
value = node.GetValue("value");

// not hooked up to anything
bool.TryParse(node.GetValue("all"), out all);
if (bool.TryParse(node.GetValue("all"), out all))
{
if (!Core.Instance.categoryAllSub.ContainsKey(categoryTitle))
{
// create confignode for an "All parts" subcategory
ConfigNode c = new ConfigNode("SUBCATEGORY");
c.AddValue("name", "All Parts in Category");
c.AddValue("category", categoryTitle);
c.AddValue("icon", iconName);
// add it to the dictionary
Core.Instance.categoryAllSub.Add(categoryTitle, c);
}
}

typeSwitch();
}
Expand Down
4 changes: 4 additions & 0 deletions FilterExtension/customSubCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public customSubCategory(ConfigNode node, string Category)
foreach (ConfigNode subNode in node.GetNodes("FILTER"))
{
filters.Add(new Filter(subNode));

// if there's an "All parts" subcategory, add the filters to it
if (Core.Instance.categoryAllSub.ContainsKey(category))
Core.Instance.categoryAllSub[category].AddNode(subNode);
}
filter = filters.Count > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ CATEGORY:NEEDS[NearFuturePropulsion|NearFutureElectrical|NearFutureConstruction|
colour = #FFF0F0F0
type = mod
value = NearFuturePropulsion, NearFutureElectrical, NearFutureConstruction, NearFutureSolar, NearFutureSpacecraft
all = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ SUBCATEGORY
CHECK
{
type = propellant
value = Oxidizer
invert = true
value = IntakeAir
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ SUBCATEGORY
value = ModuleDeployableSolarPanel
}
}
FILTER
{
CHECK
{
type = moduleName
value = ModuleCurvedSolarPanel
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBCATEGORY
SUBCATEGORY:NEEDS[ConnectedLivingSpace]
{
category = Filter by Module
name = Connected Living Space
Expand Down
Binary file modified GameData/000_FilterExtensions/FilterCreator.dll
Binary file not shown.
Binary file modified GameData/000_FilterExtensions/FilterExtensions.dll
Binary file not shown.

0 comments on commit 760ba87

Please sign in to comment.