Add a lint check to ensure no actor names are conflicting with script names
Only scripted maps will have the need to use named actors, so we can assume that there will be a Lua script used in maps with such actors.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Scripting;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
@@ -18,10 +19,16 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
{
|
{
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning, ModData modData, Map map)
|
public void Run(Action<string> emitError, Action<string> emitWarning, ModData modData, Map map)
|
||||||
{
|
{
|
||||||
var actorTypes = map.ActorDefinitions.Select(a => a.Value.Value);
|
var scriptBindings = Game.ModData.ObjectCreator.GetTypesImplementing<ScriptGlobal>().Select(t => Utility.GetCustomAttributes<ScriptGlobalAttribute>(t, true)[0].Name).ToHashSet();
|
||||||
foreach (var actor in actorTypes)
|
foreach (var actor in map.ActorDefinitions)
|
||||||
if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant()))
|
{
|
||||||
emitError($"Actor `{actor}` is not defined by any rule.");
|
var name = actor.Value.Value;
|
||||||
|
if (!map.Rules.Actors.ContainsKey(name.ToLowerInvariant()))
|
||||||
|
emitError($"Actor `{name}` is not defined by any rule.");
|
||||||
|
|
||||||
|
if (scriptBindings.Contains(actor.Key))
|
||||||
|
emitError($"Named actor `{actor.Key}` conflicts with a script global of the same name. Consider renaming the actor.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user