From 1123ef56622f77bf64f6aa0eae7bbe0348a3d7f9 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 6 Apr 2022 20:08:28 -0700 Subject: [PATCH] check for specific relation --- src/EntityComponentReader.cs | 5 +++++ src/RelationDepot.cs | 5 +++++ src/RelationStorage.cs | 6 ++++++ 3 files changed, 16 insertions(+) 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))