Merge pull request #12284 from reaperrr/interface-cleanups02

More explicit interface cleanups
This commit is contained in:
Paul Chote
2016-10-30 18:40:43 +00:00
committed by GitHub
23 changed files with 77 additions and 38 deletions

View File

@@ -130,7 +130,6 @@ namespace OpenRA.Traits
public interface INotifyAddedToWorld { void AddedToWorld(Actor self); } public interface INotifyAddedToWorld { void AddedToWorld(Actor self); }
public interface INotifyRemovedFromWorld { void RemovedFromWorld(Actor self); } public interface INotifyRemovedFromWorld { void RemovedFromWorld(Actor self); }
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); } public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
public interface INotifyActorDisposing { void Disposing(Actor self); } public interface INotifyActorDisposing { void Disposing(Actor self); }
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Cnc.Traits
return true; return true;
} }
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
if (state == PopupState.Open && idleTicks++ > info.CloseDelay) if (state == PopupState.Open && idleTicks++ > info.CloseDelay)
{ {
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Cnc.Traits
} }
} }
public void BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
{ {
if (skippedMakeAnimation) if (skippedMakeAnimation)
{ {

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
ammoSuffix = (initialAmmoStage * reloadStages / ammo).ToString(); ammoSuffix = (initialAmmoStage * reloadStages / ammo).ToString();
} }
public override void Tick(Actor self) protected override void Tick(Actor self)
{ {
if (Info.AimSequence != null) if (Info.AimSequence != null)
sequence = Attack.IsAttacking ? Info.AimSequence : Info.Sequence; sequence = Attack.IsAttacking ? Info.AimSequence : Info.Sequence;

View File

@@ -302,7 +302,7 @@ namespace OpenRA.Mods.Common.Scripting
OnCapturedInternal(self); OnCapturedInternal(self);
} }
public void Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
if (world.Disposing) if (world.Disposing)
return; return;

View File

@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Common.Traits
return new WDist(Util.ApplyPercentageModifiers(Weapon.Range.Length, rangeModifiers)); return new WDist(Util.ApplyPercentageModifiers(Weapon.Range.Length, rangeModifiers));
} }
public virtual void Created(Actor self) protected virtual void Created(Actor self)
{ {
turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret); turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret);
ammoPool = self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == Info.AmmoPoolName); ammoPool = self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == Info.AmmoPoolName);
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Traits
rangeModifiers = self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier()); rangeModifiers = self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier());
} }
public virtual void Tick(Actor self) protected virtual void Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
return; return;
@@ -168,6 +168,18 @@ namespace OpenRA.Mods.Common.Traits
delayedActions.RemoveAll(a => a.First <= 0); delayedActions.RemoveAll(a => a.First <= 0);
} }
void INotifyCreated.Created(Actor self)
{
// Split into a protected method to allow subclassing
Created(self);
}
void ITick.Tick(Actor self)
{
// Split into a protected method to allow subclassing
Tick(self);
}
protected void ScheduleDelayedAction(int t, Action a) protected void ScheduleDelayedAction(int t, Action a)
{ {
if (t > 0) if (t > 0)

View File

@@ -308,7 +308,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void DamageStateChanged(Actor self, AttackInfo e) void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{ {
Do((b, d) => b.UpdateState()); Do((b, d) => b.UpdateState());

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
} }
public void DamageStateChanged(Actor self, AttackInfo e) void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{ {
if (!self.IsInWorld) if (!self.IsInWorld)
return; return;

View File

@@ -105,13 +105,13 @@ namespace OpenRA.Mods.Common.Traits
self.QueueActivity(new CallFunc(() => ChooseNewProc(self, null))); self.QueueActivity(new CallFunc(() => ChooseNewProc(self, null)));
} }
public void Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
if (Info.SearchOnCreation) if (Info.SearchOnCreation)
self.QueueActivity(new FindResources(self)); self.QueueActivity(new FindResources(self));
} }
public void BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
{ {
if (Info.SearchOnCreation) if (Info.SearchOnCreation)
self.QueueActivity(new FindResources(self)); self.QueueActivity(new FindResources(self));
@@ -254,7 +254,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public void TickIdle(Actor self) void INotifyIdle.TickIdle(Actor self)
{ {
// Should we be intelligent while idle? // Should we be intelligent while idle?
if (!idleSmart) return; if (!idleSmart) return;

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector, ITick class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick
{ {
readonly WithGateSpriteBodyInfo gateInfo; readonly WithGateSpriteBodyInfo gateInfo;
readonly Gate gate; readonly Gate gate;
@@ -83,12 +83,12 @@ namespace OpenRA.Mods.Common.Traits.Render
return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition); return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition);
} }
public override void DamageStateChanged(Actor self, AttackInfo e) protected override void DamageStateChanged(Actor self)
{ {
UpdateState(self); UpdateState(self);
} }
public override void BuildingComplete(Actor self) protected override void OnBuildComplete(Actor self)
{ {
UpdateState(self); UpdateState(self);
UpdateNeighbours(self); UpdateNeighbours(self);
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits.Render
rb.SetDirty(); rb.SetDirty();
} }
public void RemovedFromWorld(Actor self) void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{ {
UpdateNeighbours(self); UpdateNeighbours(self);
} }

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits.Render
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>(); playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
} }
public void BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
{ {
wsb.DefaultAnimation.PlayFetchIndex(wsb.NormalizeSequence(self, info.Sequence), wsb.DefaultAnimation.PlayFetchIndex(wsb.NormalizeSequence(self, info.Sequence),
() => playerResources.ResourceCapacity != 0 () => playerResources.ResourceCapacity != 0
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits.Render
: 0); : 0);
} }
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{ {
playerResources = newOwner.PlayerActor.Trait<PlayerResources>(); playerResources = newOwner.PlayerActor.Trait<PlayerResources>();

View File

@@ -75,12 +75,17 @@ namespace OpenRA.Mods.Common.Traits.Render
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence); return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
} }
// TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system protected virtual void OnBuildComplete(Actor self)
public virtual void BuildingComplete(Actor self)
{ {
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence)); DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
} }
// TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system
void INotifyBuildComplete.BuildingComplete(Actor self)
{
OnBuildComplete(self);
}
public void PlayCustomAnimation(Actor self, string name, Action after = null) public void PlayCustomAnimation(Actor self, string name, Action after = null)
{ {
DefaultAnimation.PlayThen(NormalizeSequence(self, name), () => DefaultAnimation.PlayThen(NormalizeSequence(self, name), () =>
@@ -112,10 +117,15 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence)); DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
} }
public virtual void DamageStateChanged(Actor self, AttackInfo e) protected virtual void DamageStateChanged(Actor self)
{ {
if (DefaultAnimation.CurrentSequence != null) if (DefaultAnimation.CurrentSequence != null)
DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name)); DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name));
} }
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
DamageStateChanged(self);
}
} }
} }

View File

@@ -113,13 +113,13 @@ namespace OpenRA.Mods.Common.Traits.Render
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence); return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
} }
public virtual void DamageStateChanged(Actor self, AttackInfo e) protected virtual void DamageStateChanged(Actor self)
{ {
if (DefaultAnimation.CurrentSequence != null) if (DefaultAnimation.CurrentSequence != null)
DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name)); DefaultAnimation.ReplaceAnim(NormalizeSequence(self, DefaultAnimation.CurrentSequence.Name));
} }
public virtual void Tick(Actor self) protected virtual void Tick(Actor self)
{ {
if (Info.AimSequence == null) if (Info.AimSequence == null)
return; return;
@@ -128,6 +128,17 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation.ReplaceAnim(sequence); DefaultAnimation.ReplaceAnim(sequence);
} }
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
DamageStateChanged(self);
}
void ITick.Tick(Actor self)
{
// Split into a protected method to allow subclassing
Tick(self);
}
void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; } void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; }
void INotifySold.Selling(Actor self) { buildComplete = false; } void INotifySold.Selling(Actor self) { buildComplete = false; }
void INotifySold.Sold(Actor self) { } void INotifySold.Sold(Actor self) { }

View File

@@ -54,9 +54,9 @@ namespace OpenRA.Mods.Common.Traits.Render
turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
} }
public override void DamageStateChanged(Actor self, AttackInfo e) protected override void DamageStateChanged(Actor self)
{ {
base.DamageStateChanged(self, e); base.DamageStateChanged(self);
turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; turreted.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
} }
} }

View File

@@ -101,12 +101,12 @@ namespace OpenRA.Mods.Common.Traits.Render
wallInfo = info; wallInfo = info;
} }
public override void DamageStateChanged(Actor self, AttackInfo e) protected override void DamageStateChanged(Actor self)
{ {
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent); DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent);
} }
public void Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (!dirty) if (!dirty)
return; return;
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits.Render
dirty = false; dirty = false;
} }
public override void BuildingComplete(Actor self) protected override void OnBuildComplete(Actor self)
{ {
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent); DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent);
UpdateNeighbours(self); UpdateNeighbours(self);

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
this.info = info; this.info = info;
} }
public void BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
{ {
self.PlayVoice(info.Voice); self.PlayVoice(info.Voice);
} }

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
this.info = info; this.info = info;
} }
public void DamageStateChanged(Actor self, AttackInfo e) void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{ {
var rand = Game.CosmeticRandom; var rand = Game.CosmeticRandom;

View File

@@ -70,7 +70,12 @@ namespace OpenRA.Mods.Common.Traits
void PreparingAttack(Actor self, Target target, Armament a, Barrel barrel); void PreparingAttack(Actor self, Target target, Armament a, Barrel barrel);
} }
[RequireExplicitImplementation]
public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
[RequireExplicitImplementation]
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); } public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
public interface INotifyRepair { void Repairing(Actor self, Actor target); } public interface INotifyRepair { void Repairing(Actor self, Actor target); }
public interface INotifyBurstComplete { void FiredBurst(Actor self, Target target, Armament a); } public interface INotifyBurstComplete { void FiredBurst(Actor self, Target target, Armament a); }
@@ -82,11 +87,13 @@ namespace OpenRA.Mods.Common.Traits
public interface INotifyDocking { void Docked(Actor self, Actor harvester); void Undocked(Actor self, Actor harvester); } public interface INotifyDocking { void Docked(Actor self, Actor harvester); void Undocked(Actor self, Actor harvester); }
public interface INotifyParachuteLanded { void OnLanded(Actor ignore); } public interface INotifyParachuteLanded { void OnLanded(Actor ignore); }
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); }
public interface INotifyDiscovered { void OnDiscovered(Actor self, Player discoverer, bool playNotification); } public interface INotifyDiscovered { void OnDiscovered(Actor self, Player discoverer, bool playNotification); }
public interface IRenderActorPreviewInfo : ITraitInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); } public interface IRenderActorPreviewInfo : ITraitInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
public interface ICruiseAltitudeInfo : ITraitInfo { WDist GetCruiseAltitude(); } public interface ICruiseAltitudeInfo : ITraitInfo { WDist GetCruiseAltitude(); }
[RequireExplicitImplementation]
public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); }
[RequireExplicitImplementation] [RequireExplicitImplementation]
public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); } public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); }

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.D2k.Traits.Render
rs.Add(anim, info.Palette, info.IsPlayerPalette); rs.Add(anim, info.Palette, info.IsPlayerPalette);
} }
public void BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
{ {
buildComplete = true; buildComplete = true;
} }

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Traits
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; } public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }
public void Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>(); var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>(); var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>();

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Traits
public InfiltrateForDecoration(Actor self, InfiltrateForDecorationInfo info) public InfiltrateForDecoration(Actor self, InfiltrateForDecorationInfo info)
: base(self, info) { } : base(self, info) { }
public void Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
infiltrators.Add(infiltrator.Owner); infiltrators.Add(infiltrator.Owner);
} }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.Traits
class InfiltrateForExploration : INotifyInfiltrated class InfiltrateForExploration : INotifyInfiltrated
{ {
public void Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud); infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);
if (!self.Owner.HasFogVisibility) if (!self.Owner.HasFogVisibility)

View File

@@ -32,12 +32,12 @@ namespace OpenRA.Mods.RA.Traits
playerPower = self.Owner.PlayerActor.Trait<PowerManager>(); playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
} }
public void Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
playerPower.TriggerPowerOutage(info.Duration); playerPower.TriggerPowerOutage(info.Duration);
} }
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{ {
playerPower = self.Owner.PlayerActor.Trait<PowerManager>(); playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
} }

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Traits
this.info = info; this.info = info;
} }
public void Infiltrated(Actor self, Actor infiltrator) void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{ {
infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary
{ {