Merge pull request #10193 from atlimit8/ITraitInfoInterface

TraitInfoInterface base for interfaces implemented by trait infos
This commit is contained in:
abcdefg30
2015-12-29 15:04:57 +01:00
5 changed files with 22 additions and 21 deletions

View File

@@ -186,9 +186,9 @@ namespace OpenRA
i.Name.Replace("Init", ""), i)); i.Name.Replace("Init", ""), i));
} }
public bool HasTraitInfo<T>() where T : ITraitInfo { return traits.Contains<T>(); } public bool HasTraitInfo<T>() where T : ITraitInfoInterface { return traits.Contains<T>(); }
public T TraitInfo<T>() where T : ITraitInfo { return traits.Get<T>(); } public T TraitInfo<T>() where T : ITraitInfoInterface { return traits.Get<T>(); }
public T TraitInfoOrDefault<T>() where T : ITraitInfo { return traits.GetOrDefault<T>(); } public T TraitInfoOrDefault<T>() where T : ITraitInfoInterface { return traits.GetOrDefault<T>(); }
public IEnumerable<T> TraitInfos<T>() where T : ITraitInfo { return traits.WithInterface<T>(); } public IEnumerable<T> TraitInfos<T>() where T : ITraitInfoInterface { return traits.WithInterface<T>(); }
} }
} }

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Traits
public interface ISeedableResource { void Seed(Actor self); } public interface ISeedableResource { void Seed(Actor self); }
public interface ISelectionDecorationsInfo : ITraitInfo public interface ISelectionDecorationsInfo : ITraitInfoInterface
{ {
int[] SelectionBoxBounds { get; } int[] SelectionBoxBounds { get; }
} }
@@ -147,7 +147,7 @@ namespace OpenRA.Traits
bool HasVoice(Actor self, string voice); 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 public interface IDemolishable
{ {
void Demolish(Actor self, Actor saboteur); void Demolish(Actor self, Actor saboteur);
@@ -169,7 +169,7 @@ namespace OpenRA.Traits
Player Owner { get; } Player Owner { get; }
} }
public interface ITooltipInfo : ITraitInfo public interface ITooltipInfo : ITraitInfoInterface
{ {
string TooltipForPlayerStance(Stance stance); string TooltipForPlayerStance(Stance stance);
bool IsOwnerRowVisible { get; } bool IsOwnerRowVisible { get; }
@@ -191,7 +191,7 @@ namespace OpenRA.Traits
IEnumerable<Pair<CPos, Color>> RadarSignatureCells(Actor self); IEnumerable<Pair<CPos, Color>> RadarSignatureCells(Actor self);
} }
public interface IDefaultVisibilityInfo : ITraitInfo { } public interface IDefaultVisibilityInfo : ITraitInfoInterface { }
public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); } public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); }
public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); } public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); }
@@ -203,7 +203,7 @@ namespace OpenRA.Traits
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IOccupySpaceInfo : ITraitInfo public interface IOccupySpaceInfo : ITraitInfoInterface
{ {
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any);
bool SharesCell { get; } bool SharesCell { get; }
@@ -243,7 +243,7 @@ namespace OpenRA.Traits
public interface IReloadModifier { int GetReloadModifier(); } public interface IReloadModifier { int GetReloadModifier(); }
public interface IInaccuracyModifier { int GetInaccuracyModifier(); } public interface IInaccuracyModifier { int GetInaccuracyModifier(); }
public interface IRangeModifier { int GetRangeModifier(); } public interface IRangeModifier { int GetRangeModifier(); }
public interface IRangeModifierInfo : ITraitInfo { int GetRangeModifierDefault(); } public interface IRangeModifierInfo : ITraitInfoInterface { int GetRangeModifierDefault(); }
public interface IPowerModifier { int GetPowerModifier(); } public interface IPowerModifier { int GetPowerModifier(); }
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); } public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); } public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); }
@@ -251,7 +251,7 @@ namespace OpenRA.Traits
public interface IPips { IEnumerable<PipType> GetPips(Actor self); } public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
public interface ISelectionBar { float GetValue(); Color GetColor(); } public interface ISelectionBar { float GetValue(); Color GetColor(); }
public interface IPositionableInfo : ITraitInfo { } public interface IPositionableInfo : ITraitInfoInterface { }
public interface IPositionable : IOccupySpace public interface IPositionable : IOccupySpace
{ {
bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any); bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any);
@@ -263,7 +263,7 @@ namespace OpenRA.Traits
void SetVisualPosition(Actor self, WPos pos); void SetVisualPosition(Actor self, WPos pos);
} }
public interface IMoveInfo : ITraitInfo { } public interface IMoveInfo : ITraitInfoInterface { }
public interface IMove public interface IMove
{ {
Activity MoveTo(CPos cell, int nearEnough); Activity MoveTo(CPos cell, int nearEnough);
@@ -288,7 +288,7 @@ namespace OpenRA.Traits
int Facing { get; set; } int Facing { get; set; }
} }
public interface IFacingInfo : ITraitInfo { int GetInitialFacing(); } public interface IFacingInfo : ITraitInfoInterface { int GetInitialFacing(); }
public interface ICrushable public interface ICrushable
{ {
@@ -297,12 +297,13 @@ namespace OpenRA.Traits
bool CrushableBy(HashSet<string> crushClasses, Player owner); bool CrushableBy(HashSet<string> crushClasses, Player owner);
} }
public interface ITraitInfo { object Create(ActorInitializer init); } public interface ITraitInfoInterface { }
public interface ITraitInfo : ITraitInfoInterface { object Create(ActorInitializer init); }
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } } public class TraitInfo<T> : 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.")] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")]
public interface Requires<T> where T : class, ITraitInfo { } public interface Requires<T> where T : class, ITraitInfoInterface { }
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")]
public interface UsesInit<T> : ITraitInfo where T : IActorInit { } public interface UsesInit<T> : ITraitInfo where T : IActorInit { }
@@ -311,7 +312,7 @@ namespace OpenRA.Traits
public interface IWorldLoaded { void WorldLoaded(World w, WorldRenderer wr); } public interface IWorldLoaded { void WorldLoaded(World w, WorldRenderer wr); }
public interface ICreatePlayers { void CreatePlayers(World w); } public interface ICreatePlayers { void CreatePlayers(World w); }
public interface IBotInfo : ITraitInfo { string Name { get; } } public interface IBotInfo : ITraitInfoInterface { string Name { get; } }
public interface IBot public interface IBot
{ {
void Activate(Player p); void Activate(Player p);
@@ -334,7 +335,7 @@ namespace OpenRA.Traits
public interface IPostRenderSelection { IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr); } public interface IPostRenderSelection { IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr); }
public interface ITargetableInfo : ITraitInfo public interface ITargetableInfo : ITraitInfoInterface
{ {
HashSet<string> GetTargetTypes(); HashSet<string> GetTargetTypes();
} }
@@ -393,5 +394,5 @@ namespace OpenRA.Traits
} }
public interface IRulesetLoaded<TInfo> { void RulesetLoaded(Ruleset rules, TInfo info); } public interface IRulesetLoaded<TInfo> { void RulesetLoaded(Ruleset rules, TInfo info); }
public interface IRulesetLoaded : IRulesetLoaded<ActorInfo>, ITraitInfo { } public interface IRulesetLoaded : IRulesetLoaded<ActorInfo>, ITraitInfoInterface { }
} }

View File

@@ -20,7 +20,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public class AircraftInfo : IPositionableInfo, IFacingInfo, IOccupySpaceInfo, IMoveInfo, ICruiseAltitudeInfo, public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IOccupySpaceInfo, IMoveInfo, ICruiseAltitudeInfo,
UsesInit<LocationInit>, UsesInit<FacingInit> UsesInit<LocationInit>, UsesInit<FacingInit>
{ {
public readonly WDist CruiseAltitude = new WDist(1280); public readonly WDist CruiseAltitude = new WDist(1280);

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
class CrateInfo : IPositionableInfo, IOccupySpaceInfo, Requires<RenderSpritesInfo> class CrateInfo : ITraitInfo, IPositionableInfo, IOccupySpaceInfo, Requires<RenderSpritesInfo>
{ {
[Desc("Length of time (in seconds) until the crate gets removed automatically. " + [Desc("Length of time (in seconds) until the crate gets removed automatically. " +
"A value of zero disables auto-removal.")] "A value of zero disables auto-removal.")]

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Spawns remains of a husk actor with the correct facing.")] [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<string> AllowedTerrain = new HashSet<string>(); public readonly HashSet<string> AllowedTerrain = new HashSet<string>();