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.
 
 

77 lines
2.8 KiB

using System;
namespace gaemstone;
/// <summary>
/// Entities marked with this attribute are automatically registered with a
/// <see cref="EntityRef.Symbol"/> specified in the attribute constructor,
/// defaulting to their <see cref="EntityRef.Name"/> if not given.
///
/// Symbols are unique string identifiers used to look up their entities.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct
| AttributeTargets.Enum | AttributeTargets.Method)]
public class SymbolAttribute : Attribute
{
public string? Value { get; }
public SymbolAttribute() { }
public SymbolAttribute(string value) => Value = value;
}
// TODO: Should this be renamed from [Add<...>] to something else?
/// <summary>
/// Marked entity automatically has the specified entity added to it when
/// automatically registered. Equivalent to <see cref="EntityBuilder.Add{T}"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct
| AttributeTargets.Enum | AttributeTargets.Method,
AllowMultiple = true)]
public class AddAttribute<TEntity> : Attribute { }
/// <summary>
/// Marked entity automatically has the specified relationship pair added to it when
/// automatically registered. Equivalent to <see cref="EntityBuilder.Add{TRelation, TTarget}"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct
| AttributeTargets.Enum | AttributeTargets.Method,
AllowMultiple = true)]
public class AddAttribute<TRelation, TTarget> : Attribute { }
/// <summary>
/// Marked entity automatically has the specified component added to it when
/// automatically registered. Equivalent to <see cref="EntityBuilder.Set{TComponent}"/>.
/// Arguments are passed to a valid constructor with matching arguments. Only
/// attribute-safe primitives are allowed for the specified arguments.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct
| AttributeTargets.Enum | AttributeTargets.Method,
AllowMultiple = true)]
public class SetAttribute<TComponent> : Attribute
{
public object[] Arguments { get; }
public SetAttribute(params object[] args) => Arguments = args;
}
/// <seealso cref="IsA"/>
public class IsAAttribute<TTarget>
: AddAttribute<flecs.core.IsA, TTarget> { }
/// <seealso cref="ChildOf"/>
public class ChildOfAttribute<TTarget>
: AddAttribute<flecs.core.ChildOf, TTarget> { }
/// <seealso cref="DependsOn"/>
public class DependsOnAttribute<TTarget>
: AddAttribute<flecs.core.DependsOn, TTarget> { }
/// <seealso cref="Exclusive"/>
public class ExclusiveAttribute
: AddAttribute<flecs.core.Exclusive> { }
/// <seealso cref="With"/>
public class WithAttribute<TTarget>
: AddAttribute<flecs.core.With, TTarget> { }