diff --git a/src/EntityComponentReader.cs b/src/EntityComponentReader.cs index 2e3d981..7d77511 100644 --- a/src/EntityComponentReader.cs +++ b/src/EntityComponentReader.cs @@ -62,6 +62,11 @@ public abstract class EntityComponentReader return RelationDepot.Relations<TRelationKind>(); } + protected bool Related<TRelationKind>(in Entity a, in Entity b) + { + return RelationDepot.Related<TRelationKind>(a.ID, b.ID); + } + protected IEnumerable<Entity> RelatedToA<TRelationKind>(in Entity entity) { return RelationDepot.RelatedToA<TRelationKind>(entity.ID); diff --git a/src/RelationDepot.cs b/src/RelationDepot.cs index a293864..49fe7ac 100644 --- a/src/RelationDepot.cs +++ b/src/RelationDepot.cs @@ -37,6 +37,11 @@ namespace MoonTools.ECS return Lookup<TRelationKind>().All(); } + public bool Related<TRelationKind>(int idA, int idB) + { + return Lookup<TRelationKind>().Has(new Relation(idA, idB)); + } + public IEnumerable<Entity> RelatedToA<TRelationKind>(int entityID) { return Lookup<TRelationKind>().RelatedToA(entityID); diff --git a/src/RelationStorage.cs b/src/RelationStorage.cs index 9df0a35..3b1db1f 100644 --- a/src/RelationStorage.cs +++ b/src/RelationStorage.cs @@ -18,6 +18,7 @@ namespace MoonTools.ECS public void Add(Relation relation) { if (relations.Contains(relation)) { return; } + var idA = relation.A.ID; var idB = relation.B.ID; @@ -36,6 +37,11 @@ namespace MoonTools.ECS relations.Add(relation); } + public bool Has(Relation relation) + { + return relations.Contains(relation); + } + public IEnumerable<Entity> RelatedToA(int entityID) { if (entitiesRelatedToA.ContainsKey(entityID))