diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index ab44af6..4e56064 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -166,6 +166,11 @@ namespace Encompass protected bool HasComponent(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(entity.ID); } diff --git a/encompass-cs/Renderer.cs b/encompass-cs/Renderer.cs index d96e93e..1e122b2 100644 --- a/encompass-cs/Renderer.cs +++ b/encompass-cs/Renderer.cs @@ -58,5 +58,15 @@ namespace Encompass { return GetComponents(entity).First(); } + + protected bool HasComponent(Entity entity) where TComponent : struct, IComponent + { + return componentManager.EntityHasComponentOfType(entity.ID); + } + + protected bool SomeComponent() where TComponent : struct, IComponent + { + return componentManager.GetActiveComponentsByType().Any(); + } } } diff --git a/test/ComponentTest.cs b/test/ComponentTest.cs index 30e1ba6..554e083 100644 --- a/test/ComponentTest.cs +++ b/test/ComponentTest.cs @@ -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 {