73 lines
2.4 KiB
C#
73 lines
2.4 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;
|
|
}
|
|
|
|
protected bool EntityExists(Guid entityID)
|
|
{
|
|
return entityManager.EntityExists(entityID);
|
|
}
|
|
|
|
protected Entity GetEntity(Guid entityID)
|
|
{
|
|
return entityManager.GetEntity(entityID);
|
|
}
|
|
|
|
protected Guid GetEntityIDByComponentID(Guid componentID)
|
|
{
|
|
return componentManager.GetEntityIDByComponentID(componentID);
|
|
}
|
|
|
|
protected Entity GetEntityByComponentID(Guid componentID)
|
|
{
|
|
return GetEntity(GetEntityIDByComponentID(componentID));
|
|
}
|
|
|
|
protected IEnumerable<ValueTuple<Guid, TComponent>> ReadComponents<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentsByType<TComponent>().Select((triple) => (triple.Item2, triple.Item3));
|
|
}
|
|
|
|
protected ValueTuple<Guid, TComponent> ReadComponent<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return ReadComponents<TComponent>().Single();
|
|
}
|
|
|
|
protected IEnumerable<ValueTuple<Guid, TComponent>> GetComponents<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentsByEntityAndType<TComponent>(entity.ID);
|
|
}
|
|
|
|
protected ValueTuple<Guid, TComponent> GetComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
{
|
|
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.GetComponentsByType<TComponent>().Any();
|
|
}
|
|
}
|
|
}
|