From da507b2eedede4dd98d6ba7aebe2861fba205c8f Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 12 Dec 2023 18:54:30 +0100 Subject: [PATCH] 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. --- OpenRA.Mods.Common/Lint/CheckActors.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Lint/CheckActors.cs b/OpenRA.Mods.Common/Lint/CheckActors.cs index f0cacd80ea..757347c014 100644 --- a/OpenRA.Mods.Common/Lint/CheckActors.cs +++ b/OpenRA.Mods.Common/Lint/CheckActors.cs @@ -11,6 +11,7 @@ using System; using System.Linq; +using OpenRA.Scripting; namespace OpenRA.Mods.Common.Lint { @@ -18,10 +19,16 @@ namespace OpenRA.Mods.Common.Lint { public void Run(Action emitError, Action emitWarning, ModData modData, Map map) { - var actorTypes = map.ActorDefinitions.Select(a => a.Value.Value); - foreach (var actor in actorTypes) - if (!map.Rules.Actors.Keys.Contains(actor.ToLowerInvariant())) - emitError($"Actor `{actor}` is not defined by any rule."); + var scriptBindings = Game.ModData.ObjectCreator.GetTypesImplementing().Select(t => Utility.GetCustomAttributes(t, true)[0].Name).ToHashSet(); + foreach (var actor in map.ActorDefinitions) + { + 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."); + } } } }