refactor Targetable into Targetable{Unit,Building} and ITargetable

This commit is contained in:
Bob
2010-11-03 22:28:53 +13:00
committed by Chris Forbes
parent 98dec6dc8e
commit 39b09780f6
15 changed files with 106 additions and 84 deletions

View File

@@ -192,7 +192,6 @@
<Compile Include="Widgets\ViewportScrollControllerWidget.cs" />
<Compile Include="Traits\Player\DeveloperMode.cs" />
<Compile Include="Traits\RevealsShroud.cs" />
<Compile Include="Traits\Targetable.cs" />
<Compile Include="Traits\Health.cs" />
<Compile Include="Widgets\VqaPlayerWidget.cs" />
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
@@ -259,4 +258,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Orders
else
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.Info.Traits.Contains<TargetableInfo>())
.Where(a => a.HasTrait<ITargetable>())
.OrderByDescending(
a =>
a.Info.Traits.Contains<SelectableInfo>()
@@ -106,7 +106,7 @@ namespace OpenRA.Orders
}
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.Info.Traits.Contains<TargetableInfo>())
.Where(a => a.HasTrait<ITargetable>())
.OrderByDescending(a => a.Info.Traits.Contains<SelectableInfo>() ? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue)
.FirstOrDefault();

View File

@@ -1,42 +0,0 @@
#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.Drawing;
using OpenRA.Graphics;
using System.Linq;
using System.Collections.Generic;
namespace OpenRA.Traits
{
public class TargetableInfo : ITraitInfo
{
public readonly string[] TargetTypes = {};
public virtual object Create( ActorInitializer init ) { return new Targetable(this); }
}
public class Targetable
{
protected TargetableInfo Info;
public Targetable(TargetableInfo info)
{
Info = info;
}
public virtual string[] TargetTypes
{
get { return Info.TargetTypes;}
}
public virtual IEnumerable<int2> TargetableSquares( Actor self )
{
yield return self.Location;
}
}
}

View File

@@ -237,4 +237,10 @@ namespace OpenRA.Traits
public Actor Actor { get { return IsActor ? actor : null; } }
public bool IsActor { get { return actor != null && !actor.Destroyed; } }
}
public interface ITargetable
{
string[] TargetTypes { get; }
IEnumerable<int2> TargetableSquares( Actor self );
}
}