From a9032603ec24b0b6190343e3972d0c620ff93041 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 17 Aug 2022 15:29:38 -0700 Subject: [PATCH] add Filter.NthEntity --- src/ComponentDepot.cs | 5 +++++ src/Filter.cs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/ComponentDepot.cs b/src/ComponentDepot.cs index c6eca73..c9c84f1 100644 --- a/src/ComponentDepot.cs +++ b/src/ComponentDepot.cs @@ -185,6 +185,11 @@ namespace MoonTools.ECS } } + public Entity FilterNthEntity(Filter filter, int index) + { + return new Entity(filterSignatureToEntityIDs[filter.Signature][index]); + } + public Entity FilterRandomEntity(Filter filter) { var randomIndex = RandomGenerator.Next(FilterCount(filter)); diff --git a/src/Filter.cs b/src/Filter.cs index bf7fefa..b229728 100644 --- a/src/Filter.cs +++ b/src/Filter.cs @@ -20,5 +20,8 @@ namespace MoonTools.ECS public int Count => ComponentDepot.FilterCount(this); public bool Empty => Count == 0; + + // WARNING: this WILL crash if the index is out of range! + public Entity NthEntity(int index) => ComponentDepot.FilterNthEntity(this, index); } }