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.
48 lines
2.4 KiB
48 lines
2.4 KiB
using static gaemstone.Flecs.Core; |
|
|
|
namespace gaemstone.ECS; |
|
|
|
public abstract class EntityBase<TReturn> |
|
{ |
|
public abstract Universe Universe { get; } |
|
|
|
public abstract TReturn Add(Identifier id); |
|
public abstract TReturn Remove(Identifier id); |
|
public abstract bool Has(Identifier id); |
|
|
|
public abstract T Get<T>(); |
|
public abstract T? MaybeGet<T>() where T : unmanaged; |
|
public abstract T? MaybeGet<T>(T _ = null!) where T : class; |
|
public abstract ref T GetMut<T>() where T : unmanaged; |
|
public abstract ref T GetRefOrNull<T>() where T : unmanaged; |
|
public abstract ref T GetRefOrThrow<T>() where T : unmanaged; |
|
public abstract void Modified<T>(); |
|
|
|
public abstract TReturn Set<T>(in T value) where T : unmanaged; |
|
public abstract TReturn Set<T>(T obj) where T : class; |
|
|
|
public TReturn Add(string symbol) => Add(Universe.LookupSymbolOrThrow(symbol)); |
|
public TReturn Add<T>() => Add(Universe.LookupOrThrow(typeof(T))); |
|
public TReturn Add(Entity relation, Entity target) => Add(Identifier.Pair(relation, target)); |
|
public TReturn Add<TRelation>(Entity target) => Add(Universe.LookupOrThrow<TRelation>(), target); |
|
public TReturn Add<TRelation, TTarget>() => Add(Universe.LookupOrThrow<TRelation>(), Universe.LookupOrThrow<TTarget>()); |
|
|
|
public TReturn Remove(string symbol) => Remove(Universe.LookupSymbolOrThrow(symbol)); |
|
public TReturn Remove<T>() => Remove(Universe.LookupOrThrow(typeof(T))); |
|
public TReturn Remove(Entity relation, Entity target) => Remove(Identifier.Pair(relation, target)); |
|
public TReturn Remove<TRelation>(Entity target) => Remove(Universe.LookupOrThrow<TRelation>(), target); |
|
public TReturn Remove<TRelation, TTarget>() => Remove(Universe.LookupOrThrow<TRelation>(), Universe.LookupOrThrow<TTarget>()); |
|
|
|
public bool Has(string symbol) => Has(Universe.LookupSymbolOrThrow(symbol)); |
|
public bool Has<T>() => Has(Universe.LookupOrThrow(typeof(T))); |
|
public bool Has(Entity relation, Entity target) => Has(Identifier.Pair(relation, target)); |
|
public bool Has<TRelation>(Entity target) => Has(Universe.LookupOrThrow<TRelation>(), target); |
|
public bool Has<TRelation, TTarget>() => Has(Universe.LookupOrThrow<TRelation>(), Universe.LookupOrThrow<TTarget>()); |
|
|
|
public TReturn ChildOf(Entity parent) => Add<ChildOf>(parent); |
|
public TReturn ChildOf<TParent>() => Add<ChildOf, TParent>(); |
|
|
|
public TReturn Disable() => Add<Disabled>(); |
|
public TReturn Enable() => Remove<Disabled>(); |
|
public bool IsDisabled => Has<Disabled>(); |
|
}
|
|
|