Add ActorInfo.TraitInfo[OrDefault]<T>() requiring ITraitIfo types
This commit is contained in:
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Palette != null)
|
||||
p = init.WorldRenderer.Palette(Palette);
|
||||
|
||||
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
||||
var bi = init.Actor.TraitInfo<BuildingInfo>();
|
||||
|
||||
var width = bi.Dimensions.X;
|
||||
var bibOffset = bi.Dimensions.Y - 1;
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSprites>();
|
||||
bi = self.Info.Traits.Get<BuildingInfo>();
|
||||
bi = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
type = self.Info.Name;
|
||||
isDangling = new Lazy<bool>(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null));
|
||||
building = self.Info.Traits.Get<BuildingInfo>();
|
||||
building = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
public Bridge Neighbour(int direction) { return neighbours[direction]; }
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
var buildingMaxBounds = Dimensions;
|
||||
var buildingTraits = world.Map.Rules.Actors[buildingName].Traits;
|
||||
if (buildingTraits.Contains<BibInfo>() && !buildingTraits.Get<BibInfo>().HasMinibib)
|
||||
var bibInfo = world.Map.Rules.Actors[buildingName].TraitInfoOrDefault<BibInfo>();
|
||||
if (bibInfo != null && !bibInfo.HasMinibib)
|
||||
buildingMaxBounds += new CVec(0, 1);
|
||||
|
||||
var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent));
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
world.ActorAdded += a =>
|
||||
{
|
||||
var b = a.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
var b = a.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (b == null)
|
||||
return;
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
world.ActorRemoved += a =>
|
||||
{
|
||||
var b = a.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
var b = a.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (b == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
|
||||
{
|
||||
var lbi = world.Map.Rules.Actors[name].Traits.Get<LineBuildInfo>();
|
||||
var lbi = world.Map.Rules.Actors[name].TraitInfo<LineBuildInfo>();
|
||||
var topLeft = location; // 1x1 assumption!
|
||||
|
||||
if (world.IsCellBuildable(topLeft, bi))
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Cell contains an actor. Is it the type we want?
|
||||
if (world.ActorsWithTrait<LineBuildNode>().Any(a =>
|
||||
(a.Actor.Location == cell &&
|
||||
a.Actor.Info.Traits.Get<LineBuildNodeInfo>()
|
||||
a.Actor.Info.TraitInfo<LineBuildNodeInfo>()
|
||||
.Types.Overlaps(lbi.NodeTypes))))
|
||||
dirs[d] = i; // Cell contains actor of correct type
|
||||
else
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
|
||||
|
||||
var buildingTraits = rules.Actors[name].Traits;
|
||||
if (buildingTraits.Contains<BibInfo>() && !buildingTraits.Get<BibInfo>().HasMinibib)
|
||||
var bibInfo = rules.Actors[name].TraitInfoOrDefault<BibInfo>();
|
||||
if (bibInfo != null && !bibInfo.HasMinibib)
|
||||
{
|
||||
dim += new CVec(0, 1);
|
||||
footprint = footprint.Concat(new char[dim.X]);
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static IEnumerable<CPos> Tiles(Actor a)
|
||||
{
|
||||
return Tiles(a.World.Map.Rules, a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location);
|
||||
return Tiles(a.World.Map.Rules, a.Info.Name, a.Info.TraitInfo<BuildingInfo>(), a.Location);
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// TODO: THIS IS SHIT
|
||||
// Cancel existing primaries
|
||||
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
|
||||
foreach (var p in self.Info.TraitInfo<ProductionInfo>().Produces)
|
||||
{
|
||||
var productionType = p; // benign closure hazard
|
||||
foreach (var b in self.World
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Where(a =>
|
||||
a.Actor.Owner == self.Owner &&
|
||||
a.Trait.IsPrimary &&
|
||||
a.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains(productionType)))
|
||||
a.Actor.Info.TraitInfo<ProductionInfo>().Produces.Contains(productionType)))
|
||||
b.Trait.SetPrimaryProducer(b.Actor, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user