2019-06-17 18:33:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-06-13 02:51:36 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
|
{
|
2019-06-14 05:15:15 +00:00
|
|
|
|
public struct Entity
|
2019-06-13 02:51:36 +00:00
|
|
|
|
{
|
2019-06-17 18:33:38 +00:00
|
|
|
|
public readonly Guid id;
|
2019-06-13 02:51:36 +00:00
|
|
|
|
|
2019-06-14 03:28:26 +00:00
|
|
|
|
private ComponentManager componentManager;
|
2019-06-13 02:51:36 +00:00
|
|
|
|
|
2019-06-17 18:33:38 +00:00
|
|
|
|
internal Entity(Guid id, ComponentManager componentManager)
|
2019-06-16 01:05:56 +00:00
|
|
|
|
{
|
2019-06-13 02:51:36 +00:00
|
|
|
|
this.id = id;
|
2019-06-14 03:28:26 +00:00
|
|
|
|
this.componentManager = componentManager;
|
2019-06-13 02:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 18:33:38 +00:00
|
|
|
|
public Guid AddComponent<TComponent>(TComponent component) where TComponent : struct, IComponent
|
2019-06-16 01:05:56 +00:00
|
|
|
|
{
|
2019-06-17 18:33:38 +00:00
|
|
|
|
return componentManager.AddComponent<TComponent>(id, component);
|
2019-06-13 02:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 18:33:38 +00:00
|
|
|
|
public IEnumerable<KeyValuePair<Guid, TComponent>> GetComponents<TComponent>() where TComponent : struct, IComponent
|
2019-06-16 01:05:56 +00:00
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
|
return componentManager.GetComponentsByEntityAndType<TComponent>(id);
|
2019-06-13 02:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 18:33:38 +00:00
|
|
|
|
public KeyValuePair<Guid, TComponent> GetComponent<TComponent>() where TComponent : struct, IComponent
|
2019-06-16 01:05:56 +00:00
|
|
|
|
{
|
2019-06-13 02:51:36 +00:00
|
|
|
|
return GetComponents<TComponent>().First();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
|
public bool HasComponent<TComponent>() where TComponent : struct, IComponent
|
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
|
return componentManager.EntityHasComponentOfType<TComponent>(id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 21:14:44 +00:00
|
|
|
|
internal bool HasComponent(Type type)
|
|
|
|
|
{
|
|
|
|
|
return componentManager.EntityHasComponentOfType(id, type);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
|
internal void RemoveAllComponents()
|
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
|
componentManager.RemoveAllComponentsFromEntity(id);
|
2019-06-13 02:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|