check for specific relation

pull/2/head
cosmonaut 2022-04-06 20:08:28 -07:00
parent 0f4df1b948
commit 1123ef5662
3 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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))