78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Encompass
|
|
{
|
|
public abstract class Renderer
|
|
{
|
|
internal EntityManager entityManager;
|
|
internal ComponentManager componentManager;
|
|
|
|
internal void AssignEntityManager(EntityManager entityManager)
|
|
{
|
|
this.entityManager = entityManager;
|
|
}
|
|
|
|
internal void AssignComponentManager(ComponentManager componentManager)
|
|
{
|
|
this.componentManager = componentManager;
|
|
}
|
|
|
|
internal Guid GetEntityIDByComponentID(Guid componentID)
|
|
{
|
|
return componentManager.GetEntityIDByComponentID(componentID);
|
|
}
|
|
|
|
internal Entity GetEntity(Guid entityID)
|
|
{
|
|
return entityManager.GetEntity(entityID);
|
|
}
|
|
|
|
protected IEnumerable<Entity> ReadEntities<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return ReadComponentsIncludingEntity<TComponent>().Select(tuple => tuple.Item2);
|
|
}
|
|
|
|
protected Entity ReadEntity<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return ReadComponentIncludingEntity<TComponent>().Item2;
|
|
}
|
|
|
|
protected IEnumerable<TComponent> ReadComponents<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentsByType<TComponent>().Select(tuple => tuple.Item2);
|
|
}
|
|
|
|
protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentsByType<TComponent>().Select(tuple => (tuple.Item2, GetEntity(GetEntityIDByComponentID(tuple.Item1))));
|
|
}
|
|
|
|
protected TComponent ReadComponent<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return ReadComponents<TComponent>().First();
|
|
}
|
|
|
|
protected (TComponent, Entity) ReadComponentIncludingEntity<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return ReadComponentsIncludingEntity<TComponent>().First();
|
|
}
|
|
|
|
protected TComponent GetComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentByEntityAndType<TComponent>(entity).Item2;
|
|
}
|
|
|
|
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.EntityHasComponentOfType<TComponent>(entity);
|
|
}
|
|
|
|
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.ComponentOfTypeExists<TComponent>();
|
|
}
|
|
}
|
|
}
|