Remove IDisable for good
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Disable the actor when this trait is enabled by a condition.")]
|
||||
public class DisableOnConditionInfo : ConditionalTraitInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new DisableOnCondition(this); }
|
||||
}
|
||||
|
||||
public class DisableOnCondition : ConditionalTrait<DisableOnConditionInfo>, IDisable
|
||||
{
|
||||
public DisableOnCondition(DisableOnConditionInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public bool Disabled { get { return !IsTraitDisabled; } }
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Applies a condition to the actor when it is disabled.",
|
||||
"This is a temporary shim to help migration away from the legacy IDisable code")]
|
||||
public class GrantConditionOnDisabledInfo : ITraitInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[GrantedConditionReference]
|
||||
[Desc("Condition to grant.")]
|
||||
public readonly string Condition = null;
|
||||
|
||||
public object Create(ActorInitializer init) { return new GrantConditionOnDisabled(this); }
|
||||
}
|
||||
|
||||
public class GrantConditionOnDisabled : INotifyCreated, ITick
|
||||
{
|
||||
readonly GrantConditionOnDisabledInfo info;
|
||||
|
||||
ConditionManager conditionManager;
|
||||
int conditionToken = ConditionManager.InvalidConditionToken;
|
||||
|
||||
public GrantConditionOnDisabled(GrantConditionOnDisabledInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
|
||||
// Set initial disabled state
|
||||
Tick(self);
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
Tick(self);
|
||||
}
|
||||
|
||||
protected void Tick(Actor self)
|
||||
{
|
||||
if (conditionManager == null)
|
||||
return;
|
||||
|
||||
var disabled = self.IsDisabled();
|
||||
if (disabled && conditionToken == ConditionManager.InvalidConditionToken)
|
||||
conditionToken = conditionManager.GrantCondition(self, info.Condition);
|
||||
else if (!disabled && conditionToken != ConditionManager.InvalidConditionToken)
|
||||
conditionToken = conditionManager.RevokeCondition(self, conditionToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user