mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-06 22:27:53 -04:00
Removed .init
This commit is contained in:
parent
6ddb28ffbc
commit
39ec2106b7
6 changed files with 22 additions and 110 deletions
48
lib/init.lua
48
lib/init.lua
|
@ -2,8 +2,6 @@
|
|||
|
||||
local PATH = (...):gsub('%.init$', '')
|
||||
|
||||
local Type = require(PATH..".type")
|
||||
|
||||
local Concord = {
|
||||
_VERSION = "1.0",
|
||||
_DESCRIPTION = "A feature-complete ECS library",
|
||||
|
@ -33,46 +31,10 @@ local Concord = {
|
|||
]]
|
||||
}
|
||||
|
||||
--- Initializes the library with some optional settings
|
||||
-- @param settings Table of settings: {
|
||||
-- useEvents Flag to overwrite love.run and use events. Defaults to false
|
||||
-- }
|
||||
-- @return Concord
|
||||
function Concord.init(settings)
|
||||
Concord.entity = require(PATH..".entity")
|
||||
Concord.component = require(PATH..".component")
|
||||
Concord.system = require(PATH..".system")
|
||||
Concord.instance = require(PATH..".instance")
|
||||
Concord.assemblage = require(PATH..".assemblage")
|
||||
|
||||
if settings and settings.useEvents then
|
||||
Concord.instances = {}
|
||||
|
||||
Concord.addInstance = function(instance)
|
||||
if not Type.isInstance(instance) then
|
||||
error("bad argument #1 to 'Concord.addInstance' (Instance expected, got "..type(instance)..")", 2)
|
||||
end
|
||||
|
||||
table.insert(Concord.instances, instance)
|
||||
end
|
||||
|
||||
Concord.removeInstance = function(instance)
|
||||
if not Type.isInstance(instance) then
|
||||
error("bad argument #1 to 'Concord.addInstance' (Instance expected, got "..type(instance)..")", 2)
|
||||
end
|
||||
|
||||
for i, _instance in ipairs(Concord.instances) do
|
||||
if (instance == _instance) then
|
||||
table.remove(Concord.instances, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.run = require(PATH..".run")
|
||||
end
|
||||
|
||||
return Concord
|
||||
end
|
||||
Concord.entity = require(PATH..".entity")
|
||||
Concord.component = require(PATH..".component")
|
||||
Concord.system = require(PATH..".system")
|
||||
Concord.instance = require(PATH..".instance")
|
||||
Concord.assemblage = require(PATH..".assemblage")
|
||||
|
||||
return Concord
|
||||
|
|
55
lib/run.lua
55
lib/run.lua
|
@ -1,55 +0,0 @@
|
|||
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||
|
||||
local Concord = require(PATH)
|
||||
|
||||
return function()
|
||||
if love.math then
|
||||
love.math.setRandomSeed(os.time())
|
||||
love.timer.step()
|
||||
end
|
||||
|
||||
for _, instance in ipairs(Concord.instances) do
|
||||
instance:emit("load", arg)
|
||||
end
|
||||
|
||||
if love.timer then love.timer.step() end
|
||||
|
||||
local dt = 0
|
||||
|
||||
return function()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
for name, a, b, c, d, e, f in love.event.poll() do
|
||||
for _, instance in ipairs(Concord.instances) do
|
||||
instance:emit(name, a, b, c, d, e, f)
|
||||
end
|
||||
|
||||
if name == "quit" then
|
||||
return a or 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
dt = love.timer.getDelta()
|
||||
end
|
||||
|
||||
for _, instance in ipairs(Concord.instances) do
|
||||
instance:emit("update", dt)
|
||||
end
|
||||
|
||||
if love.graphics and love.graphics.isActive() then
|
||||
love.graphics.clear(love.graphics.getBackgroundColor())
|
||||
love.graphics.origin()
|
||||
|
||||
for _, instance in ipairs(Concord.instances) do
|
||||
instance:emit("draw")
|
||||
end
|
||||
|
||||
love.graphics.present()
|
||||
end
|
||||
|
||||
if love.timer then love.timer.sleep(0.001) end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,5 @@
|
|||
-- Type
|
||||
|
||||
local Type = {}
|
||||
|
||||
function Type.isComponent(t)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue