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

Commit

Permalink
always check for null...
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Nov 19, 2016
1 parent 6a37660 commit 7bd7eba
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
3 changes: 2 additions & 1 deletion FilterExtension/ConfigNodes/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum CheckType

public enum Equality
{
String,
Equals, // default
LessThan,
GreaterThan
Expand Down Expand Up @@ -253,7 +254,7 @@ public bool checkResult(AvailablePart part, int depth = 0)
return true;

case CheckType.field:
return invert ^ PartType.NodeCheck(part, values);
return invert ^ PartType.NodeCheck(part, values, equality);

default:
Core.Log("invalid Check type specified", Core.LogLevel.Warn);
Expand Down
2 changes: 1 addition & 1 deletion FilterExtension/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FilterExtensions
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class Core : MonoBehaviour
{
public static readonly Version version = new Version(2, 7, 1, 0);
public static readonly Version version = new Version(2, 8, 0, 0);

private static Core instance;
public static Core Instance
Expand Down
52 changes: 41 additions & 11 deletions FilterExtension/Utility/PartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -834,24 +834,54 @@ public static bool Contains<T>(string[] CheckParams, IEnumerable<T> partParams,

public static char[] splitChars = new char[] { ',', ' ', '.' };

public static bool NodeCheck(AvailablePart part, string[] parameters)
public static bool NodeCheck(AvailablePart part, string[] parameters, ConfigNodes.Check.Equality equality = ConfigNodes.Check.Equality.Equals)
{
Type baseType;
if (parameters.Length < 3
|| !Loaded_Modules.TryGetValue(parameters[0], out baseType))
return false;
foreach (PartModule pm in part.partPrefab.Modules)
try
{
if (baseType.IsAssignableFrom(Loaded_Modules[pm.moduleName]))
Type baseType;
if (parameters.Length < 3
|| !Loaded_Modules.TryGetValue(parameters[0], out baseType))
return false;
foreach (PartModule pm in part.partPrefab.Modules)
{
BaseField f = pm.Fields[parameters[1]];
if (f == null)
if (baseType.IsAssignableFrom(Loaded_Modules[pm.moduleName]))
{
return false;
BaseField f = pm.Fields[parameters[1]];
if (f == null)
{
return false;
}
double res, org;
if (f.originalValue == null)
{
return parameters[2].Equals("null", StringComparison.OrdinalIgnoreCase);
}
else if (!double.TryParse(parameters[2], out res) || !double.TryParse(f.originalValue.ToString(), out org))
{
return string.Equals(parameters[2], f.originalValue.ToString(), StringComparison.OrdinalIgnoreCase);
}
else
{
if (equality == ConfigNodes.Check.Equality.Equals)
{
return org == res;
}
else if (equality == ConfigNodes.Check.Equality.GreaterThan)
{
return org > res;
}
else if (equality == ConfigNodes.Check.Equality.LessThan)
{
return org < res;
}
}
}
return string.Equals(parameters[2], f.originalValue.ToString(), StringComparison.OrdinalIgnoreCase);
}
}
catch (Exception ex)
{
UnityEngine.Debug.LogException(ex);
}
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Testing/ByTitle - Copy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SUBCATEGORY
CHECK
{
type = field
value = ModuleEngines,exhaustDamage,false
value = ModuleScienceExperiment,experimentID,probeReport
}
}
}
Expand Down

0 comments on commit 7bd7eba

Please sign in to comment.