Actor.traits is implementation detail

This commit is contained in:
Bob
2010-08-14 15:19:30 +12:00
committed by alzeih
parent f6c6255f64
commit ae703d50b2
165 changed files with 586 additions and 561 deletions

View File

@@ -1,17 +1,17 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Traits
@@ -37,9 +37,9 @@ namespace OpenRA.Traits
bibSprites = info.BibTypes.Select(x => SpriteSheetBuilder.LoadAllSprites(x)).ToArray();
self.World.ActorAdded +=
a => { if (a.traits.Contains<Bib>()) DoBib(a,true); };
a => { if (a.HasTrait<Bib>()) DoBib(a,true); };
self.World.ActorRemoved +=
a => { if (a.traits.Contains<Bib>()) DoBib(a,false); };
a => { if (a.HasTrait<Bib>()) DoBib(a,false); };
}
public void WorldLoaded(World w)
@@ -56,7 +56,7 @@ namespace OpenRA.Traits
int bib = Array.IndexOf(info.BibWidths,size);
if (bib < 0)
{
{
Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name);
return;
}
@@ -72,23 +72,23 @@ namespace OpenRA.Traits
}
public void Render()
{
var cliprect = Game.viewport.ShroudBounds().HasValue
? Rectangle.Intersect(Game.viewport.ShroudBounds().Value, world.Map.Bounds) : world.Map.Bounds;
var minx = cliprect.Left;
var maxx = cliprect.Right;
var miny = cliprect.Top;
var maxy = cliprect.Bottom;
for (int x = minx; x < maxx; x++)
{
var cliprect = Game.viewport.ShroudBounds().HasValue
? Rectangle.Intersect(Game.viewport.ShroudBounds().Value, world.Map.Bounds) : world.Map.Bounds;
var minx = cliprect.Left;
var maxx = cliprect.Right;
var miny = cliprect.Top;
var maxy = cliprect.Bottom;
for (int x = minx; x < maxx; x++)
for (int y = miny; y < maxy; y++)
{
var t = new int2(x, y);
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(t) || tiles[x,y].type == 0) continue;
Game.Renderer.SpriteRenderer.DrawSprite(bibSprites[tiles[x, y].type - 1][tiles[x, y].image],
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(t) || tiles[x,y].type == 0) continue;
Game.Renderer.SpriteRenderer.DrawSprite(bibSprites[tiles[x, y].type - 1][tiles[x, y].image],
Game.CellSize * t, "terrain");
}
}

View File

@@ -32,11 +32,11 @@ namespace OpenRA.Traits
influence = new Actor[map.MapSize.X, map.MapSize.Y];
world.ActorAdded +=
a => { if (a.traits.Contains<Building>())
ChangeInfluence(a, a.traits.Get<Building>(), true); };
a => { if (a.HasTrait<Building>())
ChangeInfluence(a, a.Trait<Building>(), true); };
world.ActorRemoved +=
a => { if (a.traits.Contains<Building>())
ChangeInfluence(a, a.traits.Get<Building>(), false); };
a => { if (a.HasTrait<Building>())
ChangeInfluence(a, a.Trait<Building>(), false); };
}
void ChangeInfluence( Actor a, Building building, bool isAdd )

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Traits
this.world = w;
content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y];
resourceTypes = w.WorldActor.traits.WithInterface<ResourceType>().ToArray();
resourceTypes = w.WorldActor.TraitsImplementing<ResourceType>().ToArray();
foreach (var rt in resourceTypes)
rt.info.Sprites = rt.info.SpriteNames.Select(a => SpriteSheetBuilder.LoadAllSprites(a)).ToArray();

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Traits
void AddActor(Actor a)
{
if (!a.traits.Contains<RevealsShroud>())
if (!a.HasTrait<RevealsShroud>())
return;
if (a.Owner == null || a.Owner.World.LocalPlayer == null
@@ -78,7 +78,7 @@ namespace OpenRA.Traits
var v = new ActorVisibility
{
range = a.traits.Get<RevealsShroud>().RevealRange,
range = a.Trait<RevealsShroud>().RevealRange,
vis = GetVisOrigins(a).ToArray()
};
@@ -129,7 +129,7 @@ namespace OpenRA.Traits
}
else
{
var mobile = a.traits.GetOrDefault<Mobile>();
var mobile = a.TraitOrDefault<Mobile>();
if (mobile != null)
return new[] { mobile.fromCell, mobile.toCell };
else

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Traits
for (int j = 0; j < world.Map.MapSize.Y; j++)
influence[ i, j ] = new List<Actor>();
world.ActorRemoved += a => Remove( a, a.traits.GetOrDefault<IOccupySpace>() );
world.ActorRemoved += a => Remove( a, a.TraitOrDefault<IOccupySpace>() );
}
public void Tick( Actor self )
@@ -49,7 +49,7 @@ namespace OpenRA.Traits
for( int y = 0 ; y < self.World.Map.MapSize.Y ; y++ )
if( influence[ x, y ] != null )
foreach (var a in influence[ x, y ])
if (!a.traits.Get<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
if (!a.Trait<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
throw new InvalidOperationException( "UIM: Sanity check failed A" );
foreach( var t in self.World.Queries.WithTraitMultiple<IOccupySpace>() )