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