Merge ConditionManager trait directly into Actor

This commit is contained in:
atlimit8
2020-04-18 23:25:05 -05:00
committed by reaperrr
parent e12c1dc9aa
commit 259c8d2c98
65 changed files with 466 additions and 707 deletions

View File

@@ -39,8 +39,7 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly WithSpriteBody[] wsbs;
readonly bool skipMakeAnimation;
ConditionManager conditionManager;
int token = ConditionManager.InvalidConditionToken;
int token = Actor.InvalidConditionToken;
public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info)
{
@@ -52,15 +51,14 @@ namespace OpenRA.Mods.Common.Traits.Render
void INotifyCreated.Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
if (!skipMakeAnimation)
Forward(self, () => { });
}
public void Forward(Actor self, Action onComplete)
{
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition) && token == ConditionManager.InvalidConditionToken)
token = conditionManager.GrantCondition(self, info.Condition);
if (!string.IsNullOrEmpty(info.Condition) && token == Actor.InvalidConditionToken)
token = self.GrantCondition(info.Condition);
var wsb = wsbs.FirstEnabledTraitOrDefault();
@@ -71,8 +69,8 @@ namespace OpenRA.Mods.Common.Traits.Render
{
self.World.AddFrameEndTask(w =>
{
if (token != ConditionManager.InvalidConditionToken)
token = conditionManager.RevokeCondition(self, token);
if (token != Actor.InvalidConditionToken)
token = self.RevokeCondition(token);
// TODO: Rewrite this to use a trait notification for save game support
onComplete();
@@ -82,8 +80,8 @@ namespace OpenRA.Mods.Common.Traits.Render
public void Reverse(Actor self, Action onComplete)
{
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition) && token == ConditionManager.InvalidConditionToken)
token = conditionManager.GrantCondition(self, info.Condition);
if (!string.IsNullOrEmpty(info.Condition) && token == Actor.InvalidConditionToken)
token = self.GrantCondition(info.Condition);
var wsb = wsbs.FirstEnabledTraitOrDefault();
@@ -94,8 +92,8 @@ namespace OpenRA.Mods.Common.Traits.Render
{
self.World.AddFrameEndTask(w =>
{
if (token != ConditionManager.InvalidConditionToken)
token = conditionManager.RevokeCondition(self, token);
if (token != Actor.InvalidConditionToken)
token = self.RevokeCondition(token);
// TODO: Rewrite this to use a trait notification for save game support
onComplete();
@@ -116,8 +114,8 @@ namespace OpenRA.Mods.Common.Traits.Render
if (wsb != null)
wsb.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0);
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition))
token = conditionManager.GrantCondition(self, info.Condition);
if (!string.IsNullOrEmpty(info.Condition))
token = self.GrantCondition(info.Condition);
self.QueueActivity(queued, activity);
});