|
|
|
using System;
|
|
|
|
using static gaemstone.Flecs.Core;
|
|
|
|
|
|
|
|
namespace gaemstone.ECS;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// When present on an attribute attached to a type that's part of a module
|
|
|
|
/// being registered automatically through <see cref="ModuleManager.Register"/>,
|
|
|
|
/// an entity is automatically created and <see cref="LookupExtensions.CreateLookup"/>
|
|
|
|
/// called on it, meaning it can be looked up using <see cref="World.LookupByType(Type)"/>.
|
|
|
|
/// </summary>
|
|
|
|
public interface ICreateEntityAttribute { }
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Struct)]
|
|
|
|
public class EntityAttribute : Attribute, ICreateEntityAttribute { }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use a custom name or path for this entity instead of the type's name.
|
|
|
|
/// </summary>
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
|
|
|
|
public class PathAttribute : Attribute, ICreateEntityAttribute
|
|
|
|
{
|
|
|
|
public string Value { get; }
|
|
|
|
public PathAttribute(string value) => Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Register the entity under a globally unique symbol.
|
|
|
|
/// Uses the type's name by default.
|
|
|
|
/// </summary>
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
|
|
|
|
public class SymbolAttribute : Attribute, ICreateEntityAttribute
|
|
|
|
{
|
|
|
|
public string? Value { get; }
|
|
|
|
public SymbolAttribute() { }
|
|
|
|
public SymbolAttribute(string value) => Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A singleton is a single instance of a tag or component that can be retrieved
|
|
|
|
/// without explicitly specifying an entity in a query, where it is equivalent
|
|
|
|
/// to <see cref="SourceAttribute{}"/> with itself as the generic type parameter.
|
|
|
|
/// </summary>
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
|
|
|
|
public class SingletonAttribute : Attribute, ICreateEntityAttribute
|
|
|
|
{ public bool AutoAdd { get; init; } = true; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Register the proxied type instead of the one marked with this attribute.
|
|
|
|
/// This can be used to make types not registered in a module available,
|
|
|
|
/// including types registered in other assemblies.
|
|
|
|
/// </summary>
|
|
|
|
public class ProxyAttribute<T> : ProxyAttribute
|
|
|
|
{ public ProxyAttribute() : base(typeof(T)) { } }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Marked entity automatically has the specified entity added to it when
|
|
|
|
/// automatically registered. Equivalent to <see cref="EntityBase.Add{T}"/>.
|
|
|
|
/// </summary>
|
|
|
|
public class AddAttribute<TEntity> : AddEntityAttribute
|
|
|
|
{ public AddAttribute() : base(typeof(TEntity)) { } }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Marked entity automatically has the specified relationship pair added to it when
|
|
|
|
/// automatically registered, Equivalent to <see cref="EntityBase.Add{TRelation, TTarget}"/>.
|
|
|
|
/// </summary>
|
|
|
|
public class AddAttribute<TRelation, TTarget> : AddRelationAttribute
|
|
|
|
{ public AddAttribute() : base(typeof(TRelation), typeof(TTarget)) { } }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Marked entity represents a relationship type.
|
|
|
|
/// It may be used as the "relation" in a pair.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// The relationship may have component data associated with
|
|
|
|
/// it when added to an entity under these circumstances:
|
|
|
|
/// <list type="bullet">
|
|
|
|
/// <item>If marked as a <see cref="TagAttribute"/>, does not carry data.</item>
|
|
|
|
/// <item>If marked as a <see cref="ComponentAttribute"/>, carries the relation's data.</item>
|
|
|
|
/// <item>If marked with neither, will carry the target's data, if it's a component.</item>
|
|
|
|
/// </list>
|
|
|
|
/// </remarks>
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
|
|
|
|
public class RelationAttribute : Attribute, ICreateEntityAttribute { }
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
|
|
|
|
public class ComponentAttribute : Attribute, ICreateEntityAttribute { }
|
|
|
|
|
|
|
|
/// <seealso cref="Tag"/>
|
|
|
|
[AttributeUsage(AttributeTargets.Struct)]
|
|
|
|
public class TagAttribute : AddAttribute<Tag>, ICreateEntityAttribute { }
|
|
|
|
|
|
|
|
|
|
|
|
/// <seealso cref="IsA"/>
|
|
|
|
public class IsAAttribute<TTarget> : AddAttribute<IsA, TTarget> { }
|
|
|
|
|
|
|
|
/// <seealso cref="ChildOf"/>
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum)]
|
|
|
|
public class ChildOfAttribute<TTarget> : AddAttribute<ChildOf, TTarget> { }
|
|
|
|
|
|
|
|
/// <seealso cref="DependsOn"/>
|
|
|
|
public class DependsOnAttribute<TTarget> : AddAttribute<DependsOn, TTarget> { }
|
|
|
|
|
|
|
|
|
|
|
|
/// <seealso cref="Exclusive"/>
|
|
|
|
public class ExclusiveAttribute : AddAttribute<Exclusive> { }
|
|
|
|
|
|
|
|
/// <seealso cref="With"/>
|
|
|
|
public class WithAttribute<TTarget> : AddAttribute<With, TTarget> { }
|
|
|
|
|
|
|
|
|
|
|
|
// Base attributes for other attributes.
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Struct)]
|
|
|
|
public class ProxyAttribute : Attribute
|
|
|
|
{
|
|
|
|
public Type Type { get; }
|
|
|
|
internal ProxyAttribute(Type type) => Type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = true)]
|
|
|
|
public class AddEntityAttribute : Attribute
|
|
|
|
{
|
|
|
|
public Type Entity { get; }
|
|
|
|
internal AddEntityAttribute(Type entity) => Entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = true)]
|
|
|
|
public class AddRelationAttribute : Attribute
|
|
|
|
{
|
|
|
|
public Type Relation { get; }
|
|
|
|
public Type Target { get; }
|
|
|
|
internal AddRelationAttribute(Type relation, Type target)
|
|
|
|
{ Relation = relation; Target = target; }
|
|
|
|
}
|