|
|
|
using System;
|
|
|
|
using static flecs_hub.flecs;
|
|
|
|
|
|
|
|
namespace gaemstone.ECS;
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Struct)]
|
|
|
|
public class EntityAttribute : Attribute, ICreateEntityAttribute
|
|
|
|
{
|
|
|
|
/// <summary> If specified, uses this path instead of the default name. </summary>
|
|
|
|
public string[]? Path { get; }
|
|
|
|
|
|
|
|
/// <summary> If true, the path will be absolute instead of relative. </summary>
|
|
|
|
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<Entity>
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|