mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
Fixed some error messages
This commit is contained in:
parent
d8621e4070
commit
78dc7ee937
4 changed files with 48 additions and 39 deletions
|
@ -158,37 +158,31 @@ local blacklistedSystemFunctions = {
|
|||
"onDisabled",
|
||||
}
|
||||
|
||||
--- Adds a System to the World.
|
||||
-- Callbacks are registered automatically
|
||||
-- Entities added before are added to the System retroactively
|
||||
-- @see World:emit
|
||||
-- @tparam System systemClass SystemClass of System to add
|
||||
-- @treturn World self
|
||||
function World:addSystem(systemClass)
|
||||
local tryAddSystem = function (world, systemClass)
|
||||
if (not Type.isSystemClass(systemClass)) then
|
||||
error("bad argument #1 to 'World:addSystems' (SystemClass expected, got "..type(systemClass)..")", 2)
|
||||
return false, "SystemClass expected, got "..type(systemClass)
|
||||
end
|
||||
|
||||
if (self.__systemLookup[systemClass]) then
|
||||
error("bad argument #1 to 'World:addSystems' (SystemClass was already added to World)", 2)
|
||||
if (world.__systemLookup[systemClass]) then
|
||||
return false, "SystemClass was already added to World"
|
||||
end
|
||||
|
||||
-- Create instance of system
|
||||
local system = systemClass(self)
|
||||
local system = systemClass(world)
|
||||
|
||||
self.__systemLookup[systemClass] = system
|
||||
self.__systems:add(system)
|
||||
world.__systemLookup[systemClass] = system
|
||||
world.__systems:add(system)
|
||||
|
||||
for callbackName, callback in pairs(systemClass) do
|
||||
-- Skip callback if its blacklisted
|
||||
if (not blacklistedSystemFunctions[callbackName]) then
|
||||
-- Make container for all listeners of the callback if it does not exist yet
|
||||
if (not self.__events[callbackName]) then
|
||||
self.__events[callbackName] = {}
|
||||
if (not world.__events[callbackName]) then
|
||||
world.__events[callbackName] = {}
|
||||
end
|
||||
|
||||
-- Add callback to listeners
|
||||
local listeners = self.__events[callbackName]
|
||||
local listeners = world.__events[callbackName]
|
||||
listeners[#listeners + 1] = {
|
||||
system = system,
|
||||
callback = callback,
|
||||
|
@ -197,8 +191,24 @@ function World:addSystem(systemClass)
|
|||
end
|
||||
|
||||
-- Evaluate all existing entities
|
||||
for j = 1, self.__entities.size do
|
||||
system:__evaluate(self.__entities[j])
|
||||
for j = 1, world.__entities.size do
|
||||
system:__evaluate(world.__entities[j])
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Adds a System to the World.
|
||||
-- Callbacks are registered automatically
|
||||
-- Entities added before are added to the System retroactively
|
||||
-- @see World:emit
|
||||
-- @tparam System systemClass SystemClass of System to add
|
||||
-- @treturn World self
|
||||
function World:addSystem(systemClass)
|
||||
local ok, err = tryAddSystem(self, systemClass)
|
||||
|
||||
if not ok then
|
||||
error("bad argument #1 to 'World:addSystem' ("..err..")", 2)
|
||||
end
|
||||
|
||||
return self
|
||||
|
@ -214,7 +224,10 @@ function World:addSystems(...)
|
|||
for i = 1, select("#", ...) do
|
||||
local systemClass = select(i, ...)
|
||||
|
||||
self:addSystem(systemClass)
|
||||
local ok, err = tryAddSystem(self, systemClass)
|
||||
if not ok then
|
||||
error("bad argument #"..i.." to 'World:addSystems' ("..err..")", 2)
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue