Merge pull request #13108 from atlimit8/ConditionsToVariables

ConditionExpression to (Boolean|Integer)Expression refactor
This commit is contained in:
reaperrr
2017-04-17 14:52:21 +02:00
committed by GitHub
8 changed files with 85 additions and 30 deletions

View File

@@ -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 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, ConditionExpression> Requirements = new Dictionary<string, ConditionExpression>();
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);
}
}