mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
Added named systems
This commit is contained in:
parent
038111d558
commit
d4efca976c
10 changed files with 176 additions and 92 deletions
45
main.lua
45
main.lua
|
@ -6,50 +6,63 @@ require(file)
|
||||||
]=]--
|
]=]--
|
||||||
|
|
||||||
local Concord = require("src")
|
local Concord = require("src")
|
||||||
local Component = require("src.component")
|
|
||||||
|
|
||||||
local test_comp_1 = Concord.component("test_comp_1", function(e, x, y)
|
local Component = require("src.component")
|
||||||
|
local Components = require("src.components")
|
||||||
|
|
||||||
|
local System = Concord.system
|
||||||
|
local Systems = Concord.systems
|
||||||
|
|
||||||
|
local Entity = Concord.entity
|
||||||
|
|
||||||
|
local World = Concord.world
|
||||||
|
|
||||||
|
Component("test_comp_1", function(e, x, y)
|
||||||
e.x = x
|
e.x = x
|
||||||
e.y = y
|
e.y = y
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local test_comp_2 = Concord.component("test_comp_2", function(e, a)
|
Component("test_comp_2", function(e, a)
|
||||||
e.a = a
|
e.a = a
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local test_comp_3 = Concord.component("test_comp_3", function(e, b)
|
Component("test_comp_3", function(e, b)
|
||||||
e.b = b
|
e.b = b
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local test_system = Concord.system({Component.test_comp_1})
|
local test_system = System("test_system", {Components.test_comp_1})
|
||||||
|
|
||||||
function onEntityAdded(e)
|
local function onEntityAdded(e) -- luacheck: ignore
|
||||||
print("Added")
|
print("Added")
|
||||||
end
|
end
|
||||||
|
|
||||||
function onEntityRemoved(e)
|
local function onEntityRemoved(e) -- luacheck: ignore
|
||||||
print("Removed")
|
print("Removed")
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_system:init()
|
function test_system:init()
|
||||||
self.pool.onEntityAdded = onEntityAdded
|
self.pool.onEntityAdded = onEntityAdded
|
||||||
self.pool.onEntityRemoved = onEntityRemoved
|
self.pool.onEntityRemoved = onEntityRemoved
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_system:update(dt)
|
function test_system:update(dt) -- luacheck: ignore
|
||||||
|
--print(#self.pool)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_system:update2(dt) -- luacheck: ignore
|
||||||
--print(#self.pool)
|
--print(#self.pool)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local world = World()
|
||||||
|
|
||||||
local world = Concord.world()
|
local entity = Entity()
|
||||||
|
entity:give(Components.test_comp_1, 100, 100)
|
||||||
local entity = Concord.entity()
|
|
||||||
entity:give(Component.test_comp_1, 100, 100)
|
|
||||||
|
|
||||||
world:addEntity(entity)
|
world:addEntity(entity)
|
||||||
|
|
||||||
world:addSystem(test_system(), "update")
|
world:addSystem(Systems.test_system, "update")
|
||||||
|
world:addSystem(Systems.test_system, "update", "update2")
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
world:flush()
|
world:flush()
|
||||||
|
@ -59,10 +72,10 @@ end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
if key == "q" then
|
if key == "q" then
|
||||||
entity:remove(Component.test_comp_1)
|
entity:remove(Components.test_comp_1)
|
||||||
end
|
end
|
||||||
if key == "w" then
|
if key == "w" then
|
||||||
entity:give(Component.test_comp_1)
|
entity:give(Components.test_comp_1)
|
||||||
end
|
end
|
||||||
if key == "e" then
|
if key == "e" then
|
||||||
world:removeEntity(entity)
|
world:removeEntity(entity)
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
--- Component
|
--- Component
|
||||||
|
|
||||||
|
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||||
|
|
||||||
|
local Components = require(PATH..".components")
|
||||||
|
|
||||||
local Component = {}
|
local Component = {}
|
||||||
Component.__index = Component
|
Component.__index = Component
|
||||||
|
|
||||||
|
@ -15,10 +19,6 @@ function Component.new(name, populate)
|
||||||
error("bad argument #2 to 'Component.new' (function/nil expected, got "..type(populate)..")", 2)
|
error("bad argument #2 to 'Component.new' (function/nil expected, got "..type(populate)..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (Component[name] ~= nil) then
|
|
||||||
error("bad argument #2 to 'Component.new' (Component with name '"..name.."' already exists", 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
local component = setmetatable({
|
local component = setmetatable({
|
||||||
__name = name,
|
__name = name,
|
||||||
__populate = populate,
|
__populate = populate,
|
||||||
|
@ -28,7 +28,7 @@ function Component.new(name, populate)
|
||||||
|
|
||||||
component.__mt = {__index = component}
|
component.__mt = {__index = component}
|
||||||
|
|
||||||
Component[name] = component
|
Components.register(name, component)
|
||||||
|
|
||||||
return component
|
return component
|
||||||
end
|
end
|
||||||
|
|
29
src/components.lua
Normal file
29
src/components.lua
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
-- Components
|
||||||
|
|
||||||
|
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||||
|
|
||||||
|
local Type = require(PATH..".type")
|
||||||
|
|
||||||
|
local Components = {}
|
||||||
|
|
||||||
|
function Components.register(name, component)
|
||||||
|
if (type(name) ~= "string") then
|
||||||
|
error("bad argument #1 to 'Components.register' (string expected, got "..type(name)..")", 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (not Type.isComponent(component)) then
|
||||||
|
error("bad argument #2 to 'Components.register' (component expected, got "..type(component)..")", 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (rawget(Components, name)) then
|
||||||
|
error("bad argument #2 to 'Components.register' (Component with name '"..name.."' is already registerd)", 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
Components[name] = component
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(Components, {
|
||||||
|
__index = function(_, name)
|
||||||
|
error("Attempt to index component '"..tostring(name).."' that does not exist / was not registered", 2)
|
||||||
|
end
|
||||||
|
})
|
|
@ -33,7 +33,9 @@ local Concord = {
|
||||||
|
|
||||||
Concord.entity = require(PATH..".entity")
|
Concord.entity = require(PATH..".entity")
|
||||||
Concord.component = require(PATH..".component")
|
Concord.component = require(PATH..".component")
|
||||||
|
Concord.components = require(PATH..".components")
|
||||||
Concord.system = require(PATH..".system")
|
Concord.system = require(PATH..".system")
|
||||||
|
Concord.systems = require(PATH..".systems")
|
||||||
Concord.world = require(PATH..".world")
|
Concord.world = require(PATH..".world")
|
||||||
Concord.assemblage = require(PATH..".assemblage")
|
Concord.assemblage = require(PATH..".assemblage")
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,8 @@ function List:remove(obj)
|
||||||
|
|
||||||
self[obj] = nil
|
self[obj] = nil
|
||||||
self.size = size - 1
|
self.size = size - 1
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets an object by numerical index.
|
--- Gets an object by numerical index.
|
||||||
|
|
|
@ -45,10 +45,10 @@ function Pool:remove(e)
|
||||||
self:onEntityRemoved(e)
|
self:onEntityRemoved(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Pool:onEntityAdded(e)
|
function Pool:onEntityAdded(e) -- luacheck: ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
function Pool:onEntityRemoved(e)
|
function Pool:onEntityRemoved(e) -- luacheck: ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(Pool, {
|
return setmetatable(Pool, {
|
||||||
|
|
|
@ -2,20 +2,21 @@
|
||||||
|
|
||||||
local PATH = (...):gsub('%.[^%.]+$', '')
|
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||||
|
|
||||||
local Pool = require(PATH..".pool")
|
local Systems = require(PATH..".systems")
|
||||||
|
local Pool = require(PATH..".pool")
|
||||||
|
|
||||||
local System = {}
|
local System = {}
|
||||||
System.mt = {
|
System.mt = {
|
||||||
__index = System,
|
__index = System,
|
||||||
__call = function(systemProto, ...)
|
__call = function(baseSystem, world)
|
||||||
local system = setmetatable({
|
local system = setmetatable({
|
||||||
__pools = {},
|
__pools = {},
|
||||||
__world = nil,
|
__world = world,
|
||||||
|
|
||||||
__isSystem = true,
|
__isSystem = true,
|
||||||
}, systemProto)
|
}, baseSystem)
|
||||||
|
|
||||||
for _, filter in pairs(systemProto.__filter) do
|
for _, filter in pairs(baseSystem.__filter) do
|
||||||
local pool = system:__buildPool(filter)
|
local pool = system:__buildPool(filter)
|
||||||
if not system[pool.name] then
|
if not system[pool.name] then
|
||||||
system[pool.name] = pool
|
system[pool.name] = pool
|
||||||
|
@ -25,7 +26,8 @@ System.mt = {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
system:init(...)
|
system:init(world)
|
||||||
|
|
||||||
return system
|
return system
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
@ -33,13 +35,21 @@ System.mt = {
|
||||||
--- Creates a new System prototype.
|
--- Creates a new System prototype.
|
||||||
-- @param ... Variable amounts of filters
|
-- @param ... Variable amounts of filters
|
||||||
-- @return A new System prototype
|
-- @return A new System prototype
|
||||||
function System.new(...)
|
function System.new(name, ...)
|
||||||
local systemProto = setmetatable({
|
if (type(name) ~= "string") then
|
||||||
|
error("bad argument #1 to 'System.new' (string expected, got "..type(name)..")", 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local baseSystem = setmetatable({
|
||||||
|
__name = name,
|
||||||
|
__isBaseSystem = true,
|
||||||
__filter = {...},
|
__filter = {...},
|
||||||
}, System.mt)
|
}, System.mt)
|
||||||
systemProto.__index = systemProto
|
baseSystem.__index = baseSystem
|
||||||
|
|
||||||
return systemProto
|
Systems.register(name, baseSystem)
|
||||||
|
|
||||||
|
return baseSystem
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Builds a Pool for the System.
|
--- Builds a Pool for the System.
|
||||||
|
@ -98,13 +108,8 @@ function System:getWorld()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Default callback for system initialization.
|
--- Default callback for system initialization.
|
||||||
-- @param ... Varags
|
|
||||||
function System:init(...) -- luacheck: ignore
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Default callback for when the System is added to an World.
|
|
||||||
-- @param world The World the System was added to
|
-- @param world The World the System was added to
|
||||||
function System:addedTo(world) -- luacheck: ignore
|
function System:init(world) -- luacheck: ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Default callback for when a System's callback is enabled.
|
-- Default callback for when a System's callback is enabled.
|
||||||
|
|
29
src/systems.lua
Normal file
29
src/systems.lua
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
-- Systems
|
||||||
|
|
||||||
|
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||||
|
|
||||||
|
local Type = require(PATH..".type")
|
||||||
|
|
||||||
|
local Systems = {}
|
||||||
|
|
||||||
|
function Systems.register(name, system)
|
||||||
|
if (type(name) ~= "string") then
|
||||||
|
error("bad argument #1 to 'Systems.register' (string expected, got "..type(name)..")", 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (not Type.isBaseSystem(system)) then
|
||||||
|
error("bad argument #2 to 'Systems.register' (baseSystem expected, got "..type(system)..")", 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (rawget(Systems, name)) then
|
||||||
|
error("bad argument #2 to 'Systems.register' (System with name '"..name.."' is already registerd)", 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
Systems[name] = system
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(Systems, {
|
||||||
|
__index = function(_, name)
|
||||||
|
error("Attempt to index system '"..tostring(name).."' that does not exist / was not registered", 2)
|
||||||
|
end
|
||||||
|
})
|
16
src/type.lua
16
src/type.lua
|
@ -3,23 +3,23 @@
|
||||||
local Type = {}
|
local Type = {}
|
||||||
|
|
||||||
function Type.isComponent(t)
|
function Type.isComponent(t)
|
||||||
return type(t) == "table" and t.__isComponent
|
return type(t) == "table" and t.__isComponent or false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Type.isEntity(t)
|
function Type.isEntity(t)
|
||||||
return type(t) == "table" and t.__isEntity
|
return type(t) == "table" and t.__isEntity or false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Type.isBaseSystem(t)
|
||||||
|
return type(t) == "table" and t.__isBaseSystem or false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Type.isSystem(t)
|
function Type.isSystem(t)
|
||||||
return type(t) == "table" and t.__isSystem
|
return type(t) == "table" and t.__isSystem or false
|
||||||
end
|
|
||||||
|
|
||||||
function Type.isContext(t)
|
|
||||||
return type(t) == "table" and t.__isContext
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Type.isAssemblage(t)
|
function Type.isAssemblage(t)
|
||||||
return type(t) == "table" and t.__isAssemblage
|
return type(t) == "table" and t.__isAssemblage or false
|
||||||
end
|
end
|
||||||
|
|
||||||
return Type
|
return Type
|
||||||
|
|
|
@ -14,11 +14,14 @@ function World.new()
|
||||||
local world = setmetatable({
|
local world = setmetatable({
|
||||||
entities = List(),
|
entities = List(),
|
||||||
systems = List(),
|
systems = List(),
|
||||||
|
|
||||||
events = {},
|
events = {},
|
||||||
|
|
||||||
__added = {},
|
__added = {},
|
||||||
__removed = {},
|
__removed = {},
|
||||||
|
|
||||||
|
__systemLookup = {},
|
||||||
|
|
||||||
__isWorld = true,
|
__isWorld = true,
|
||||||
}, World)
|
}, World)
|
||||||
|
|
||||||
|
@ -68,8 +71,8 @@ function World:flush()
|
||||||
e.__wasAdded = false
|
e.__wasAdded = false
|
||||||
e.__isDirty = false
|
e.__isDirty = false
|
||||||
|
|
||||||
for i = 1, self.systems.size do
|
for j = 1, self.systems.size do
|
||||||
self.systems:get(i):__evaluate(e)
|
self.systems:get(j):__evaluate(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
self:onEntityAdded(e)
|
self:onEntityAdded(e)
|
||||||
|
@ -79,16 +82,16 @@ function World:flush()
|
||||||
e.world = nil
|
e.world = nil
|
||||||
self.entities:remove(e)
|
self.entities:remove(e)
|
||||||
|
|
||||||
for i = 1, self.systems.size do
|
for j = 1, self.systems.size do
|
||||||
self.systems:get(i):__remove(e)
|
self.systems:get(j):__remove(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
e.__wasRemoved = false
|
e.__wasRemoved = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if e.__isDirty then
|
if e.__isDirty then
|
||||||
for i = 1, self.systems.size do
|
for j = 1, self.systems.size do
|
||||||
self.systems:get(i):__evaluate(e)
|
self.systems:get(j):__evaluate(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
e.__isDirty = false
|
e.__isDirty = false
|
||||||
|
@ -99,43 +102,46 @@ function World:flush()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Adds a System to the World.
|
--- Adds a System to the World.
|
||||||
-- @param system The System to add
|
-- @param baseSystem The BaseSystem of the system to add
|
||||||
-- @param eventName The Event to register to
|
-- @param callbackName The callbackName to register to
|
||||||
-- @param callback The function name to call. Defaults to eventName
|
-- @param callback The function name to call. Defaults to callbackName
|
||||||
-- @param enabled If the system is enabled. Defaults to true
|
-- @param enabled If the system is enabled. Defaults to true
|
||||||
-- @return self
|
-- @return self
|
||||||
function World:addSystem(system, eventName, callback, enabled)
|
function World:addSystem(baseSystem, callbackName, callback, enabled)
|
||||||
if not Type.isSystem(system) then
|
if not Type.isBaseSystem(baseSystem) then
|
||||||
error("bad argument #1 to 'World:addSystem' (System expected, got "..type(system)..")", 2)
|
error("bad argument #1 to 'World:addSystem' (baseSystem expected, got "..type(baseSystem)..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
if system.__World and system.__World ~= self then
|
local system = self.__systemLookup[baseSystem]
|
||||||
error("System already in World '" ..tostring(system.__World).."'")
|
if (not system) then
|
||||||
end
|
-- System was not created for this world yet, so we create it ourselves
|
||||||
|
|
||||||
|
print("Created system")
|
||||||
|
|
||||||
|
system = baseSystem(self)
|
||||||
|
|
||||||
|
self.__systemLookup[baseSystem] = system
|
||||||
|
|
||||||
if not self.systems:has(system) then
|
|
||||||
self.systems:add(system)
|
self.systems:add(system)
|
||||||
system.__World = self
|
|
||||||
|
|
||||||
system:addedTo(self)
|
|
||||||
|
|
||||||
for i = 1, self.entities.size do
|
|
||||||
system:__evaluate(self.entities:get(i))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if eventName then
|
-- Retroactively evaluate all entities for this system
|
||||||
self.events[eventName] = self.events[eventName] or {}
|
for i = 1, self.entities.size do
|
||||||
|
system:__evaluate(self.entities:get(i))
|
||||||
|
end
|
||||||
|
|
||||||
local i = #self.events[eventName] + 1
|
if callbackName then
|
||||||
self.events[eventName][i] = {
|
self.events[callbackName] = self.events[callbackName] or {}
|
||||||
|
|
||||||
|
local i = #self.events[callbackName] + 1
|
||||||
|
self.events[callbackName][i] = {
|
||||||
system = system,
|
system = system,
|
||||||
callback = callback or eventName,
|
callback = callback or callbackName,
|
||||||
enabled = enabled == nil or enabled,
|
enabled = enabled == nil or enabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
if enabled == nil or enabled then
|
if enabled == nil or enabled then
|
||||||
system:enabledCallback(callback or eventName)
|
system:enabledCallback(callback or callbackName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,15 +150,15 @@ end
|
||||||
|
|
||||||
--- Enables a System in the World.
|
--- Enables a System in the World.
|
||||||
-- @param system The System to enable
|
-- @param system The System to enable
|
||||||
-- @param eventName The Event it was registered to
|
-- @param callbackName The Event it was registered to
|
||||||
-- @param callback The callback it was registered with. Defaults to eventName
|
-- @param callback The callback it was registered with. Defaults to eventName
|
||||||
-- @return self
|
-- @return self
|
||||||
function World:enableSystem(system, eventName, callback)
|
function World:enableSystem(system, callbackName, callback)
|
||||||
if not Type.isSystem(system) then
|
if not Type.isSystem(system) then
|
||||||
error("bad argument #1 to 'World:enableSystem' (System expected, got "..type(system)..")", 2)
|
error("bad argument #1 to 'World:enableSystem' (System expected, got "..type(system)..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self:setSystem(system, eventName, callback, true)
|
return self:setSystem(system, callbackName, callback, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Disables a System in the World.
|
--- Disables a System in the World.
|
||||||
|
@ -160,12 +166,12 @@ end
|
||||||
-- @param eventName The Event it was registered to
|
-- @param eventName The Event it was registered to
|
||||||
-- @param callback The callback it was registered with. Defaults to eventName
|
-- @param callback The callback it was registered with. Defaults to eventName
|
||||||
-- @return self
|
-- @return self
|
||||||
function World:disableSystem(system, eventName, callback)
|
function World:disableSystem(system, callbackName, callback)
|
||||||
if not Type.isSystem(system) then
|
if not Type.isSystem(system) then
|
||||||
error("bad argument #1 to 'World:disableSystem' (System expected, got "..type(system)..")", 2)
|
error("bad argument #1 to 'World:disableSystem' (System expected, got "..type(system)..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self:setSystem(system, eventName, callback, false)
|
return self:setSystem(system, callbackName, callback, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sets a System 'enable' in the World.
|
--- Sets a System 'enable' in the World.
|
||||||
|
@ -174,15 +180,15 @@ end
|
||||||
-- @param callback The callback it was registered with. Defaults to eventName
|
-- @param callback The callback it was registered with. Defaults to eventName
|
||||||
-- @param enable The state to set it to
|
-- @param enable The state to set it to
|
||||||
-- @return self
|
-- @return self
|
||||||
function World:setSystem(system, eventName, callback, enable)
|
function World:setSystem(system, callbackName, callback, enable)
|
||||||
if not Type.isSystem(system) then
|
if not Type.isSystem(system) then
|
||||||
error("bad argument #1 to 'World:setSystem' (System expected, got "..type(system)..")", 2)
|
error("bad argument #1 to 'World:setSystem' (System expected, got "..type(system)..")", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
callback = callback or eventName
|
callback = callback or callbackName
|
||||||
|
|
||||||
if callback then
|
if callback then
|
||||||
local listeners = self.events[eventName]
|
local listeners = self.events[callbackName]
|
||||||
|
|
||||||
if listeners then
|
if listeners then
|
||||||
for i = 1, #listeners do
|
for i = 1, #listeners do
|
||||||
|
@ -210,12 +216,12 @@ end
|
||||||
-- @param eventName The Event that should be emitted
|
-- @param eventName The Event that should be emitted
|
||||||
-- @param ... Parameters passed to listeners
|
-- @param ... Parameters passed to listeners
|
||||||
-- @return self
|
-- @return self
|
||||||
function World:emit(eventName, ...)
|
function World:emit(callbackName, ...)
|
||||||
if not eventName or type(eventName) ~= "string" then
|
if not callbackName or type(callbackName) ~= "string" then
|
||||||
error("bad argument #1 to 'World:emit' (String expected, got "..type(eventName)..")")
|
error("bad argument #1 to 'World:emit' (String expected, got "..type(callbackName)..")")
|
||||||
end
|
end
|
||||||
|
|
||||||
local listeners = self.events[eventName]
|
local listeners = self.events[callbackName]
|
||||||
|
|
||||||
if listeners then
|
if listeners then
|
||||||
for i = 1, #listeners do
|
for i = 1, #listeners do
|
||||||
|
@ -234,11 +240,9 @@ end
|
||||||
-- @return self
|
-- @return self
|
||||||
function World:clear()
|
function World:clear()
|
||||||
for i = 1, self.entities.size do
|
for i = 1, self.entities.size do
|
||||||
self.entities:get(i):destroy()
|
self.removeEntity(self.entities:get(i))
|
||||||
end
|
end
|
||||||
|
|
||||||
self:flush()
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue