add more lint interfaces to reduce boiler plate
This commit is contained in:
@@ -327,7 +327,9 @@ namespace OpenRA.Traits
|
||||
Stance oldStance, Stance newStance);
|
||||
}
|
||||
|
||||
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning, Map map); }
|
||||
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
|
||||
public interface ILintMapPass { void Run(Action<string> emitError, Action<string> emitWarning, Map map); }
|
||||
public interface ILintRulesPass { void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules); }
|
||||
|
||||
public interface IObjectivesPanel
|
||||
{
|
||||
|
||||
@@ -15,17 +15,12 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckActorReferences : ILintPass
|
||||
public class CheckActorReferences : ILintRulesPass
|
||||
{
|
||||
Action<string> emitError;
|
||||
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
this.emitError = emitError;
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
|
||||
@@ -14,13 +14,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckActors : ILintPass
|
||||
public class CheckActors : ILintMapPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
{
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
var actorTypes = map.ActorDefinitions.Select(a => a.Value.Value);
|
||||
foreach (var actor in actorTypes)
|
||||
if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant()))
|
||||
|
||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckDeathTypes : ILintPass
|
||||
class CheckDeathTypes : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
var animations = actorInfo.Value.Traits.WithInterface<WithDeathAnimationInfo>().ToList();
|
||||
|
||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckDefaultVisibility : ILintPass
|
||||
class CheckDefaultVisibility : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
if (actorInfo.Key.StartsWith("^"))
|
||||
|
||||
@@ -14,13 +14,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckMapCordon : ILintPass
|
||||
public class CheckMapCordon : ILintMapPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
{
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
if (map.Bounds.Left == 0 || map.Bounds.Top == 0
|
||||
|| map.Bounds.Right == map.MapSize.X || map.Bounds.Bottom == map.MapSize.Y)
|
||||
emitError("This map does not define a valid cordon.\n"
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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 COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckMapRules : ILintPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
{
|
||||
try
|
||||
{
|
||||
Game.ModData.RulesetCache.Load(map);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
emitError(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckPalettes : ILintPass
|
||||
class CheckPalettes : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
var palettes = GetPalettes(emitError, rules).ToList();
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
|
||||
@@ -15,13 +15,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckPlayers : ILintPass
|
||||
public class CheckPlayers : ILintMapPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
{
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
var players = new MapPlayers(map.PlayerDefinitions).Players;
|
||||
|
||||
var playerNames = players.Values.Select(p => p.Name).ToHashSet();
|
||||
|
||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckRevealFootprint : ILintPass
|
||||
class CheckRevealFootprint : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
if (actorInfo.Key.StartsWith("^"))
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckSequences : ILintPass
|
||||
class CheckSequences : ILintMapPass
|
||||
{
|
||||
Action<string> emitError;
|
||||
|
||||
|
||||
@@ -17,11 +17,8 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckSyncAnnotations : ILintPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning)
|
||||
{
|
||||
if (map != null)
|
||||
return;
|
||||
|
||||
/* first, check all the types implementing ISync */
|
||||
foreach (var t in Game.ModData.ObjectCreator.GetTypesImplementing<ISync>())
|
||||
if (!HasAnySyncFields(t))
|
||||
|
||||
@@ -14,16 +14,12 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckTraitPrerequisites : ILintPass
|
||||
public class CheckTraitPrerequisites : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
foreach (var actorInfo in rules.Actors.Where(a => !a.Key.StartsWith("^")))
|
||||
{
|
||||
try
|
||||
{
|
||||
var hasTraits = actorInfo.Value.TraitsInConstructOrder().Any();
|
||||
@@ -34,6 +30,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
emitError("Actor {0} is not constructible; failure: {1}".F(actorInfo.Key, e.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckUpgrades : ILintPass
|
||||
public class CheckUpgrades : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
CheckUpgradesValidity(emitError, rules);
|
||||
CheckUpgradesUsage(emitError, emitWarning, rules);
|
||||
}
|
||||
|
||||
@@ -15,15 +15,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
public class CheckVoiceReferences : ILintPass
|
||||
public class CheckVoiceReferences : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any() && !map.VoiceDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
|
||||
|
||||
@@ -15,15 +15,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class LintBuildablePrerequisites : ILintPass
|
||||
class LintBuildablePrerequisites : ILintRulesPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
|
||||
{
|
||||
if (map != null && !map.RuleDefinitions.Any())
|
||||
return;
|
||||
|
||||
var rules = map == null ? Game.ModData.DefaultRules : map.Rules;
|
||||
|
||||
// ProvidesPrerequisite allows arbitrary prereq definitions
|
||||
var customPrereqs = rules.Actors.SelectMany(a => a.Value.Traits
|
||||
.WithInterface<ProvidesPrerequisiteInfo>().Select(p => p.Prerequisite ?? a.Value.Name));
|
||||
|
||||
@@ -183,7 +183,6 @@
|
||||
<Compile Include="Lint\CheckPlayers.cs" />
|
||||
<Compile Include="Lint\CheckActors.cs" />
|
||||
<Compile Include="Lint\CheckMapCordon.cs" />
|
||||
<Compile Include="Lint\CheckMapRules.cs" />
|
||||
<Compile Include="Lint\CheckActorReferences.cs" />
|
||||
<Compile Include="Lint\CheckSyncAnnotations.cs" />
|
||||
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
|
||||
|
||||
@@ -52,7 +52,25 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
var maps = new List<Map>();
|
||||
if (args.Length < 2)
|
||||
{
|
||||
maps.Add(null);
|
||||
Console.WriteLine("Testing mod: {0}".F(Game.ModData.Manifest.Mod.Title));
|
||||
|
||||
// Run all rule checks on the default mod rules.
|
||||
CheckRules(Game.ModData.DefaultRules);
|
||||
|
||||
// Run all generic (not mod-level) checks here.
|
||||
foreach (var customPassType in Game.ModData.ObjectCreator.GetTypesImplementing<ILintPass>())
|
||||
{
|
||||
try
|
||||
{
|
||||
var customPass = (ILintPass)Game.ModData.ObjectCreator.CreateBasic(customPassType);
|
||||
customPass.Run(EmitError, EmitWarning);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EmitError("{0} failed with exception: {1}".F(customPassType, e));
|
||||
}
|
||||
}
|
||||
|
||||
Game.ModData.MapCache.LoadMaps();
|
||||
maps.AddRange(Game.ModData.MapCache
|
||||
.Where(m => m.Status == MapStatus.Available)
|
||||
@@ -63,29 +81,24 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
foreach (var testMap in maps)
|
||||
{
|
||||
if (testMap != null)
|
||||
{
|
||||
Console.WriteLine("Testing map: {0}".F(testMap.Title));
|
||||
testMap.PreloadRules();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Testing mod: {0}".F(Game.ModData.Manifest.Mod.Title));
|
||||
}
|
||||
Console.WriteLine("Testing map: {0}".F(testMap.Title));
|
||||
testMap.PreloadRules();
|
||||
|
||||
foreach (var customPassType in Game.ModData.ObjectCreator
|
||||
.GetTypesImplementing<ILintPass>())
|
||||
// Run all rule checks on the map if it defines custom rules.
|
||||
if (testMap.RuleDefinitions.Any() || testMap.VoiceDefinitions.Any() || testMap.WeaponDefinitions.Any())
|
||||
CheckRules(testMap.Rules, testMap);
|
||||
|
||||
// Run all map-level checks here.
|
||||
foreach (var customMapPassType in Game.ModData.ObjectCreator.GetTypesImplementing<ILintMapPass>())
|
||||
{
|
||||
try
|
||||
{
|
||||
var customPass = (ILintPass)Game.ModData.ObjectCreator
|
||||
.CreateBasic(customPassType);
|
||||
|
||||
customPass.Run(EmitError, EmitWarning, testMap);
|
||||
var customMapPass = (ILintMapPass)Game.ModData.ObjectCreator.CreateBasic(customMapPassType);
|
||||
customMapPass.Run(EmitError, EmitWarning, testMap);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EmitError("{0} failed with exception: {1}".F(customPassType, e));
|
||||
EmitError("{0} failed with exception: {1}".F(customMapPassType, e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,5 +115,22 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckRules(Ruleset rules, Map map = null)
|
||||
{
|
||||
foreach (var customRulesPassType in Game.ModData.ObjectCreator.GetTypesImplementing<ILintRulesPass>())
|
||||
{
|
||||
try
|
||||
{
|
||||
Game.ModData.RulesetCache.Load(map);
|
||||
var customRulesPass = (ILintRulesPass)Game.ModData.ObjectCreator.CreateBasic(customRulesPassType);
|
||||
customRulesPass.Run(EmitError, EmitWarning, rules);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EmitError("{0} failed with exception: {1}".F(customRulesPassType, e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user