summaryrefslogtreecommitdiff
path: root/honey/ecs/ecs.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-09 12:24:28 -0500
committersanine-a <sanine.not@pm.me>2023-05-09 12:24:28 -0500
commit02247e743b83669e2d799111fc10a4772de66dfc (patch)
treef6b8e29897897f1af5b03bc6f57693624292bd21 /honey/ecs/ecs.lua
parent02389173aa65bb27379eb910a71a395e161c5b87 (diff)
add ecs.Accessor helper and node _child hierarchy
Diffstat (limited to 'honey/ecs/ecs.lua')
-rw-r--r--honey/ecs/ecs.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/honey/ecs/ecs.lua b/honey/ecs/ecs.lua
index b0409e4..301ed36 100644
--- a/honey/ecs/ecs.lua
+++ b/honey/ecs/ecs.lua
@@ -271,4 +271,29 @@ function SystemDb.removeSystem(self, id)
end
+--===== Access helper =====--
+
+
+function Accessor(db, id)
+ local tbl = {
+ __db = db,
+ __id = id,
+ }
+
+ setmetatable(tbl, {
+ __index=function(self, key)
+ return self.__db:getComponent(self.__id, key)
+ end,
+ __newindex=function(self, key, value)
+ self.__db:addComponent(self.__id, key, value)
+ end,
+ __tostring=function(self)
+ return string.format("Accessor<%s>", self.__id)
+ end,
+ })
+
+ return tbl
+end
+
+
return module