From 3d2aa751a3632b220a140e1c908c982a94542228 Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Mon, 7 Dec 2015 18:18:46 -0600 Subject: [PATCH] TraitInfoInterface base for interfaces implemented by trait infos --- OpenRA.Game/GameRules/ActorInfo.cs | 8 +++---- OpenRA.Game/Traits/TraitsInterfaces.cs | 29 ++++++++++++----------- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 2 +- OpenRA.Mods.Common/Traits/Crates/Crate.cs | 2 +- OpenRA.Mods.Common/Traits/Husk.cs | 2 +- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/OpenRA.Game/GameRules/ActorInfo.cs b/OpenRA.Game/GameRules/ActorInfo.cs index cac0cea4af..58e5665694 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -191,9 +191,9 @@ namespace OpenRA i.Name.Replace("Init", ""), i)); } - public bool HasTraitInfo() where T : ITraitInfo { return traits.Contains(); } - public T TraitInfo() where T : ITraitInfo { return traits.Get(); } - public T TraitInfoOrDefault() where T : ITraitInfo { return traits.GetOrDefault(); } - public IEnumerable TraitInfos() where T : ITraitInfo { return traits.WithInterface(); } + public bool HasTraitInfo() where T : ITraitInfoInterface { return traits.Contains(); } + public T TraitInfo() where T : ITraitInfoInterface { return traits.Get(); } + public T TraitInfoOrDefault() where T : ITraitInfoInterface { return traits.GetOrDefault(); } + public IEnumerable TraitInfos() where T : ITraitInfoInterface { return traits.WithInterface(); } } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index c1fdbeda35..9fcd13b39e 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -130,7 +130,7 @@ namespace OpenRA.Traits public interface ISeedableResource { void Seed(Actor self); } - public interface ISelectionDecorationsInfo : ITraitInfo + public interface ISelectionDecorationsInfo : ITraitInfoInterface { int[] SelectionBoxBounds { get; } } @@ -143,7 +143,7 @@ namespace OpenRA.Traits bool HasVoice(Actor self, string voice); } - public interface IDemolishableInfo : ITraitInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); } + public interface IDemolishableInfo : ITraitInfoInterface { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); } public interface IDemolishable { void Demolish(Actor self, Actor saboteur); @@ -165,7 +165,7 @@ namespace OpenRA.Traits Player Owner { get; } } - public interface ITooltipInfo : ITraitInfo + public interface ITooltipInfo : ITraitInfoInterface { string TooltipForPlayerStance(Stance stance); bool IsOwnerRowVisible { get; } @@ -187,7 +187,7 @@ namespace OpenRA.Traits IEnumerable> RadarSignatureCells(Actor self); } - public interface IDefaultVisibilityInfo : ITraitInfo { } + public interface IDefaultVisibilityInfo : ITraitInfoInterface { } public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); } public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); } @@ -199,7 +199,7 @@ namespace OpenRA.Traits public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } - public interface IOccupySpaceInfo : ITraitInfo + public interface IOccupySpaceInfo : ITraitInfoInterface { IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); bool SharesCell { get; } @@ -239,7 +239,7 @@ namespace OpenRA.Traits public interface IReloadModifier { int GetReloadModifier(); } public interface IInaccuracyModifier { int GetInaccuracyModifier(); } public interface IRangeModifier { int GetRangeModifier(); } - public interface IRangeModifierInfo : ITraitInfo { int GetRangeModifierDefault(); } + public interface IRangeModifierInfo : ITraitInfoInterface { int GetRangeModifierDefault(); } public interface IPowerModifier { int GetPowerModifier(); } public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); } public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); } @@ -248,7 +248,7 @@ namespace OpenRA.Traits public interface ITags { IEnumerable GetTags(); } public interface ISelectionBar { float GetValue(); Color GetColor(); } - public interface IPositionableInfo : ITraitInfo { } + public interface IPositionableInfo : ITraitInfoInterface { } public interface IPositionable : IOccupySpace { bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any); @@ -260,7 +260,7 @@ namespace OpenRA.Traits void SetVisualPosition(Actor self, WPos pos); } - public interface IMoveInfo : ITraitInfo { } + public interface IMoveInfo : ITraitInfoInterface { } public interface IMove { Activity MoveTo(CPos cell, int nearEnough); @@ -285,7 +285,7 @@ namespace OpenRA.Traits int Facing { get; set; } } - public interface IFacingInfo : ITraitInfo { int GetInitialFacing(); } + public interface IFacingInfo : ITraitInfoInterface { int GetInitialFacing(); } public interface ICrushable { @@ -294,12 +294,13 @@ namespace OpenRA.Traits bool CrushableBy(HashSet crushClasses, Player owner); } - public interface ITraitInfo { object Create(ActorInitializer init); } + public interface ITraitInfoInterface { } + public interface ITraitInfo : ITraitInfoInterface { object Create(ActorInitializer init); } public class TraitInfo : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } } [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")] - public interface Requires where T : class, ITraitInfo { } + public interface Requires where T : class, ITraitInfoInterface { } [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")] public interface UsesInit : ITraitInfo where T : IActorInit { } @@ -308,7 +309,7 @@ namespace OpenRA.Traits public interface IWorldLoaded { void WorldLoaded(World w, WorldRenderer wr); } public interface ICreatePlayers { void CreatePlayers(World w); } - public interface IBotInfo : ITraitInfo { string Name { get; } } + public interface IBotInfo : ITraitInfoInterface { string Name { get; } } public interface IBot { void Activate(Player p); @@ -331,7 +332,7 @@ namespace OpenRA.Traits public interface IPostRenderSelection { IEnumerable RenderAfterWorld(WorldRenderer wr); } - public interface ITargetableInfo : ITraitInfo + public interface ITargetableInfo : ITraitInfoInterface { HashSet GetTargetTypes(); } @@ -390,5 +391,5 @@ namespace OpenRA.Traits } public interface IRulesetLoaded { void RulesetLoaded(Ruleset rules, TInfo info); } - public interface IRulesetLoaded : IRulesetLoaded, ITraitInfo { } + public interface IRulesetLoaded : IRulesetLoaded, ITraitInfoInterface { } } diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 1346c54b40..8a34c7f4c0 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -20,7 +20,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class AircraftInfo : IPositionableInfo, IFacingInfo, IOccupySpaceInfo, IMoveInfo, ICruiseAltitudeInfo, + public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IOccupySpaceInfo, IMoveInfo, ICruiseAltitudeInfo, UsesInit, UsesInit { public readonly WDist CruiseAltitude = new WDist(1280); diff --git a/OpenRA.Mods.Common/Traits/Crates/Crate.cs b/OpenRA.Mods.Common/Traits/Crates/Crate.cs index 722c01c26d..4acbbfcaa4 100644 --- a/OpenRA.Mods.Common/Traits/Crates/Crate.cs +++ b/OpenRA.Mods.Common/Traits/Crates/Crate.cs @@ -15,7 +15,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - class CrateInfo : IPositionableInfo, IOccupySpaceInfo, Requires + class CrateInfo : ITraitInfo, IPositionableInfo, IOccupySpaceInfo, Requires { [Desc("Length of time (in seconds) until the crate gets removed automatically. " + "A value of zero disables auto-removal.")] diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index b5ab9c1134..766137de28 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -17,7 +17,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Spawns remains of a husk actor with the correct facing.")] - public class HuskInfo : IOccupySpaceInfo, IFacingInfo + public class HuskInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo { public readonly HashSet AllowedTerrain = new HashSet();