namespace Svelto.ECS
{
///
/// Inherit from an ExtendibleEntityDescriptor to extend a base entity descriptor that can be used
/// to swap and remove specialized entities from abstract engines
///
/// Usage Example:
///
/// class SpecialisedDescriptor : ExtendibleEntityDescriptor
/// {
/// public SpecialisedDescriptor() : base (new IComponentBuilder[]
/// {
/// new ComponentBuilder() //add more components to the base descriptor
/// })
/// {
/// ExtendWith(); //add extra components from descriptors that act as contract
/// }
/// }
///
///
public abstract class ExtendibleEntityDescriptor : IDynamicEntityDescriptor where TType : IEntityDescriptor, new()
{
static ExtendibleEntityDescriptor()
{
//I am removing this check because in reality there is not a strong reason to forbid it and
//furthermore it's already possible to extend a SerializableEntityDescriptor through DynamicEntityDescriptor
// if (typeof(ISerializableEntityDescriptor).IsAssignableFrom(typeof(TType)))
// throw new Exception(
// $"SerializableEntityDescriptors cannot be used as base entity descriptor: {typeof(TType)}");
}
protected ExtendibleEntityDescriptor(IComponentBuilder[] extraEntities)
{
_dynamicDescriptor = new DynamicEntityDescriptor(extraEntities);
}
protected ExtendibleEntityDescriptor()
{
_dynamicDescriptor = new DynamicEntityDescriptor(true);
}
protected ExtendibleEntityDescriptor ExtendWith() where T : IEntityDescriptor, new()
{
_dynamicDescriptor.ExtendWith();
return this;
}
protected ExtendibleEntityDescriptor ExtendWith(IComponentBuilder[] extraEntities)
{
_dynamicDescriptor.ExtendWith(extraEntities);
return this;
}
protected void Add() where T : struct, IEntityComponent
{
_dynamicDescriptor.Add();
}
protected void Add() where T : struct, IEntityComponent where U : struct, IEntityComponent
{
_dynamicDescriptor.Add();
}
protected void Add() where T : struct, IEntityComponent where U : struct, IEntityComponent where V : struct, IEntityComponent
{
_dynamicDescriptor.Add();
}
public IComponentBuilder[] componentsToBuild => _dynamicDescriptor.componentsToBuild;
DynamicEntityDescriptor _dynamicDescriptor;
}
}