diff --git a/lib/instance.lua b/lib/instance.lua index e3f4656..451ef50 100644 --- a/lib/instance.lua +++ b/lib/instance.lua @@ -107,6 +107,8 @@ function Instance:addSystem(system, eventName, callback, enabled) if not self.systems:has(system) then self.systems:add(system) system.__instance = self + + system:addedTo(self) end if eventName then @@ -177,7 +179,14 @@ function Instance:setSystem(system, eventName, callback, enable) local listener = listeners[i] if listener.system == system and listener.callback == callback then + if enable and not listener.enabled then + system:enabledCallback(callback) + elseif not enable and listener.enabled then + system:disabledCallback(callback) + end + listener.enabled = enable + break end end diff --git a/lib/system.lua b/lib/system.lua index 0027332..04cf6a4 100644 --- a/lib/system.lua +++ b/lib/system.lua @@ -42,11 +42,6 @@ function System.new(...) return systemProto end ---- Default initialization function. --- @param ... Varags -function System:init(...) -end - --- Builds a Pool for the System. -- @param baseFilter The 'raw' Filter -- @return A new Pool @@ -140,6 +135,11 @@ function System:__has(e) return self.__all[e] and true end +--- Default callback for system initialization. +-- @param ... Varags +function System:init(...) +end + --- Default callback for adding an Entity. -- @param e The Entity that was added function System:entityAdded(e) @@ -162,6 +162,21 @@ end function System:entityRemovedFrom(e, pool) end +-- Default callback for when the System is added to an Instance. +-- @param instance The Instance the System was added to +function System:addedTo(instance) +end + +-- Default callback for when a System's callback is enabled. +-- @param callbackName The name of the callback that was enabled +function System:enabledCallback(callbackName) +end + +-- Default callback for when a System's callback is disabled. +-- @param callbackName The name of the callback that was disabled +function System:disabledCallback(callbackName) +end + return setmetatable(System, { __call = function(_, ...) return System.new(...) end, })