You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.5 KiB
95 lines
3.5 KiB
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="Universe.Lookup(Type)"/>. |
|
/// </summary> |
|
public interface ICreateEntityAttribute { } |
|
|
|
/// <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 |
|
{ |
|
/// <summary> Whether to add the entity to itself on registration. </summary> |
|
public bool AutoAdd { get; init; } = false; |
|
} |
|
|
|
/// <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)) { } } |
|
|
|
/// <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; } |
|
}
|
|
|