Add FieldLoader and linter support for BooleanExpression.
This commit is contained in:
@@ -15,12 +15,14 @@ using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -396,6 +398,22 @@ namespace OpenRA
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType == typeof(BooleanExpression))
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new BooleanExpression(value);
|
||||
}
|
||||
catch (InvalidDataException e)
|
||||
{
|
||||
throw new YamlException(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType.IsEnum)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace OpenRA.Support
|
||||
{
|
||||
public class BooleanExpression
|
||||
{
|
||||
public readonly string Expression;
|
||||
readonly HashSet<string> variables = new HashSet<string>();
|
||||
public IEnumerable<string> Variables { get { return variables; } }
|
||||
|
||||
@@ -68,6 +69,7 @@ namespace OpenRA.Support
|
||||
|
||||
public BooleanExpression(string expression)
|
||||
{
|
||||
Expression = expression;
|
||||
var openParens = 0;
|
||||
var closeParens = 0;
|
||||
var tokens = new List<Token>();
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
@@ -26,8 +28,13 @@ namespace OpenRA.Mods.Common.Lint
|
||||
return (string[])fieldInfo.GetValue(ruleInfo);
|
||||
if (type == typeof(HashSet<string>))
|
||||
return (HashSet<string>)fieldInfo.GetValue(ruleInfo);
|
||||
if (type == typeof(BooleanExpression))
|
||||
{
|
||||
var expr = (BooleanExpression)fieldInfo.GetValue(ruleInfo);
|
||||
return expr != null ? expr.Variables : Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
emitError("Bad type for reference on {0}.{1}. Supported types: string, string[], HashSet<string>"
|
||||
emitError("Bad type for reference on {0}.{1}. Supported types: string, string[], HashSet<string>, BooleanExpression"
|
||||
.F(ruleInfo.GetType().Name, fieldInfo.Name));
|
||||
|
||||
return new string[] { };
|
||||
|
||||
Reference in New Issue
Block a user