Merge pull request #9083 from Mailaender/lint-cleanup
Cleaned up the ILint boiler plate code
This commit is contained in:
@@ -327,7 +327,9 @@ namespace OpenRA.Traits
|
|||||||
Stance oldStance, Stance newStance);
|
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
|
public interface IObjectivesPanel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,17 +15,12 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
public class CheckActorReferences : ILintPass
|
public class CheckActorReferences : ILintRulesPass
|
||||||
{
|
{
|
||||||
Action<string> emitError;
|
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;
|
this.emitError = emitError;
|
||||||
|
|
||||||
foreach (var actorInfo in rules.Actors)
|
foreach (var actorInfo in rules.Actors)
|
||||||
|
|||||||
@@ -14,13 +14,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
public class CheckActors : ILintPass
|
public class CheckActors : ILintMapPass
|
||||||
{
|
{
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||||
{
|
{
|
||||||
if (map == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var actorTypes = map.ActorDefinitions.Select(a => a.Value.Value);
|
var actorTypes = map.ActorDefinitions.Select(a => a.Value.Value);
|
||||||
foreach (var actor in actorTypes)
|
foreach (var actor in actorTypes)
|
||||||
if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant()))
|
if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant()))
|
||||||
|
|||||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
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)
|
foreach (var actorInfo in rules.Actors)
|
||||||
{
|
{
|
||||||
var animations = actorInfo.Value.Traits.WithInterface<WithDeathAnimationInfo>().ToList();
|
var animations = actorInfo.Value.Traits.WithInterface<WithDeathAnimationInfo>().ToList();
|
||||||
|
|||||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
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)
|
foreach (var actorInfo in rules.Actors)
|
||||||
{
|
{
|
||||||
if (actorInfo.Key.StartsWith("^"))
|
if (actorInfo.Key.StartsWith("^"))
|
||||||
|
|||||||
@@ -14,13 +14,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
public class CheckMapCordon : ILintPass
|
public class CheckMapCordon : ILintMapPass
|
||||||
{
|
{
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||||
{
|
{
|
||||||
if (map == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (map.Bounds.Left == 0 || map.Bounds.Top == 0
|
if (map.Bounds.Left == 0 || map.Bounds.Top == 0
|
||||||
|| map.Bounds.Right == map.MapSize.X || map.Bounds.Bottom == map.MapSize.Y)
|
|| map.Bounds.Right == map.MapSize.X || map.Bounds.Bottom == map.MapSize.Y)
|
||||||
emitError("This map does not define a valid cordon.\n"
|
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
|
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();
|
var palettes = GetPalettes(emitError, rules).ToList();
|
||||||
|
|
||||||
foreach (var actorInfo in rules.Actors)
|
foreach (var actorInfo in rules.Actors)
|
||||||
|
|||||||
@@ -15,13 +15,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
public class CheckPlayers : ILintPass
|
public class CheckPlayers : ILintMapPass
|
||||||
{
|
{
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||||
{
|
{
|
||||||
if (map == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var players = new MapPlayers(map.PlayerDefinitions).Players;
|
var players = new MapPlayers(map.PlayerDefinitions).Players;
|
||||||
|
|
||||||
var playerNames = players.Values.Select(p => p.Name).ToHashSet();
|
var playerNames = players.Values.Select(p => p.Name).ToHashSet();
|
||||||
|
|||||||
@@ -16,15 +16,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
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)
|
foreach (var actorInfo in rules.Actors)
|
||||||
{
|
{
|
||||||
if (actorInfo.Key.StartsWith("^"))
|
if (actorInfo.Key.StartsWith("^"))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
class CheckSequences : ILintPass
|
class CheckSequences : ILintMapPass
|
||||||
{
|
{
|
||||||
Action<string> emitError;
|
Action<string> emitError;
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,8 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
{
|
{
|
||||||
class CheckSyncAnnotations : ILintPass
|
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 */
|
/* first, check all the types implementing ISync */
|
||||||
foreach (var t in Game.ModData.ObjectCreator.GetTypesImplementing<ISync>())
|
foreach (var t in Game.ModData.ObjectCreator.GetTypesImplementing<ISync>())
|
||||||
if (!HasAnySyncFields(t))
|
if (!HasAnySyncFields(t))
|
||||||
|
|||||||
@@ -14,16 +14,12 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
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("^")))
|
foreach (var actorInfo in rules.Actors.Where(a => !a.Key.StartsWith("^")))
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var hasTraits = actorInfo.Value.TraitsInConstructOrder().Any();
|
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));
|
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
|
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);
|
CheckUpgradesValidity(emitError, rules);
|
||||||
CheckUpgradesUsage(emitError, emitWarning, rules);
|
CheckUpgradesUsage(emitError, emitWarning, rules);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
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 actorInfo in rules.Actors)
|
||||||
{
|
{
|
||||||
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
|
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())
|
||||||
|
|||||||
@@ -15,15 +15,10 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
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
|
// ProvidesPrerequisite allows arbitrary prereq definitions
|
||||||
var customPrereqs = rules.Actors.SelectMany(a => a.Value.Traits
|
var customPrereqs = rules.Actors.SelectMany(a => a.Value.Traits
|
||||||
.WithInterface<ProvidesPrerequisiteInfo>().Select(p => p.Prerequisite ?? a.Value.Name));
|
.WithInterface<ProvidesPrerequisiteInfo>().Select(p => p.Prerequisite ?? a.Value.Name));
|
||||||
|
|||||||
@@ -182,7 +182,6 @@
|
|||||||
<Compile Include="Lint\CheckPlayers.cs" />
|
<Compile Include="Lint\CheckPlayers.cs" />
|
||||||
<Compile Include="Lint\CheckActors.cs" />
|
<Compile Include="Lint\CheckActors.cs" />
|
||||||
<Compile Include="Lint\CheckMapCordon.cs" />
|
<Compile Include="Lint\CheckMapCordon.cs" />
|
||||||
<Compile Include="Lint\CheckMapRules.cs" />
|
|
||||||
<Compile Include="Lint\CheckActorReferences.cs" />
|
<Compile Include="Lint\CheckActorReferences.cs" />
|
||||||
<Compile Include="Lint\CheckSyncAnnotations.cs" />
|
<Compile Include="Lint\CheckSyncAnnotations.cs" />
|
||||||
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
|
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
|
||||||
|
|||||||
@@ -52,7 +52,25 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
var maps = new List<Map>();
|
var maps = new List<Map>();
|
||||||
if (args.Length < 2)
|
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();
|
Game.ModData.MapCache.LoadMaps();
|
||||||
maps.AddRange(Game.ModData.MapCache
|
maps.AddRange(Game.ModData.MapCache
|
||||||
.Where(m => m.Status == MapStatus.Available)
|
.Where(m => m.Status == MapStatus.Available)
|
||||||
@@ -63,29 +81,24 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
foreach (var testMap in maps)
|
foreach (var testMap in maps)
|
||||||
{
|
{
|
||||||
if (testMap != null)
|
Console.WriteLine("Testing map: {0}".F(testMap.Title));
|
||||||
{
|
testMap.PreloadRules();
|
||||||
Console.WriteLine("Testing map: {0}".F(testMap.Title));
|
|
||||||
testMap.PreloadRules();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Testing mod: {0}".F(Game.ModData.Manifest.Mod.Title));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var customPassType in Game.ModData.ObjectCreator
|
// Run all rule checks on the map if it defines custom rules.
|
||||||
.GetTypesImplementing<ILintPass>())
|
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
|
try
|
||||||
{
|
{
|
||||||
var customPass = (ILintPass)Game.ModData.ObjectCreator
|
var customMapPass = (ILintMapPass)Game.ModData.ObjectCreator.CreateBasic(customMapPassType);
|
||||||
.CreateBasic(customPassType);
|
customMapPass.Run(EmitError, EmitWarning, testMap);
|
||||||
|
|
||||||
customPass.Run(EmitError, EmitWarning, testMap);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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);
|
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