From 371e3a188e190a9c8b53dc6eef02d4eea72db826 Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 13 Apr 2023 23:40:31 -0500 Subject: move message dispatching into ecs-systems.lua --- honey/ecs.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'honey/ecs.lua') diff --git a/honey/ecs.lua b/honey/ecs.lua index 69feb12..39f1c77 100644 --- a/honey/ecs.lua +++ b/honey/ecs.lua @@ -69,9 +69,22 @@ function EntityDb.addComponent(self, id, name, value) end +-- add multiple components at once, for convenience +function EntityDb.addComponents(self, id, components) + for name, value in pairs(components) do + self:addComponent(id, name, value) + end +end + + -- get all entities with a given component function EntityDb.queryComponent(self, name) - return self.components[name].data + local component = self.components[name] + if component then + return component.data + else + return {} + end end -- cgit v1.2.1