fix bug when no messages existed for queried entity

pull/5/head
Evan Hemsley 2019-12-29 20:41:35 -08:00
parent df7abf4cf3
commit 9057228795
2 changed files with 15 additions and 1 deletions

View File

@ -90,7 +90,7 @@ namespace Encompass
public IEnumerable<TMessage> WithEntity(int entityID)
{
return entityToMessage[entityID];
return entityToMessage.ContainsKey(entityID) ? entityToMessage[entityID] : System.Linq.Enumerable.Empty<TMessage>();
}
public override void Clear()

View File

@ -483,6 +483,20 @@ namespace Tests
entityMessageResults.Should().ContainEquivalentOf(new EntityMessage(entity, 5));
}
[Test]
public void NoMessagesWithEntity()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
worldBuilder.AddEngine(new EntityMessageReceiverEngine(entity));
var world = worldBuilder.Build();
world.Update(0.01);
entityMessageResults.Should().BeEmpty();
}
class SomeComponentTestEngine : Engine
{
public override void Update(double dt)