using System; using static flecs_hub.flecs; namespace gaemstone.ECS; [AttributeUsage(AttributeTargets.Struct)] public class EntityAttribute : Attribute, ICreateEntityAttribute { /// If specified, uses this path instead of the default name. public string[]? Path { get; } /// If true, the path will be absolute instead of relative. public bool Global { get; init; } public EntityAttribute() { } public EntityAttribute(params string[] path) { if (path.Length == 0) throw new ArgumentException( "Path must not be empty", nameof(path)); Path = path; } } public readonly struct Entity : IEquatable { public static readonly Entity None = default; public readonly ecs_entity_t Value; public uint ID => (uint)Value.Data; public bool IsSome => Value.Data != 0; public bool IsNone => Value.Data == 0; public Entity(ecs_entity_t value) => Value = value; public bool Equals(Entity other) => Value.Data == other.Value.Data; public override bool Equals(object? obj) => (obj is Entity other) && Equals(other); public override int GetHashCode() => Value.Data.GetHashCode(); public override string? ToString() => $"Entity(0x{Value.Data.Data:X})"; public static bool operator ==(Entity left, Entity right) => left.Equals(right); public static bool operator !=(Entity left, Entity right) => !left.Equals(right); public static implicit operator ecs_entity_t(Entity e) => e.Value; public static implicit operator Identifier(Entity e) => new(e.Value.Data); public static implicit operator ecs_id_t(Entity e) => e.Value.Data; }