Added callbacks for systems

This commit is contained in:
Justin van der Leij 2018-07-30 13:32:48 +02:00
parent 30a3b38fe1
commit 940217af40
2 changed files with 29 additions and 5 deletions

View file

@ -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

View file

@ -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,
})