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.
38 lines
1.4 KiB
38 lines
1.4 KiB
using System; |
|
using gaemstone.Utility; |
|
using static flecs_hub.flecs; |
|
|
|
namespace gaemstone.ECS; |
|
|
|
public unsafe partial class World |
|
{ |
|
public EntityRef? LookupAlive(Entity value) |
|
=> EntityRef.CreateOrNull(this, new(ecs_get_alive(this, value))); |
|
public EntityRef LookupAliveOrThrow(Entity entity) |
|
=> LookupAlive(entity) ?? throw new EntityNotFoundException( |
|
$"Entity {entity} is not alive"); |
|
|
|
// TODO: Simplify method names? |
|
public EntityRef? LookupByPath(EntityPath path) |
|
=> LookupByPath(default, path); |
|
public EntityRef? LookupByPath(Entity parent, EntityPath path) |
|
=> EntityRef.CreateOrNull(this, EntityPath.Lookup(this, parent, path, false)); |
|
public EntityRef LookupByPathOrThrow(EntityPath path) |
|
=> LookupByPathOrThrow(default, path); |
|
public EntityRef LookupByPathOrThrow(Entity parent, EntityPath path) |
|
=> new(this, EntityPath.Lookup(this, parent, path, true)); |
|
|
|
// TODO: Provide overload that uses a UTF-8 byte span? |
|
public EntityRef? LookupBySymbol(string symbol) |
|
{ |
|
using var alloc = TempAllocator.Use(); |
|
var entity = ecs_lookup_symbol(this, alloc.AllocateCString(symbol), false); |
|
return EntityRef.CreateOrNull(this, new(entity)); |
|
} |
|
public EntityRef LookupBySymbolOrThrow(string symbol) |
|
=> LookupBySymbol(symbol) ?? throw new EntityNotFoundException( |
|
$"Entity with symbol '{symbol}' not found"); |
|
} |
|
|
|
public class EntityNotFoundException : Exception |
|
{ public EntityNotFoundException(string message) : base(message) { } }
|
|
|