Replace IConditionConsumer w/ variable observers for multiple variable expressions for traits.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -44,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public object Create(ActorInitializer init) { return new Pluggable(init, this); }
|
||||
}
|
||||
|
||||
public class Pluggable : IConditionConsumer, INotifyCreated
|
||||
public class Pluggable : IObservesVariables, INotifyCreated
|
||||
{
|
||||
public readonly PluggableInfo Info;
|
||||
|
||||
@@ -114,12 +115,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
active = null;
|
||||
}
|
||||
|
||||
IEnumerable<string> IConditionConsumer.Conditions { get { return Info.ConsumedConditions; } }
|
||||
|
||||
void IConditionConsumer.ConditionsChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
|
||||
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
||||
{
|
||||
foreach (var req in Info.Requirements)
|
||||
plugTypesAvailability[req.Key] = req.Value.Evaluate(conditions);
|
||||
yield return new VariableObserver(
|
||||
(self, variables) => plugTypesAvailability[req.Key] = req.Value.Evaluate(variables),
|
||||
req.Value.Variables);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user