Added (Boolean|Integer)Expression subclasses of VariableExpression

This commit is contained in:
atlimit8
2017-04-11 02:52:54 -05:00
parent e73d3922dd
commit b0187dd646
6 changed files with 79 additions and 24 deletions

View File

@@ -29,13 +29,13 @@ namespace OpenRA.Mods.Common.Lint
if (typeof(IEnumerable<string>).IsAssignableFrom(type))
return fieldInfo.GetValue(ruleInfo) as IEnumerable<string>;
if (type == typeof(VariableExpression))
if (type == typeof(BooleanExpression) || type == typeof(IntegerExpression))
{
var expr = (VariableExpression)fieldInfo.GetValue(ruleInfo);
return expr != null ? expr.Variables : Enumerable.Empty<string>();
}
throw new InvalidOperationException("Bad type for reference on {0}.{1}. Supported types: string, IEnumerable<string>, BooleanExpression"
throw new InvalidOperationException("Bad type for reference on {0}.{1}. Supported types: string, IEnumerable<string>, BooleanExpression, IntegerExpression"
.F(ruleInfo.GetType().Name, fieldInfo.Name));
}
@@ -48,13 +48,13 @@ namespace OpenRA.Mods.Common.Lint
if (typeof(IEnumerable).IsAssignableFrom(type))
return (IEnumerable<string>)propertyInfo.GetValue(ruleInfo);
if (type == typeof(VariableExpression))
if (type == typeof(BooleanExpression) || type == typeof(IntegerExpression))
{
var expr = (VariableExpression)propertyInfo.GetValue(ruleInfo);
return expr != null ? expr.Variables : Enumerable.Empty<string>();
}
throw new InvalidOperationException("Bad type for reference on {0}.{1}. Supported types: string, IEnumerable<string>, BooleanExpression"
throw new InvalidOperationException("Bad type for reference on {0}.{1}. Supported types: string, IEnumerable<string>, BooleanExpression, IntegerExpression"
.F(ruleInfo.GetType().Name, propertyInfo.Name));
}
}

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
[ConsumedConditionReference]
[Desc("Boolean expression defining the condition to enable this trait.")]
public readonly VariableExpression RequiresCondition = null;
public readonly BooleanExpression RequiresCondition = null;
public abstract object Create(ActorInitializer init);
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
EnabledByDefault = RequiresCondition != null ? RequiresCondition.Evaluate(NoConditions) > 0 : true;
EnabledByDefault = RequiresCondition == null || RequiresCondition.Evaluate(NoConditions);
}
}
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits
return;
var wasDisabled = IsTraitDisabled;
IsTraitDisabled = Info.RequiresCondition.Evaluate(conditions) <= 0;
IsTraitDisabled = !Info.RequiresCondition.Evaluate(conditions);
if (IsTraitDisabled != wasDisabled)
{

View File

@@ -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, VariableExpression> Requirements = new Dictionary<string, VariableExpression>();
public readonly Dictionary<string, BooleanExpression> Requirements = new Dictionary<string, BooleanExpression>();
[GrantedConditionReference]
public IEnumerable<string> LinterConditions { get { return Conditions.Values; } }
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
void IConditionConsumer.ConditionsChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
{
foreach (var req in Info.Requirements)
plugTypesAvailability[req.Key] = req.Value.Evaluate(conditions) != 0;
plugTypesAvailability[req.Key] = req.Value.Evaluate(conditions);
}
}