|
|
|
@ -19,7 +19,7 @@ public unsafe readonly partial struct Entity<TContext> |
|
|
|
|
public bool IsSome => Value.IsSome; |
|
|
|
|
|
|
|
|
|
public bool IsValid => EntityAccess.IsValid(World, this); |
|
|
|
|
public bool IsAlive => EntityAccess.IsAlive(World, this); |
|
|
|
|
public bool IsAlive => IsSome && EntityAccess.IsAlive(World, this); |
|
|
|
|
|
|
|
|
|
public string? Name { get => EntityAccess.GetName(World, this); set => EntityAccess.SetName(World, this, value); } |
|
|
|
|
public string? Symbol { get => EntityAccess.GetSymbol(World, this); set => EntityAccess.SetSymbol(World, this, value); } |
|
|
|
@ -39,9 +39,17 @@ public unsafe readonly partial struct Entity<TContext> |
|
|
|
|
public static Entity<TContext> GetOrInvalid(World<TContext> world, Entity value) |
|
|
|
|
=> new(world, value); |
|
|
|
|
public static Entity<TContext>? GetOrNull(World<TContext> world, Entity value) |
|
|
|
|
=> ecs_is_valid(world, value) ? new(world, value) : null; |
|
|
|
|
=> new Entity<TContext>(world, value).ValidOrNull(); |
|
|
|
|
public static Entity<TContext> GetOrThrow(World<TContext> world, Entity value) |
|
|
|
|
=> ecs_is_valid(world, value) ? new(world, value) : throw new InvalidOperationException($"The entity {value} is not valid"); |
|
|
|
|
=> new Entity<TContext>(world, value).ValidOrThrow(); |
|
|
|
|
|
|
|
|
|
public Entity<TContext>? ValidOrNull() => IsValid ? this : null; |
|
|
|
|
public Entity<TContext> ValidOrThrow() => IsValid ? this |
|
|
|
|
: throw new InvalidOperationException($"The entity {this} is not valid"); |
|
|
|
|
|
|
|
|
|
public Entity<TContext>? AliveOrNull() => IsAlive ? this : null; |
|
|
|
|
public Entity<TContext> AliveOrThrow() => IsAlive ? this |
|
|
|
|
: throw new InvalidOperationException($"The entity {this} is not alive"); |
|
|
|
|
|
|
|
|
|
public void Delete() |
|
|
|
|
=> ecs_delete(World, this); |
|
|
|
@ -50,7 +58,8 @@ public unsafe readonly partial struct Entity<TContext> |
|
|
|
|
public Entity<TContext> CreateLookup<T>() |
|
|
|
|
{ |
|
|
|
|
ref var lookup = ref Lookup<TContext>.Entity<T>.Value; |
|
|
|
|
if (lookup.IsSome) throw new InvalidOperationException( |
|
|
|
|
if (lookup == this) { /* Don't throw if lookup already has the same entity set. */ } |
|
|
|
|
else if (lookup.IsSome) throw new InvalidOperationException( |
|
|
|
|
$"The lookup for type {typeof(T)} in context {typeof(TContext)} is already in use by {lookup}"); |
|
|
|
|
lookup = this; |
|
|
|
|
return this; |
|
|
|
|