actually working custom lint passes

This commit is contained in:
Chris Forbes
2011-04-05 21:56:31 +12:00
parent 55c609ee16
commit 24a205d992
5 changed files with 273 additions and 229 deletions

View File

@@ -84,6 +84,14 @@ namespace OpenRA
return ctor.Invoke( a ); return ctor.Invoke( a );
} }
public IEnumerable<Type> GetTypesImplementing<T>()
{
var it = typeof(T);
return ModAssemblies.Select( ma => ma.First ).Distinct()
.SelectMany(ma => ma.GetTypes()
.Where(t => t != it && it.IsAssignableFrom(t)));
}
[AttributeUsage( AttributeTargets.Parameter )] [AttributeUsage( AttributeTargets.Parameter )]
public class ParamAttribute : Attribute public class ParamAttribute : Attribute
{ {

View File

@@ -14,6 +14,7 @@ using OpenRA.FileFormats;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Network; using OpenRA.Network;
using System;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
@@ -40,23 +41,24 @@ namespace OpenRA.Traits
public interface IIssueOrder public interface IIssueOrder
{ {
IEnumerable<IOrderTargeter> Orders { get; } IEnumerable<IOrderTargeter> Orders { get; }
Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ); Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued);
} }
public interface IOrderTargeter public interface IOrderTargeter
{ {
string OrderID { get; } string OrderID { get; }
int OrderPriority { get; } int OrderPriority { get; }
bool CanTargetActor( Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueue, ref string cursor ); bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueue, ref string cursor);
bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueue, bool forceMove, ref string cursor); bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueue, bool forceMove, ref string cursor);
bool IsQueued { get; } bool IsQueued { get; }
} }
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); }
}
public interface IOrderCursor { string CursorForOrder(Actor self, Order order); } public interface IOrderCursor { string CursorForOrder(Actor self, Order order); }
public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); } public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); }
public interface ICustomUnitOrderGenerator : IOrderGenerator {}; public interface ICustomUnitOrderGenerator : IOrderGenerator { };
public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); } public interface INotifySold { void Selling(Actor self); void Sold(Actor self); }
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
@@ -64,7 +66,7 @@ namespace OpenRA.Traits
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
public interface IStoreOre { int Capacity { get; }} public interface IStoreOre { int Capacity { get; } }
public interface IToolTip public interface IToolTip
{ {
string Name(); string Name();
@@ -107,14 +109,14 @@ namespace OpenRA.Traits
public static class IOccupySpaceExts public static class IOccupySpaceExts
{ {
public static int2 NearestCellTo( this IOccupySpace ios, int2 other ) public static int2 NearestCellTo(this IOccupySpace ios, int2 other)
{ {
var nearest = ios.TopLeft; var nearest = ios.TopLeft;
var nearestDistance = int.MaxValue; var nearestDistance = int.MaxValue;
foreach( var cell in ios.OccupiedCells() ) foreach (var cell in ios.OccupiedCells())
{ {
var dist = ( other - cell.First ).LengthSquared; var dist = (other - cell.First).LengthSquared;
if( dist < nearestDistance ) if (dist < nearestDistance)
{ {
nearest = cell.First; nearest = cell.First;
nearestDistance = dist; nearestDistance = dist;
@@ -130,8 +132,8 @@ namespace OpenRA.Traits
public interface ISpeedModifier { decimal GetSpeedModifier(); } public interface ISpeedModifier { decimal GetSpeedModifier(); }
public interface IFirepowerModifier { float GetFirepowerModifier(); } public interface IFirepowerModifier { float GetFirepowerModifier(); }
public interface ISelectionColorModifier { Color GetSelectionColorModifier(Actor self, Color defaultColor); } public interface ISelectionColorModifier { Color GetSelectionColorModifier(Actor self, Color defaultColor); }
public interface IPalette { void InitPalette( WorldRenderer wr ); } public interface IPalette { void InitPalette(WorldRenderer wr); }
public interface IPaletteModifier { void AdjustPalette(Dictionary<string,Palette> b); } public interface IPaletteModifier { void AdjustPalette(Dictionary<string, Palette> b); }
public interface IPips { IEnumerable<PipType> GetPips(Actor self); } public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
public interface ITags { IEnumerable<TagType> GetTags(); } public interface ITags { IEnumerable<TagType> GetTags(); }
public interface ISelectionBar { float GetValue(); Color GetColor(); } public interface ISelectionBar { float GetValue(); Color GetColor(); }
@@ -218,7 +220,7 @@ namespace OpenRA.Traits
IEnumerable<float2> GetCurrentPath(); IEnumerable<float2> GetCurrentPath();
} }
public interface IRenderOverlay { void Render( WorldRenderer wr ); } public interface IRenderOverlay { void Render(WorldRenderer wr); }
public interface INotifyIdle { void TickIdle(Actor self); } public interface INotifyIdle { void TickIdle(Actor self); }
public interface IBlocksBullets { } public interface IBlocksBullets { }
@@ -232,10 +234,15 @@ namespace OpenRA.Traits
public interface ITargetable public interface ITargetable
{ {
string[] TargetTypes { get; } string[] TargetTypes { get; }
IEnumerable<int2> TargetableCells( Actor self ); IEnumerable<int2> TargetableCells(Actor self);
bool TargetableBy(Actor self, Actor byActor); bool TargetableBy(Actor self, Actor byActor);
} }
public interface INotifyStanceChanged { void StanceChanged(Actor self, Player a, Player b, public interface INotifyStanceChanged
Stance oldStance, Stance newStance); } {
void StanceChanged(Actor self, Player a, Player b,
Stance oldStance, Stance newStance);
}
public interface ILintPass { void Run(Action<string> emitError); }
} }

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class LintBuildablePrerequisites : ILintPass
{
public void Run(Action<string> emitError)
{
emitError("Hello World");
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -63,6 +63,7 @@
<Compile Include="Air\FlyCircle.cs" /> <Compile Include="Air\FlyCircle.cs" />
<Compile Include="Buildings\Sellable.cs" /> <Compile Include="Buildings\Sellable.cs" />
<Compile Include="Effects\CashTick.cs" /> <Compile Include="Effects\CashTick.cs" />
<Compile Include="Lint\LintBuildablePrerequisites.cs" />
<Compile Include="ProductionBar.cs" /> <Compile Include="ProductionBar.cs" />
<Compile Include="Render\RenderEditorOnly.cs" /> <Compile Include="Render\RenderEditorOnly.cs" />
<Compile Include="SmokeTrailWhenDamaged.cs" /> <Compile Include="SmokeTrailWhenDamaged.cs" />

View File

@@ -30,6 +30,7 @@ namespace RALint
static int Main(string[] args) static int Main(string[] args)
{ {
Console.WriteLine("This is teh sucks");
try try
{ {
// bind some nonfatal error handling into FieldLoader, so we don't just *explode*. // bind some nonfatal error handling into FieldLoader, so we don't just *explode*.
@@ -44,6 +45,17 @@ namespace RALint
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>()) foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
CheckTrait(actorInfo.Value, traitInfo); CheckTrait(actorInfo.Value, traitInfo);
foreach (var customPassType in Game.modData.ObjectCreator
.GetTypesImplementing<ILintPass>())
{
var customPass = (ILintPass)Game.modData.ObjectCreator
.CreateBasic(customPassType);
Console.WriteLine("CustomPass: {0}".F(customPassType.ToString()));
customPass.Run(EmitError);
}
if (errors > 0) if (errors > 0)
{ {
Console.WriteLine("Errors: {0}", errors); Console.WriteLine("Errors: {0}", errors);