Replace ITraitInfo interface with TraitInfo class.
This commit is contained in:
@@ -32,7 +32,7 @@ namespace OpenRA
|
||||
/// </summary>
|
||||
public readonly string Name;
|
||||
readonly TypeDictionary traits = new TypeDictionary();
|
||||
List<ITraitInfo> constructOrderCache = null;
|
||||
List<TraitInfo> constructOrderCache = null;
|
||||
|
||||
public ActorInfo(ObjectCreator creator, string name, MiniYaml node)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public ActorInfo(string name, params ITraitInfo[] traitInfos)
|
||||
public ActorInfo(string name, params TraitInfo[] traitInfos)
|
||||
{
|
||||
Name = name;
|
||||
foreach (var t in traitInfos)
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA
|
||||
traits.TrimExcess();
|
||||
}
|
||||
|
||||
static ITraitInfo LoadTraitInfo(ObjectCreator creator, string traitName, MiniYaml my)
|
||||
static TraitInfo LoadTraitInfo(ObjectCreator creator, string traitName, MiniYaml my)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(my.Value))
|
||||
throw new YamlException("Junk value `{0}` on trait node {1}"
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA
|
||||
|
||||
// HACK: The linter does not want to crash when a trait doesn't exist but only print an error instead
|
||||
// ObjectCreator will only return null to signal us to abort here if the linter is running
|
||||
var info = creator.CreateObject<ITraitInfo>(traitName + "Info");
|
||||
var info = creator.CreateObject<TraitInfo>(traitName + "Info");
|
||||
if (info == null)
|
||||
return null;
|
||||
|
||||
@@ -97,12 +97,12 @@ namespace OpenRA
|
||||
return info;
|
||||
}
|
||||
|
||||
public IEnumerable<ITraitInfo> TraitsInConstructOrder()
|
||||
public IEnumerable<TraitInfo> TraitsInConstructOrder()
|
||||
{
|
||||
if (constructOrderCache != null)
|
||||
return constructOrderCache;
|
||||
|
||||
var source = traits.WithInterface<ITraitInfo>().Select(i => new
|
||||
var source = traits.WithInterface<TraitInfo>().Select(i => new
|
||||
{
|
||||
Trait = i,
|
||||
Type = i.GetType(),
|
||||
@@ -148,7 +148,7 @@ namespace OpenRA
|
||||
return constructOrderCache;
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> PrerequisitesOf(ITraitInfo info)
|
||||
public static IEnumerable<Type> PrerequisitesOf(TraitInfo info)
|
||||
{
|
||||
return info
|
||||
.GetType()
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Checks for pause related desyncs. Attach this to the world actor.")]
|
||||
public class DebugPauseStateInfo : ITraitInfo
|
||||
public class DebugPauseStateInfo : TraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new DebugPauseState(init.World); }
|
||||
public override object Create(ActorInitializer init) { return new DebugPauseState(init.World); }
|
||||
}
|
||||
|
||||
public class DebugPauseState : ISync
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Primitives;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Add this to the World actor definition.")]
|
||||
public class FixedColorPaletteInfo : ITraitInfo
|
||||
public class FixedColorPaletteInfo : TraitInfo
|
||||
{
|
||||
[PaletteReference]
|
||||
[Desc("The name of the palette to base off.")]
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Traits
|
||||
[Desc("Allow palette modifiers to change the palette.")]
|
||||
public readonly bool AllowModifiers = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new FixedColorPalette(this); }
|
||||
public override object Create(ActorInitializer init) { return new FixedColorPalette(this); }
|
||||
}
|
||||
|
||||
public class FixedColorPalette : ILoadsPalettes
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
[Desc("Required for FrozenUnderFog to work. Attach this to the player actor.")]
|
||||
public class FrozenActorLayerInfo : Requires<ShroudInfo>, ITraitInfo
|
||||
public class FrozenActorLayerInfo : TraitInfo, Requires<ShroudInfo>
|
||||
{
|
||||
[Desc("Size of partition bins (cells)")]
|
||||
public readonly int BinSize = 10;
|
||||
|
||||
public object Create(ActorInitializer init) { return new FrozenActorLayer(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new FrozenActorLayer(init.Self, this); }
|
||||
}
|
||||
|
||||
public class FrozenActor
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Primitives;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Define a player palette by swapping palette indices.")]
|
||||
public class IndexedPlayerPaletteInfo : ITraitInfo, IRulesetLoaded
|
||||
public class IndexedPlayerPaletteInfo : TraitInfo, IRulesetLoaded
|
||||
{
|
||||
[PaletteReference]
|
||||
[Desc("The name of the palette to base off.")]
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public readonly Dictionary<string, int[]> PlayerIndex;
|
||||
|
||||
public object Create(ActorInitializer init) { return new IndexedPlayerPalette(this); }
|
||||
public override object Create(ActorInitializer init) { return new IndexedPlayerPalette(this); }
|
||||
|
||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Primitives;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Add this to the Player actor definition.")]
|
||||
public class PlayerColorPaletteInfo : ITraitInfo
|
||||
public class PlayerColorPaletteInfo : TraitInfo
|
||||
{
|
||||
[PaletteReference]
|
||||
[Desc("The name of the palette to base off.")]
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Traits
|
||||
[Desc("Allow palette modifiers to change the palette.")]
|
||||
public readonly bool AllowModifiers = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayerColorPalette(this); }
|
||||
public override object Create(ActorInitializer init) { return new PlayerColorPalette(this); }
|
||||
}
|
||||
|
||||
public class PlayerColorPalette : ILoadsPlayerPalettes
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Primitives;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Add this to the Player actor definition.")]
|
||||
public class PlayerHighlightPaletteInfo : ITraitInfo
|
||||
public class PlayerHighlightPaletteInfo : TraitInfo
|
||||
{
|
||||
[PaletteDefinition(true)]
|
||||
[Desc("The prefix for the resulting player palettes")]
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Traits
|
||||
[Desc("Index set to be fully transparent/invisible.")]
|
||||
public readonly int TransparentIndex = 0;
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayerHighlightPalette(this); }
|
||||
public override object Create(ActorInitializer init) { return new PlayerHighlightPalette(this); }
|
||||
}
|
||||
|
||||
public class PlayerHighlightPalette : ILoadsPlayerPalettes
|
||||
|
||||
@@ -15,7 +15,7 @@ using System.Collections.Generic;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("Required for shroud and fog visibility checks. Add this to the player actor.")]
|
||||
public class ShroudInfo : ITraitInfo, ILobbyOptions
|
||||
public class ShroudInfo : TraitInfo, ILobbyOptions
|
||||
{
|
||||
[Translate]
|
||||
[Desc("Descriptive label for the fog checkbox in the lobby.")]
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Traits
|
||||
FogCheckboxVisible, FogCheckboxDisplayOrder, FogCheckboxEnabled, FogCheckboxLocked);
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new Shroud(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new Shroud(init.Self, this); }
|
||||
}
|
||||
|
||||
public class Shroud : ISync, INotifyCreated, ITick
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Traits
|
||||
/// </summary>
|
||||
public sealed class DamageType { DamageType() { } }
|
||||
|
||||
public interface IHealthInfo : ITraitInfo
|
||||
public interface IHealthInfo : ITraitInfoInterface
|
||||
{
|
||||
int MaxHP { get; }
|
||||
}
|
||||
@@ -324,9 +324,17 @@ namespace OpenRA.Traits
|
||||
public interface IFacingInfo : ITraitInfoInterface { int GetInitialFacing(); }
|
||||
|
||||
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 abstract class TraitInfo : ITraitInfoInterface
|
||||
{
|
||||
public abstract object Create(ActorInitializer init);
|
||||
}
|
||||
|
||||
public class TraitInfo<T> : TraitInfo where T : new()
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new T(); }
|
||||
}
|
||||
|
||||
public interface ILobbyCustomRulesIgnore { }
|
||||
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1302:InterfaceNamesMustBeginWithI", Justification = "Not a real interface, but more like a tag.")]
|
||||
@@ -541,7 +549,7 @@ namespace OpenRA.Traits
|
||||
public interface ICreationActivity { Activity GetCreationActivity(); }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IObservesVariablesInfo : ITraitInfo { }
|
||||
public interface IObservesVariablesInfo : ITraitInfoInterface { }
|
||||
|
||||
public delegate void VariableObserverNotifier(Actor self, IReadOnlyDictionary<string, int> variables);
|
||||
public struct VariableObserver
|
||||
|
||||
@@ -30,12 +30,12 @@ namespace OpenRA.Traits
|
||||
public override string ToString() { return "{0}->{1}".F(Actor.Info.Name, Bounds.GetType().Name); }
|
||||
}
|
||||
|
||||
public class ScreenMapInfo : ITraitInfo
|
||||
public class ScreenMapInfo : TraitInfo
|
||||
{
|
||||
[Desc("Size of partition bins (world pixels)")]
|
||||
public readonly int BinSize = 250;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ScreenMap(init.World, this); }
|
||||
public override object Create(ActorInitializer init) { return new ScreenMap(init.World, this); }
|
||||
}
|
||||
|
||||
public class ScreenMap : IWorldLoaded
|
||||
|
||||
@@ -16,12 +16,12 @@ using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class ScreenShakerInfo : ITraitInfo
|
||||
public class ScreenShakerInfo : TraitInfo
|
||||
{
|
||||
public readonly float2 MinMultiplier = new float2(-3, -3);
|
||||
public readonly float2 MaxMultiplier = new float2(3, 3);
|
||||
|
||||
public object Create(ActorInitializer init) { return new ScreenShaker(this); }
|
||||
public override object Create(ActorInitializer init) { return new ScreenShaker(this); }
|
||||
}
|
||||
|
||||
public class ScreenShaker : ITick, IWorldLoaded
|
||||
|
||||
Reference in New Issue
Block a user