Add ActorInfo.TraitInfo[OrDefault]<T>() requiring ITraitIfo types
This commit is contained in:
@@ -103,7 +103,7 @@ namespace OpenRA
|
||||
|
||||
bounds = Exts.Lazy(() =>
|
||||
{
|
||||
var si = Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
var si = Info.TraitInfoOrDefault<SelectableInfo>();
|
||||
var size = (si != null && si.Bounds != null) ? new int2(si.Bounds[0], si.Bounds[1]) :
|
||||
TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace OpenRA
|
||||
|
||||
visualBounds = Exts.Lazy(() =>
|
||||
{
|
||||
var sd = Info.Traits.GetOrDefault<ISelectionDecorationsInfo>();
|
||||
var sd = Info.TraitInfoOrDefault<ISelectionDecorationsInfo>();
|
||||
if (sd == null || sd.SelectionBoxBounds == null)
|
||||
return bounds.Value;
|
||||
|
||||
|
||||
@@ -185,5 +185,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public bool HasTraitInfo<T>() where T : ITraitInfo { return Traits.Contains<T>(); }
|
||||
public T TraitInfo<T>() where T : ITraitInfo { return Traits.Get<T>(); }
|
||||
public T TraitInfoOrDefault<T>() where T : ITraitInfo { return Traits.GetOrDefault<T>(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public static int SelectionPriority(this ActorInfo a)
|
||||
{
|
||||
var selectableInfo = a.Traits.GetOrDefault<SelectableInfo>();
|
||||
var selectableInfo = a.TraitInfoOrDefault<SelectableInfo>();
|
||||
return selectableInfo != null ? selectableInfo.Priority : int.MinValue;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public static int SelectionPriority(this Actor a)
|
||||
{
|
||||
var basePriority = a.Info.Traits.Get<SelectableInfo>().Priority;
|
||||
var basePriority = a.Info.TraitInfo<SelectableInfo>().Priority;
|
||||
var lp = a.World.LocalPlayer;
|
||||
|
||||
if (a.Owner == lp || lp == null)
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA
|
||||
if (actor.Owner != world.LocalPlayer || !actor.IsInWorld)
|
||||
continue;
|
||||
|
||||
var selectable = actor.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
var selectable = actor.Info.TraitInfoOrDefault<SelectableInfo>();
|
||||
if (selectable == null || !actor.HasVoice(selectable.Voice))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ISeedableResource { void Seed(Actor self); }
|
||||
|
||||
public interface ISelectionDecorationsInfo
|
||||
public interface ISelectionDecorationsInfo : ITraitInfo
|
||||
{
|
||||
int[] SelectionBoxBounds { get; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user