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(); } + protected bool Related(in Entity a, in Entity b) + { + return RelationDepot.Related(a.ID, b.ID); + } + protected IEnumerable RelatedToA(in Entity entity) { return RelationDepot.RelatedToA(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().All(); } + public bool Related(int idA, int idB) + { + return Lookup().Has(new Relation(idA, idB)); + } + public IEnumerable RelatedToA(int entityID) { return Lookup().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 RelatedToA(int entityID) { if (entitiesRelatedToA.ContainsKey(entityID))