Exception should inform which actors causes it.

This commit is contained in:
Andre Mohren
2019-07-13 18:14:19 +02:00
committed by Paul Chote
parent b5c387774c
commit ebc533ed53

View File

@@ -86,13 +86,13 @@ namespace OpenRA
public T Get<T>(Actor actor) public T Get<T>(Actor actor)
{ {
CheckDestroyed(actor); CheckDestroyed(actor);
return InnerGet<T>().Get(actor.ActorID); return InnerGet<T>().Get(actor);
} }
public T GetOrDefault<T>(Actor actor) public T GetOrDefault<T>(Actor actor)
{ {
CheckDestroyed(actor); CheckDestroyed(actor);
return InnerGet<T>().GetOrDefault(actor.ActorID); return InnerGet<T>().GetOrDefault(actor);
} }
public IEnumerable<T> WithInterface<T>(Actor actor) public IEnumerable<T> WithInterface<T>(Actor actor)
@@ -144,22 +144,22 @@ namespace OpenRA
traits.Insert(insertIndex, (T)trait); traits.Insert(insertIndex, (T)trait);
} }
public T Get(uint actor) public T Get(Actor actor)
{ {
var result = GetOrDefault(actor); var result = GetOrDefault(actor);
if (result == null) if (result == null)
throw new InvalidOperationException("Actor does not have trait of type `{0}`".F(typeof(T))); throw new InvalidOperationException("Actor {0} does not have trait of type `{1}`".F(actor.Info.Name, typeof(T)));
return result; return result;
} }
public T GetOrDefault(uint actor) public T GetOrDefault(Actor actor)
{ {
++Queries; ++Queries;
var index = actors.BinarySearchMany(actor); var index = actors.BinarySearchMany(actor.ActorID);
if (index >= actors.Count || actors[index].ActorID != actor) if (index >= actors.Count || actors[index] != actor)
return default(T); return default(T);
else if (index + 1 < actors.Count && actors[index + 1].ActorID == actor) else if (index + 1 < actors.Count && actors[index + 1] == actor)
throw new InvalidOperationException("Actor {0} has multiple traits of type `{1}`".F(actors[index].Info.Name, typeof(T))); throw new InvalidOperationException("Actor {0} has multiple traits of type `{1}`".F(actor.Info.Name, typeof(T)));
else return traits[index]; else return traits[index];
} }