diff --git a/src/gaemstone.ECS/EntityBase.cs b/src/gaemstone.ECS/EntityBase.cs index 52902f2..def9ce6 100644 --- a/src/gaemstone.ECS/EntityBase.cs +++ b/src/gaemstone.ECS/EntityBase.cs @@ -28,17 +28,17 @@ public abstract class EntityBase public bool Has() => Has(World.LookupByTypeOrThrow(), World.LookupByTypeOrThrow()); - public abstract T Get(Identifier id); public abstract T? GetOrNull(Identifier id) where T : unmanaged; public abstract T? GetOrNull(Identifier id, T _ = null!) where T : class; + public abstract T GetOrThrow(Identifier id); public abstract ref T GetMut(Identifier id) where T : unmanaged; public abstract ref T GetRefOrNull(Identifier id) where T : unmanaged; public abstract ref T GetRefOrThrow(Identifier id) where T : unmanaged; public abstract void Modified(Identifier id); - public T Get() => Get(World.LookupByTypeOrThrow()); public T? GetOrNull() where T : unmanaged => GetOrNull(World.LookupByTypeOrThrow()); public T? GetOrNull(T _ = null!) where T : class => GetOrNull(World.LookupByTypeOrThrow()); + public T GetOrThrow() => GetOrThrow(World.LookupByTypeOrThrow()); public ref T GetMut() where T : unmanaged => ref GetMut(World.LookupByTypeOrThrow()); public ref T GetRefOrNull() where T : unmanaged => ref GetRefOrNull(World.LookupByTypeOrThrow()); public ref T GetRefOrThrow() where T : unmanaged => ref GetRefOrThrow(World.LookupByTypeOrThrow()); diff --git a/src/gaemstone.ECS/EntityBuilder.cs b/src/gaemstone.ECS/EntityBuilder.cs index dd6e2cf..e00ef17 100644 --- a/src/gaemstone.ECS/EntityBuilder.cs +++ b/src/gaemstone.ECS/EntityBuilder.cs @@ -67,9 +67,9 @@ public class EntityBuilder => !id.IsWildcard ? _toAdd.Contains(id) : throw new NotSupportedException(); // TODO: Support wildcard. - public override T Get(Identifier id) => throw new NotSupportedException(); public override T? GetOrNull(Identifier id) => throw new NotSupportedException(); public override T? GetOrNull(Identifier id, T _ = null!) where T : class => throw new NotSupportedException(); + public override T GetOrThrow(Identifier id) => throw new NotSupportedException(); public override ref T GetMut(Identifier id) => throw new NotSupportedException(); public override ref T GetRefOrNull(Identifier id) => throw new NotSupportedException(); public override ref T GetRefOrThrow(Identifier id) => throw new NotSupportedException(); diff --git a/src/gaemstone.ECS/EntityRef.cs b/src/gaemstone.ECS/EntityRef.cs index 57687fd..ce688ae 100644 --- a/src/gaemstone.ECS/EntityRef.cs +++ b/src/gaemstone.ECS/EntityRef.cs @@ -74,14 +74,6 @@ public unsafe class EntityRef public override EntityRef Remove(Identifier id) { ecs_remove_id(World, this, id); return this; } public override bool Has(Identifier id) => ecs_has_id(World, this, id); - public override T Get(Identifier id) - { - var ptr = ecs_get_id(World, this, id); - if (ptr == null) throw new Exception($"Component {typeof(T)} not found on {this}"); - return typeof(T).IsValueType ? Unsafe.Read(ptr) - : (T)((GCHandle)Unsafe.Read(ptr)).Target!; - } - public override T? GetOrNull(Identifier id) { var ptr = ecs_get_id(World, this, id); @@ -95,6 +87,14 @@ public unsafe class EntityRef return (ptr != null) ? (T)((GCHandle)Unsafe.Read(ptr)).Target! : null; } + public override T GetOrThrow(Identifier id) + { + var ptr = ecs_get_id(World, this, id); + if (ptr == null) throw new Exception($"Component {typeof(T)} not found on {this}"); + return typeof(T).IsValueType ? Unsafe.Read(ptr) + : (T)((GCHandle)Unsafe.Read(ptr)).Target!; + } + public override ref T GetRefOrNull(Identifier id) { var @ref = ecs_ref_init_id(World, this, id);