using System; using System.Collections.Generic; namespace MoonTools.ECS { public abstract class EntityComponentReader { internal EntityStorage EntityStorage; internal ComponentDepot ComponentDepot; internal RelationDepot RelationDepot; protected FilterBuilder FilterBuilder => new FilterBuilder(ComponentDepot); internal void RegisterEntityStorage(EntityStorage entityStorage) { EntityStorage = entityStorage; } internal void RegisterComponentDepot(ComponentDepot componentDepot) { ComponentDepot = componentDepot; } internal void RegisterRelationDepot(RelationDepot relationDepot) { RelationDepot = relationDepot; } protected ReadOnlySpan ReadComponents() where TComponent : struct { return ComponentDepot.ReadComponents(); } protected bool Has(in Entity entity) where TComponent : struct { return ComponentDepot.Has(entity.ID); } protected bool Some() where TComponent : struct { return ComponentDepot.Some(); } protected ref readonly TComponent Get(in Entity entity) where TComponent : struct { return ref ComponentDepot.Get(entity.ID); } protected ref readonly TComponent GetSingleton() where TComponent : struct { return ref ComponentDepot.Get(); } protected Entity GetSingletonEntity() where TComponent : struct { return ComponentDepot.GetSingletonEntity(); } protected bool Exists(in Entity entity) { return EntityStorage.Exists(entity); } protected IEnumerable<(Entity, Entity, TRelationKind)> Relations() where TRelationKind : struct { return RelationDepot.Relations(); } protected bool Related(in Entity a, in Entity b) where TRelationKind : struct { return RelationDepot.Related(a.ID, b.ID); } protected IEnumerable<(Entity, TRelationKind)> RelatedToA(in Entity entity) where TRelationKind : struct { return RelationDepot.RelatedToA(entity.ID); } protected IEnumerable<(Entity, TRelationKind)> RelatedToB(in Entity entity) where TRelationKind : struct { return RelationDepot.RelatedToB(entity.ID); } } }