mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
Allow Entity.new to take a world
This commit is contained in:
parent
fea5fc7223
commit
ce32d16b8d
2 changed files with 10 additions and 4 deletions
4
main.lua
4
main.lua
|
@ -70,11 +70,9 @@ end
|
||||||
|
|
||||||
local world = World()
|
local world = World()
|
||||||
|
|
||||||
local entity = Entity()
|
local entity = Entity(world)
|
||||||
entity:give(test_comp_1, 100, 100)
|
entity:give(test_comp_1, 100, 100)
|
||||||
|
|
||||||
world:addEntity(entity)
|
|
||||||
|
|
||||||
world:addSystem(test_system_1, "test")
|
world:addSystem(test_system_1, "test")
|
||||||
world:addSystem(test_system_2, "test")
|
world:addSystem(test_system_2, "test")
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,11 @@ Entity.__index = Entity
|
||||||
|
|
||||||
--- Creates and initializes a new Entity.
|
--- Creates and initializes a new Entity.
|
||||||
-- @return A new Entity
|
-- @return A new Entity
|
||||||
function Entity.new()
|
function Entity.new(world)
|
||||||
|
if (world ~= nil and not Type.isWorld(world)) then
|
||||||
|
error("bad argument #1 to 'Entity.new' (world/nil expected, got "..type(world)..")", 2)
|
||||||
|
end
|
||||||
|
|
||||||
local e = setmetatable({
|
local e = setmetatable({
|
||||||
__world = nil,
|
__world = nil,
|
||||||
__components = {},
|
__components = {},
|
||||||
|
@ -17,6 +21,10 @@ function Entity.new()
|
||||||
__isEntity = true,
|
__isEntity = true,
|
||||||
}, Entity)
|
}, Entity)
|
||||||
|
|
||||||
|
if (world) then
|
||||||
|
world:addEntity(e)
|
||||||
|
end
|
||||||
|
|
||||||
return e
|
return e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue