encompass-cs/encompass-cs/Entity.cs

70 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Encompass
{
public struct Entity
{
public readonly Guid id;
private readonly ComponentManager componentManager;
internal Entity(Guid id, ComponentManager componentManager)
{
this.id = id;
this.componentManager = componentManager;
}
public Guid AddComponent<TComponent>(TComponent component) where TComponent : struct, IComponent
{
return componentManager.AddComponent(id, component);
}
public Guid AddDrawComponent<TComponent>(TComponent component, int layer = 0) where TComponent : struct, IComponent
{
return componentManager.AddDrawComponent(id, component, layer);
}
public IEnumerable<KeyValuePair<Guid, TComponent>> GetComponents<TComponent>() where TComponent : struct, IComponent
{
return componentManager.GetComponentsByEntityAndType<TComponent>(id);
}
public KeyValuePair<Guid, TComponent> GetComponent<TComponent>() where TComponent : struct, IComponent
{
return GetComponents<TComponent>().First();
}
public bool HasComponent<TComponent>() where TComponent : struct, IComponent
{
return componentManager.EntityHasComponentOfType<TComponent>(id);
}
internal bool HasComponent(Type type)
{
return componentManager.EntityHasComponentOfType(id, type);
}
public void ActivateComponent(Guid componentID)
{
componentManager.MarkForActivation(componentID);
}
public void DeactivateComponent(Guid componentID)
{
componentManager.MarkForDeactivation(componentID);
}
public void RemoveComponent(Guid componentID)
{
componentManager.MarkForRemoval(componentID);
}
internal void RemoveAllComponents()
{
componentManager.RemoveAllComponentsFromEntity(id);
}
}
}