Rename ConditionExpression => VariableExpression
This commit is contained in:
@@ -398,13 +398,13 @@ namespace OpenRA
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType == typeof(ConditionExpression))
|
||||
else if (fieldType == typeof(VariableExpression))
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new ConditionExpression(value);
|
||||
return new VariableExpression(value);
|
||||
}
|
||||
catch (InvalidDataException e)
|
||||
{
|
||||
|
||||
@@ -260,7 +260,7 @@
|
||||
<Compile Include="Primitives\float3.cs" />
|
||||
<Compile Include="InstalledMods.cs" />
|
||||
<Compile Include="CryptoUtil.cs" />
|
||||
<Compile Include="Support\ConditionExpression.cs" />
|
||||
<Compile Include="Support\VariableExpression.cs" />
|
||||
<Compile Include="ExternalMods.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -18,7 +18,7 @@ using Expressions = System.Linq.Expressions;
|
||||
|
||||
namespace OpenRA.Support
|
||||
{
|
||||
public class ConditionExpression
|
||||
public class VariableExpression
|
||||
{
|
||||
public readonly string Expression;
|
||||
readonly HashSet<string> variables = new HashSet<string>();
|
||||
@@ -525,7 +525,7 @@ namespace OpenRA.Support
|
||||
}
|
||||
}
|
||||
|
||||
public ConditionExpression(string expression)
|
||||
public VariableExpression(string expression)
|
||||
{
|
||||
Expression = expression;
|
||||
var tokens = new List<Token>();
|
||||
@@ -29,9 +29,9 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (typeof(IEnumerable<string>).IsAssignableFrom(type))
|
||||
return fieldInfo.GetValue(ruleInfo) as IEnumerable<string>;
|
||||
|
||||
if (type == typeof(ConditionExpression))
|
||||
if (type == typeof(VariableExpression))
|
||||
{
|
||||
var expr = (ConditionExpression)fieldInfo.GetValue(ruleInfo);
|
||||
var expr = (VariableExpression)fieldInfo.GetValue(ruleInfo);
|
||||
return expr != null ? expr.Variables : Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (typeof(IEnumerable).IsAssignableFrom(type))
|
||||
return (IEnumerable<string>)propertyInfo.GetValue(ruleInfo);
|
||||
|
||||
if (type == typeof(ConditionExpression))
|
||||
if (type == typeof(VariableExpression))
|
||||
{
|
||||
var expr = (ConditionExpression)propertyInfo.GetValue(ruleInfo);
|
||||
var expr = (VariableExpression)propertyInfo.GetValue(ruleInfo);
|
||||
return expr != null ? expr.Variables : Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
[ConsumedConditionReference]
|
||||
[Desc("Boolean expression defining the condition to enable this trait.")]
|
||||
public readonly ConditionExpression RequiresCondition = null;
|
||||
public readonly VariableExpression RequiresCondition = null;
|
||||
|
||||
public abstract object Create(ActorInitializer init);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Requirements for accepting a plug type.",
|
||||
"Key is the plug type that the requirements applies to.",
|
||||
"Value is the condition expression defining the requirements to place the plug.")]
|
||||
public readonly Dictionary<string, ConditionExpression> Requirements = new Dictionary<string, ConditionExpression>();
|
||||
public readonly Dictionary<string, VariableExpression> Requirements = new Dictionary<string, VariableExpression>();
|
||||
|
||||
[GrantedConditionReference]
|
||||
public IEnumerable<string> LinterConditions { get { return Conditions.Values; } }
|
||||
|
||||
@@ -19,7 +19,7 @@ using OpenRA.Support;
|
||||
namespace OpenRA.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ConditionExpressionTest
|
||||
public class VariableExpressionTest
|
||||
{
|
||||
IReadOnlyDictionary<string, int> testValues = new ReadOnlyDictionary<string, int>(new Dictionary<string, int>()
|
||||
{
|
||||
@@ -29,28 +29,28 @@ namespace OpenRA.Test
|
||||
|
||||
void AssertFalse(string expression)
|
||||
{
|
||||
Assert.False(new ConditionExpression(expression).Evaluate(testValues) > 0, expression);
|
||||
Assert.False(new VariableExpression(expression).Evaluate(testValues) > 0, expression);
|
||||
}
|
||||
|
||||
void AssertTrue(string expression)
|
||||
{
|
||||
Assert.True(new ConditionExpression(expression).Evaluate(testValues) > 0, expression);
|
||||
Assert.True(new VariableExpression(expression).Evaluate(testValues) > 0, expression);
|
||||
}
|
||||
|
||||
void AssertValue(string expression, int value)
|
||||
{
|
||||
Assert.AreEqual(value, new ConditionExpression(expression).Evaluate(testValues), expression);
|
||||
Assert.AreEqual(value, new VariableExpression(expression).Evaluate(testValues), expression);
|
||||
}
|
||||
|
||||
void AssertParseFailure(string expression)
|
||||
{
|
||||
Assert.Throws(typeof(InvalidDataException), () => new ConditionExpression(expression).Evaluate(testValues), expression);
|
||||
Assert.Throws(typeof(InvalidDataException), () => new VariableExpression(expression).Evaluate(testValues), expression);
|
||||
}
|
||||
|
||||
void AssertParseFailure(string expression, string errorMessage)
|
||||
{
|
||||
var actualErrorMessage = Assert.Throws(typeof(InvalidDataException),
|
||||
() => new ConditionExpression(expression).Evaluate(testValues),
|
||||
() => new VariableExpression(expression).Evaluate(testValues),
|
||||
expression).Message;
|
||||
Assert.AreEqual(errorMessage, actualErrorMessage, expression + " ===> " + actualErrorMessage);
|
||||
}
|
||||
@@ -55,7 +55,7 @@
|
||||
<Compile Include="OpenRA.Mods.Common\ShapeTest.cs" />
|
||||
<Compile Include="OpenRA.Game\OrderTest.cs" />
|
||||
<Compile Include="OpenRA.Game\PlatformTest.cs" />
|
||||
<Compile Include="OpenRA.Game\ConditionExpressionTest.cs" />
|
||||
<Compile Include="OpenRA.Game\VariableExpressionTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
|
||||
Reference in New Issue
Block a user