From c994e9d7fe0401f85b920c41af9238fa9d7dd860 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Wed, 13 Nov 2019 20:08:11 -0800 Subject: [PATCH] add component reader methods that include entities --- encompass-cs/Engine.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 4c57a00..c2a0532 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -242,7 +242,15 @@ namespace Encompass } /// - /// Returns a Component with the specified Component Type and ID. If multiples exist, an arbitrary Component is returned. + /// Returns all of the components of the specified type including an Entity reference for each Component. + /// + protected IEnumerable<(Guid, TComponent, Entity)> ReadComponentsIncludingEntity() where TComponent : struct, IComponent + { + return ReadComponents().Select((tuple) => (tuple.Item1, tuple.Item2, GetEntityByComponentID(tuple.Item1))); + } + + /// + /// Returns a Component with the specified Component Type. If multiples exist, an arbitrary Component is returned. /// protected (Guid, TComponent) ReadComponent() where TComponent : struct, IComponent { @@ -266,6 +274,15 @@ namespace Encompass } } + /// + /// Returns a component of the specified type including its Entity reference. If multiples exist, an arbitrary Component is returned. + /// + protected (Guid, TComponent, Entity) ReadComponentIncludingEntity() where TComponent : struct, IComponent + { + var (id, component) = ReadComponent(); + return (id, component, GetEntityByComponentID(id)); + } + /// /// Returns true if any Component with the specified Component Type exists. ///