From 0d96ebc90c9740e7e66a70aa11168b11f49d220b Mon Sep 17 00:00:00 2001 From: sanine-a Date: Fri, 12 May 2023 14:10:48 -0500 Subject: run working program with refactored code --- honey/ecs/script.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'honey/ecs/script.lua') 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 -- cgit v1.2.1