diff options
Diffstat (limited to 'honey/ecs/script.lua')
-rw-r--r-- | honey/ecs/script.lua | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/honey/ecs/script.lua b/honey/ecs/script.lua index 9ae7d72..46af4fa 100644 --- a/honey/ecs/script.lua +++ b/honey/ecs/script.lua @@ -1,3 +1,6 @@ +local ecs = require 'honey.ecs.ecs' +local node = require 'honey.ecs.node' + local module = {} setmetatable(module, {__index=_G}) setfenv(1, module) @@ -16,8 +19,8 @@ end --===== dispatch messages to handlers =====-- -dispatch = function(entities, msg, data) - local query = entities:queryComponent(msg) +dispatch = function(db, msg, data) + local query = db:queryComponent(msg) for id, handler in pairs(query) do local f = getFunction(handler) f(entities, id, data) @@ -26,19 +29,16 @@ end --===== script system =====-- -system = function(params) - return { - db=params.db, - update=function(self, dt) - local entities = self.db:queryComponent("script") - for id, script in pairs(entities) do - local f = getFunction(script) - f(self.db, id, dt) - end - end - } -end +local script = ecs.System("script", function(db, dt, params) + local entities = db:queryComponent("script") + for id, script in pairs(entities) do + local f = getFunction(script) + f(db, id, dt) + end +end) +script:addDependencies(node.system) +system = {script} return module |