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

Commit

Permalink
1.1 compatiblity
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Apr 21, 2016
1 parent 5510b63 commit 3ec3523
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 223 deletions.
61 changes: 35 additions & 26 deletions FilterExtension/ConfigNodes/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FilterExtensions.ConfigNodes
{
using Utility;

public class Check
public class Check : ICloneable
{
public enum CheckType
{
Expand Down Expand Up @@ -139,13 +139,17 @@ public Check(ConfigNode node)
public Check(Check c)
{
type = c.type;
values = (string[])c.values.Clone();
if (c.values != null)
values = (string[])c.values.Clone();
invert = c.invert;
contains = c.contains;

checks = new List<Check>();
for (int i = 0; i < c.checks.Count; i++)
checks.Add(new Check(c.checks[i]));
if (c.checks != null)
{
checks = new List<Check>(c.checks.Count);
for (int i = 0; i < c.checks.Count; ++i)
checks.Add(new Check(c.checks[i]));
}
}

public Check(string Type, string Value, bool Invert = false, bool Contains = true, Equality Compare = Equality.Equals)
Expand All @@ -161,26 +165,6 @@ public Check(string Type, string Value, bool Invert = false, bool Contains = tru
checks = new List<Check>();
}

public ConfigNode toConfigNode()
{
ConfigNode node = new ConfigNode("CHECK");
node.AddValue("type", type.typeString);

if (values != null)
node.AddValue("value", string.Join(",", values));
node.AddValue("invert", invert.ToString());

if (type.usesContains)
node.AddValue("contains", contains.ToString());
if (type.usesEquality)
node.AddValue("equality", equality.ToString());

foreach (Check c in this.checks)
node.AddNode(c.toConfigNode());

return node;
}

public bool checkPart(AvailablePart part, int depth = 0)
{
bool result = true;
Expand Down Expand Up @@ -286,7 +270,32 @@ public static CheckParameters getCheckType(string type)

public bool isEmpty()
{
return !checks.Any() || values == null || values.Length > 0;
return !checks.Any() && (values == null || values.Length == 0);
}

public ConfigNode toConfigNode()
{
ConfigNode node = new ConfigNode("CHECK");
node.AddValue("type", type.typeString);

if (values != null)
node.AddValue("value", string.Join(",", values));
node.AddValue("invert", invert.ToString());

if (type.usesContains)
node.AddValue("contains", contains.ToString());
if (type.usesEquality)
node.AddValue("equality", equality.ToString());

foreach (Check c in this.checks)
node.AddNode(c.toConfigNode());

return node;
}

public object Clone()
{
return new Check(this);
}

public bool Equals(Check c2)
Expand Down
14 changes: 7 additions & 7 deletions FilterExtension/ConfigNodes/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FilterExtensions.ConfigNodes
{
public class Filter
public class Filter : ICloneable
{
public List<Check> checks { get; set; } // checks are processed in serial (a && b), inversion gives (!a || !b) logic
public bool invert { get; set; }
Expand Down Expand Up @@ -52,14 +52,14 @@ public ConfigNode toConfigNode()
return node;
}

public object Clone()
{
return new Filter(this);
}

internal bool checkFilter(AvailablePart part, int depth = 0)
{
for (int i = 0; i < checks.Count; i++)
{
if (!checks[i].checkPart(part, depth))
return invert ? true : false;
}
return invert ? false : true;
return invert ? !checks.All(c => c.checkPart(part, depth)) : checks.All(c => c.checkPart(part, depth));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions FilterExtension/ConfigNodes/customCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void initialise()
continue;
}

List<string> conflictsList;
//List<string> conflictsList;
#warning subcategory conflicts are broken and doing stupid things
//if (Core.Instance.conflictsDict.TryGetValue(subcategoryItem.subcategoryName, out conflictsList))
//{
Expand All @@ -156,7 +156,7 @@ public void initialise()
// }
//}

customSubCategory sC = new customSubCategory(subcategory.toConfigNode());
customSubCategory sC = new customSubCategory(subcategory);
if (subcategoryItem.applyTemplate)
sC.template = templates;

Expand Down
20 changes: 19 additions & 1 deletion FilterExtension/ConfigNodes/customSubCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FilterExtensions.ConfigNodes
{
using KSP.UI.Screens;
public class customSubCategory
public class customSubCategory : ICloneable
{
public string subCategoryTitle { get; set; } // title of this subcategory
public string iconName { get; set; } // default icon to use
Expand Down Expand Up @@ -39,6 +39,19 @@ public customSubCategory(ConfigNode node)
template = new List<Filter>();
}

public customSubCategory(customSubCategory subCat)
{
subCategoryTitle = subCat.subCategoryTitle;
iconName = subCat.iconName;
filters = new List<Filter>(subCat.filters.Count);
subCat.filters.ForEach(f => filters.Add(new Filter(f)));

template = new List<Filter>(subCat.template.Count);
subCat.template.ForEach(f => template.Add(new Filter(f)));

unPurchasedOverride = subCat.unPurchasedOverride;
}

public customSubCategory(string name, string icon)
{
filters = new List<Filter>();
Expand Down Expand Up @@ -77,6 +90,11 @@ public ConfigNode toConfigNode()
return node;
}

public object Clone()
{
return new customSubCategory(this);
}

/// <summary>
/// called by subcategory check type, has depth limit protection
/// </summary>
Expand Down
38 changes: 0 additions & 38 deletions FilterExtension/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ private void generateEngineTypes()
f.checks = checks;
sC.filters.Add(f);
subCategoriesDict.Add(name, sC);

Log(sC.toConfigNode());
}
}
}
Expand Down Expand Up @@ -373,42 +371,6 @@ private bool stringListComparer(List<string> propellants)
return false;
}

/// <summary>
/// refresh the visible subcategories to ensure all changes are visible
/// </summary>
public static void setSelectedCategory()
{
try
{
PartCategorizer.Category Filter = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.activeButton.CurrentState == KSP.UI.UIRadioButton.State.True);
if (Filter != null)
Filter.button.activeButton.SetState(KSP.UI.UIRadioButton.State.False, KSP.UI.UIRadioButton.CallType.APPLICATIONSILENT, null);

Filter = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.categoryName == Settings.categoryDefault);
if (Filter != null)
Filter.button.activeButton.SetState(KSP.UI.UIRadioButton.State.True, KSP.UI.UIRadioButton.CallType.APPLICATIONSILENT, null);
else
{
Filter = PartCategorizer.Instance.filters[0];
if (Filter != null)
{
Filter.button.activeButton.SetState(KSP.UI.UIRadioButton.State.True, KSP.UI.UIRadioButton.CallType.APPLICATIONSILENT, null);
}
}

// set the subcategory button
//Filter = Filter.subcategories.FirstOrDefault(sC => sC.button.categoryName == instance.subCategoryDefault);
//if (Filter != null && Filter.button.activeButton.State != RUIToggleButtonTyped.ButtonState.TRUE)
// Filter.button.activeButton.SetTrue(Filter.button.activeButton, RUIToggleButtonTyped.ClickType.FORCED);
}
catch (Exception e)
{
Log("Category refresh failed");
Log(e.InnerException);
Log(e.StackTrace);
}
}

/// <summary>
/// mark all subcategories that have identical filtering
/// </summary>
Expand Down
38 changes: 37 additions & 1 deletion FilterExtension/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,47 @@ IEnumerator editorInit()
yield return null;
if (Settings.debug)
Core.Log("Refreshing parts list");
Core.setSelectedCategory();
setSelectedCategory();

ready = true;
}

/// <summary>
/// refresh the visible subcategories to ensure all changes are visible
/// </summary>
public static void setSelectedCategory()
{
//try
//{
// PartCategorizer.Category Filter = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.activeButton.CurrentState == KSP.UI.UIRadioButton.State.True);
// if (Filter != null)
// Filter.button.activeButton.SetState(KSP.UI.UIRadioButton.State.False, KSP.UI.UIRadioButton.CallType.APPLICATIONSILENT, null);

// Filter = PartCategorizer.Instance.filters.FirstOrDefault(f => f.button.categoryName == Settings.categoryDefault);
// if (Filter != null)
// Filter.button.activeButton.SetState(KSP.UI.UIRadioButton.State.True, KSP.UI.UIRadioButton.CallType.APPLICATIONSILENT, null);
// else
// {
// Filter = PartCategorizer.Instance.filters[0];
// if (Filter != null)
// {
// Filter.button.activeButton.SetState(KSP.UI.UIRadioButton.State.True, KSP.UI.UIRadioButton.CallType.APPLICATIONSILENT, null);
// }
// }

// // set the subcategory button
// //Filter = Filter.subcategories.FirstOrDefault(sC => sC.button.categoryName == instance.subCategoryDefault);
// //if (Filter != null && Filter.button.activeButton.State != RUIToggleButtonTyped.ButtonState.TRUE)
// // Filter.button.activeButton.SetTrue(Filter.button.activeButton, RUIToggleButtonTyped.ClickType.FORCED);
//}
//catch (Exception e)
//{
// Core.Log("Category refresh failed");
// Core.Log(e.InnerException);
// Core.Log(e.StackTrace);
//}
}

/// <summary>
/// checks all subcats not created by FE for visibility of parts set to "category = none"
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion FilterExtension/Utility/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static bool checkCrewCapacity(AvailablePart part, string[] value, ConfigN
else // only compare against the first value here
{
if (value.Length > 1)
Core.Log("Size comparisons against multiple values when not using Equals only use the first value. Value list is: {0}", string.Join(", ", value));
Core.Log("Crew comparisons against multiple values when not using Equals only use the first value. Value list is: {0}", string.Join(", ", value));

int i;
if (int.TryParse(value[0], out i))
Expand Down

This file was deleted.

Loading

0 comments on commit 3ec3523

Please sign in to comment.