encompass-cs/src/Entity.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2019-06-13 02:51:36 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
namespace Encompass
{
2019-06-14 05:15:15 +00:00
public struct Entity
2019-06-13 02:51:36 +00:00
{
public readonly uint id;
2019-06-13 02:51:36 +00:00
private ComponentManager componentManager;
2019-06-13 02:51:36 +00:00
internal Entity(uint id, ComponentManager componentManager) {
2019-06-13 02:51:36 +00:00
this.id = id;
this.componentManager = componentManager;
2019-06-13 02:51:36 +00:00
}
2019-06-14 05:15:15 +00:00
public void AddComponent<TComponent>(TComponent component) where TComponent : struct, IComponent {
componentManager.AddComponent<TComponent>(id, component);
2019-06-13 02:51:36 +00:00
}
2019-06-14 05:15:15 +00:00
public IEnumerable<TComponent> GetComponents<TComponent>() where TComponent : struct, IComponent {
return componentManager.GetComponentsByEntityAndType<TComponent>(id);
2019-06-13 02:51:36 +00:00
}
2019-06-14 05:15:15 +00:00
public TComponent GetComponent<TComponent>() where TComponent : struct, IComponent {
2019-06-13 02:51:36 +00:00
return GetComponents<TComponent>().First();
}
2019-06-14 05:15:15 +00:00
public bool HasComponent<TComponent>() where TComponent : struct, IComponent {
return componentManager.EntityHasComponentOfType<TComponent>(id);
}
internal void RemoveAllComponents() {
componentManager.RemoveAllComponentsFromEntity(id);
2019-06-13 02:51:36 +00:00
}
}
}