Merge pull request #12381 from pchote/upgrade-conditions
Upgrades overhaul part 1: EnabledCondition
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>();
|
||||
@@ -220,7 +222,7 @@ namespace OpenRA.Support
|
||||
return new VariableToken(start, expression.Substring(start));
|
||||
}
|
||||
|
||||
static bool ParseSymbol(VariableToken t, Dictionary<string, bool> symbols)
|
||||
static bool ParseSymbol(VariableToken t, IReadOnlyDictionary<string, bool> symbols)
|
||||
{
|
||||
bool value;
|
||||
symbols.TryGetValue(t.Symbol, out value);
|
||||
@@ -269,7 +271,7 @@ namespace OpenRA.Support
|
||||
yield return s.Pop();
|
||||
}
|
||||
|
||||
public bool Evaluate(Dictionary<string, bool> symbols)
|
||||
public bool Evaluate(IReadOnlyDictionary<string, bool> symbols)
|
||||
{
|
||||
var s = new Stack<bool>();
|
||||
foreach (var t in postfix)
|
||||
|
||||
Reference in New Issue
Block a user