fix panic when using runtime HasComponent
parent
2a62adee51
commit
bdac3d8541
|
@ -33,7 +33,7 @@ namespace Encompass
|
|||
|
||||
public bool Has(Type type, Entity entity)
|
||||
{
|
||||
return Stores[type].Has(entity);
|
||||
return Stores.ContainsKey(type) && Stores[type].Has(entity);
|
||||
}
|
||||
|
||||
public TComponent Get<TComponent>(Entity entity) where TComponent : struct, IComponent
|
||||
|
|
|
@ -308,6 +308,8 @@ namespace Tests
|
|||
world.Update(0.01);
|
||||
}
|
||||
|
||||
static bool hasComponentRuntimeTypeResult;
|
||||
|
||||
[Receives(typeof(HasComponentTestMessage))]
|
||||
[Reads(typeof(MockComponent))]
|
||||
class HasComponentWithRuntimeTypeEngine : Engine
|
||||
|
@ -316,7 +318,7 @@ namespace Tests
|
|||
{
|
||||
foreach (var hasComponentTestEngine in ReadMessages<HasComponentTestMessage>())
|
||||
{
|
||||
Assert.IsTrue(HasComponent(hasComponentTestEngine.entity, typeof(MockComponent)));
|
||||
hasComponentRuntimeTypeResult = HasComponent(hasComponentTestEngine.entity, typeof(MockComponent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -342,6 +344,27 @@ namespace Tests
|
|||
var world = worldBuilder.Build();
|
||||
|
||||
world.Update(0.01);
|
||||
|
||||
Assert.IsTrue(hasComponentRuntimeTypeResult);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasComponentWithRuntimeTypeFalseWhenNoneHaveBeenCreated()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine(new HasComponentWithRuntimeTypeEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
HasComponentTestMessage hasComponentTestMessage;
|
||||
hasComponentTestMessage.entity = entity;
|
||||
worldBuilder.SendMessage(hasComponentTestMessage);
|
||||
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
world.Update(0.01);
|
||||
|
||||
Assert.IsFalse(hasComponentRuntimeTypeResult);
|
||||
}
|
||||
|
||||
struct RemoveComponentTestMessage : IMessage
|
||||
|
|
Loading…
Reference in New Issue