Fix CA1851
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
@@ -21,8 +20,8 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
var selectable = actorInfo.Value.TraitInfos<SelectableInfo>().Count();
|
||||
var interactable = actorInfo.Value.TraitInfos<InteractableInfo>().Count();
|
||||
var selectable = actorInfo.Value.TraitInfos<SelectableInfo>().Count;
|
||||
var interactable = actorInfo.Value.TraitInfos<InteractableInfo>().Count;
|
||||
if (selectable > 0 && selectable != interactable)
|
||||
emitWarning($"Actor `{actorInfo.Value.Name}` defines both Interactable and Selectable traits. This may cause unexpected results.");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
try
|
||||
{
|
||||
var visibilityTypes = actorInfo.Value.TraitInfos<IDefaultVisibilityInfo>();
|
||||
var count = visibilityTypes.Count();
|
||||
var count = visibilityTypes.Count;
|
||||
|
||||
if (count == 0)
|
||||
emitError($"Actor type `{actorInfo.Key}` does not define a default visibility type.");
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Server;
|
||||
using OpenRA.Traits;
|
||||
@@ -41,7 +40,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
continue;
|
||||
|
||||
var hitShapes = actorInfo.Value.TraitInfos<HitShapeInfo>();
|
||||
if (!hitShapes.Any())
|
||||
if (hitShapes.Count == 0)
|
||||
emitError($"Actor type `{actorInfo.Key}` has a Health trait but no HitShape trait.");
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Server;
|
||||
@@ -32,12 +33,15 @@ namespace OpenRA.Mods.Common.Lint
|
||||
static void Run(Action<string> emitError, Ruleset rules)
|
||||
{
|
||||
var worldActor = rules.Actors[SystemActors.World];
|
||||
var locomotorInfos = worldActor.TraitInfos<LocomotorInfo>().ToArray();
|
||||
foreach (var li in locomotorInfos)
|
||||
foreach (var otherLocomotor in locomotorInfos)
|
||||
if (li != otherLocomotor && li.Name == otherLocomotor.Name)
|
||||
emitError($"More than one Locomotor exists with the name `{li.Name}`.");
|
||||
var locomotorNames = worldActor.TraitInfos<LocomotorInfo>().Select(li => li.Name).ToList();
|
||||
var duplicateNames = locomotorNames
|
||||
.GroupBy(name => name)
|
||||
.Where(g => g.Count() > 1)
|
||||
.Select(g => g.Key);
|
||||
foreach (var duplicateName in duplicateNames)
|
||||
emitError($"More than one Locomotor exists with the name `{duplicateName}`.");
|
||||
|
||||
var locomotorNamesSet = locomotorNames.ToHashSet();
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
foreach (var traitInfo in actorInfo.Value.TraitInfos<TraitInfo>())
|
||||
@@ -51,16 +55,16 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (string.IsNullOrEmpty(locomotor))
|
||||
continue;
|
||||
|
||||
CheckLocomotors(actorInfo.Value, emitError, locomotorInfos, locomotor);
|
||||
CheckLocomotors(actorInfo.Value, emitError, locomotorNamesSet, locomotor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckLocomotors(ActorInfo actorInfo, Action<string> emitError, LocomotorInfo[] locomotorInfos, string locomotor)
|
||||
static void CheckLocomotors(ActorInfo actorInfo, Action<string> emitError, HashSet<string> locomotorNames, string locomotor)
|
||||
{
|
||||
if (!locomotorInfos.Any(l => l.Name == locomotor))
|
||||
if (!locomotorNames.Contains(locomotor))
|
||||
emitError($"Actor `{actorInfo.Name}` defines Locomotor `{locomotor}` not found on World actor.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,12 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
var wsbs = actorInfo.Value.TraitInfos<WithSpriteBodyInfo>();
|
||||
foreach (var wsb in wsbs)
|
||||
if (wsbs.Any(w => w != wsb && w.Name == wsb.Name))
|
||||
emitError($"Actor type `{actorInfo.Key}` has more than one *SpriteBody with Name: {wsb.Name}.");
|
||||
var duplicateNames = actorInfo.Value.TraitInfos<WithSpriteBodyInfo>()
|
||||
.GroupBy(wsb => wsb.Name)
|
||||
.Where(g => g.Count() > 1)
|
||||
.Select(g => g.Key);
|
||||
foreach (var duplicateName in duplicateNames)
|
||||
emitError($"Actor type `{actorInfo.Key}` has more than one *SpriteBody with Name: {duplicateName}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user