mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 04:13:58 -04:00
Allow systems to be disabled
This commit is contained in:
parent
6eaf66308d
commit
04a35a117e
2 changed files with 36 additions and 6 deletions
|
@ -9,6 +9,8 @@ System.mt = {
|
|||
__index = System,
|
||||
__call = function(baseSystem, world)
|
||||
local system = setmetatable({
|
||||
__enabled = true,
|
||||
|
||||
__pools = {},
|
||||
__world = world,
|
||||
|
||||
|
@ -94,6 +96,32 @@ function System:clear()
|
|||
end
|
||||
end
|
||||
|
||||
function System:enable()
|
||||
self:setEnabled(true)
|
||||
end
|
||||
|
||||
function System:disable()
|
||||
self:setEnabled(false)
|
||||
end
|
||||
|
||||
function System:toggleEnable()
|
||||
self:setEnabled(not self.__enabled)
|
||||
end
|
||||
|
||||
function System:setEnabled(enable)
|
||||
if (not self.__enabled and enable) then
|
||||
self.__enabled = true
|
||||
self:onEnabledCallback()
|
||||
elseif (self.__enabled and not enable) then
|
||||
self.__enabled = false
|
||||
self:onDisabledCallback()
|
||||
end
|
||||
end
|
||||
|
||||
function System:isEnabled()
|
||||
return self.__enabled
|
||||
end
|
||||
|
||||
--- Returns the World the System is in.
|
||||
-- @return The world the system is in
|
||||
function System:getWorld()
|
||||
|
@ -107,16 +135,16 @@ 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) -- luacheck: ignore
|
||||
function System:onEnabledCallback(callbackName) -- luacheck: ignore
|
||||
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) -- luacheck: ignore
|
||||
function System:onDisabledCallback(callbackName) -- luacheck: ignore
|
||||
end
|
||||
|
||||
return setmetatable(System, {
|
||||
__call = function(_, ...)
|
||||
return System.new(...)
|
||||
end,
|
||||
})
|
||||
})
|
|
@ -129,7 +129,7 @@ local blacklistedSystemMethods = {
|
|||
|
||||
function World:addSystem(baseSystem)
|
||||
if (not Type.isBaseSystem(baseSystem)) then
|
||||
error("bad argument #"..i.." to 'World:addSystems' (baseSystem expected, got "..type(baseSystem)..")", 2)
|
||||
error("bad argument #1 to 'World:addSystems' (baseSystem expected, got "..type(baseSystem)..")", 2)
|
||||
end
|
||||
|
||||
-- TODO: Check if baseSystem was already added
|
||||
|
@ -203,9 +203,11 @@ function World:emit(callbackName, ...)
|
|||
for i = 1, #listeners do
|
||||
local listener = listeners[i]
|
||||
|
||||
self:__flush()
|
||||
if (listener.system.__enabled) then
|
||||
self:__flush()
|
||||
|
||||
listener.callback(listener.system, ...)
|
||||
listener.callback(listener.system, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue