adds read check to HasComponent and HasComponent and SomeComponent to Renderer

pull/5/head
Evan Hemsley 2019-07-17 13:15:15 -07:00
parent 4c82337362
commit 949c3aa26d
3 changed files with 18 additions and 3 deletions

View File

@ -166,6 +166,11 @@ namespace Encompass
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (!readTypes.Contains(typeof(TComponent)))
{
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", this.GetType().Name, typeof(TComponent).Name);
}
return componentManager.EntityHasComponentOfType<TComponent>(entity.ID);
}

View File

@ -58,5 +58,15 @@ namespace Encompass
{
return GetComponents<TComponent>(entity).First();
}
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return componentManager.EntityHasComponentOfType<TComponent>(entity.ID);
}
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
{
return componentManager.GetActiveComponentsByType<TComponent>().Any();
}
}
}

View File

@ -201,7 +201,7 @@ namespace Tests
public Entity entity;
}
[Reads(typeof(HasComponentWhenInactiveTestMessage))]
[Reads(typeof(HasComponentWhenInactiveTestMessage), typeof(MockComponent))]
class HasComponentWhenInactiveTestEngine : Engine
{
public override void Update(double dt)
@ -290,7 +290,7 @@ namespace Tests
public Guid componentID;
}
[Reads(typeof(ActivateComponentMessage))]
[Reads(typeof(ActivateComponentMessage), typeof(MockComponent))]
[Writes(typeof(MockComponent))]
class ActivateComponentEngine : Engine
{
@ -336,7 +336,7 @@ namespace Tests
public Guid componentID;
}
[Reads(typeof(DeactivateComponentMessage))]
[Reads(typeof(DeactivateComponentMessage), typeof(MockComponent))]
[Writes(typeof(MockComponent))]
class DeactivateComponentEngine : Engine
{