Feature Request: Entity Queries
I find myself in need of the ability to query for and operate on more than one entity in systems sometimes. It would be nice tobe able to do something like:
local filter = tiny.requireAll("position", "otherComponent")
local entities = world.query(filter)
I understand that this library is considered feature complete, but this would be a handy feature!
See 2nd request in #13 and https://bakpakin.github.io/tiny-ecs/doc/#System_functions: this can be done by using a vanilla system (a non-processing one, meaning it won't iterate over entities) and its entities field : )
Something like
local mySystem = tiny.system()
mySystem.filter = tiny.requireAll("position", "otherComponent")
function mySystem:update(dt)
local entities = self.entities
-- operations on entities
end
or even without the update function
local mySystem = tiny.system()
mySystem.filter = tiny.requireAll("position", "otherComponent")
-- …
local filteredEntities = mySystem.entities
-- operations on entities
I know this is stale, but I would recommend to set up a system as above - this will be the most efficient. Otherwise, you could simply make a utility function to iterate through world.entities and collect entities you are looking for.