Added try/catch for TypeDictionary errors in Lint code
TypeDictionary errors are very hard for modders to debug as they don't mention which actor is causing the error
This commit is contained in:
@@ -33,24 +33,32 @@ namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
foreach (var actorInfo in rules.Actors)
|
||||
{
|
||||
var count = actorInfo.Value.TraitInfos<IDefaultVisibilityInfo>().Count();
|
||||
|
||||
if (count == 0)
|
||||
emitError($"Actor type `{actorInfo.Key}` does not define a default visibility type!");
|
||||
else if (count > 1)
|
||||
emitError($"Actor type `{actorInfo.Key}` defines multiple default visibility types!");
|
||||
else
|
||||
// Catch TypeDictionary errors
|
||||
try
|
||||
{
|
||||
var vis = actorInfo.Value.TraitInfoOrDefault<HiddenUnderShroudInfo>();
|
||||
if (vis != null && vis.Type == VisibilityType.Footprint)
|
||||
var count = actorInfo.Value.TraitInfos<IDefaultVisibilityInfo>().Count();
|
||||
|
||||
if (count == 0)
|
||||
emitError($"Actor type `{actorInfo.Key}` does not define a default visibility type!");
|
||||
else if (count > 1)
|
||||
emitError($"Actor type `{actorInfo.Key}` defines multiple default visibility types!");
|
||||
else
|
||||
{
|
||||
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios == null)
|
||||
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{vis.GetType()}` but has no IOccupySpace traits!");
|
||||
else if (ios.OccupiedCells(actorInfo.Value, CPos.Zero).Count == 0)
|
||||
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{vis.GetType()}` but does not have any footprint cells!");
|
||||
var vis = actorInfo.Value.TraitInfoOrDefault<HiddenUnderShroudInfo>();
|
||||
if (vis != null && vis.Type == VisibilityType.Footprint)
|
||||
{
|
||||
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios == null)
|
||||
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{vis.GetType()}` but has no IOccupySpace traits!");
|
||||
else if (ios.OccupiedCells(actorInfo.Value, CPos.Zero).Count == 0)
|
||||
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{vis.GetType()}` but does not have any footprint cells!");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
emitError($"{e.Message} (Actor type `{actorInfo.Key}`)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user