Add ActorInfo.HasTraitInfo<T>() requiring ITraitInfo types
This commit is contained in:
@@ -92,10 +92,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
foreach (var a in actors)
|
||||
{
|
||||
var actor = a;
|
||||
if (actor.Traits.Contains<BridgeInfo>()) // bridge layer takes care about that automatically
|
||||
if (actor.HasTraitInfo<BridgeInfo>()) // bridge layer takes care about that automatically
|
||||
continue;
|
||||
|
||||
if (!actor.Traits.Contains<IRenderActorPreviewInfo>())
|
||||
if (!actor.HasTraitInfo<IRenderActorPreviewInfo>())
|
||||
continue;
|
||||
|
||||
var filter = actor.Traits.GetOrDefault<EditorTilesetFilterInfo>();
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
|
||||
|
||||
var harvesters = template.Get<LabelWidget>("HARVESTERS");
|
||||
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead && a.Info.Traits.Contains<HarvesterInfo>()).ToString();
|
||||
harvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead && a.Info.HasTraitInfo<HarvesterInfo>()).ToString();
|
||||
|
||||
return template;
|
||||
}
|
||||
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
return ScrollItemWidget.Setup(template, () => false, () =>
|
||||
{
|
||||
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead && a.Info.Traits.Contains<BaseBuildingInfo>() && a.Owner == player);
|
||||
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead && a.Info.HasTraitInfo<BaseBuildingInfo>() && a.Owner == player);
|
||||
if (playerBase != null)
|
||||
worldRenderer.Viewport.Center(playerBase.CenterPosition);
|
||||
});
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
static string ActorName(Ruleset rules, string a)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.Traits.Contains<TooltipInfo>())
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.HasTraitInfo<TooltipInfo>())
|
||||
return ai.Traits.Get<TooltipInfo>().Name;
|
||||
|
||||
return a;
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var actor = World.Map.Rules.Actors[icon.Name];
|
||||
|
||||
if (item != null && item.Done && actor.Traits.Contains<BuildingInfo>())
|
||||
if (item != null && item.Done && actor.HasTraitInfo<BuildingInfo>())
|
||||
{
|
||||
World.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, icon.Name);
|
||||
return true;
|
||||
|
||||
@@ -198,7 +198,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
// Is added to world.ActorAdded by the SidebarLogic handler
|
||||
public void ActorChanged(Actor a)
|
||||
{
|
||||
if (a.Info.Traits.Contains<ProductionQueueInfo>())
|
||||
if (a.Info.HasTraitInfo<ProductionQueueInfo>())
|
||||
{
|
||||
var allQueues = a.World.ActorsWithTrait<ProductionQueue>()
|
||||
.Where(p => p.Actor.Owner == p.Actor.World.LocalPlayer && p.Actor.IsInWorld && p.Trait.Enabled)
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
|
||||
var underCursor = world.ScreenMap.ActorsAt(worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
|
||||
.Where(a => !world.FogObscures(a) && a.Info.Traits.Contains<ITooltipInfo>())
|
||||
.Where(a => !world.FogObscures(a) && a.Info.HasTraitInfo<ITooltipInfo>())
|
||||
.WithHighestSelectionPriority();
|
||||
|
||||
if (underCursor != null)
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
bool PerformGuard()
|
||||
{
|
||||
var actors = world.Selection.Actors
|
||||
.Where(a => !a.Disposed && a.Owner == world.LocalPlayer && a.Info.Traits.Contains<GuardInfo>());
|
||||
.Where(a => !a.Disposed && a.Owner == world.LocalPlayer && a.Info.HasTraitInfo<GuardInfo>());
|
||||
|
||||
if (actors.Any())
|
||||
world.OrderGenerator = new GuardOrderGenerator(actors);
|
||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var building = world.ActorsWithTrait<Building>()
|
||||
.Select(b => b.Actor)
|
||||
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.Info.Traits.Contains<SelectableInfo>());
|
||||
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.Info.HasTraitInfo<SelectableInfo>());
|
||||
|
||||
// No buildings left
|
||||
if (building == null)
|
||||
@@ -223,7 +223,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
bool CycleProductionBuildings()
|
||||
{
|
||||
var facilities = world.ActorsWithTrait<Production>()
|
||||
.Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.Info.Traits.Contains<BaseBuildingInfo>())
|
||||
.Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.Info.HasTraitInfo<BaseBuildingInfo>())
|
||||
.OrderBy(f => f.Actor.Info.Traits.Get<ProductionInfo>().Produces.First())
|
||||
.Select(b => b.Actor)
|
||||
.ToList();
|
||||
|
||||
Reference in New Issue
Block a user