Allow Entity.new to take a world

This commit is contained in:
Tjakka5 2020-01-03 21:39:40 +01:00
parent fea5fc7223
commit ce32d16b8d
2 changed files with 10 additions and 4 deletions

View file

@ -70,11 +70,9 @@ end
local world = World()
local entity = Entity()
local entity = Entity(world)
entity:give(test_comp_1, 100, 100)
world:addEntity(entity)
world:addSystem(test_system_1, "test")
world:addSystem(test_system_2, "test")

View file

@ -9,7 +9,11 @@ Entity.__index = Entity
--- Creates and initializes 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({
__world = nil,
__components = {},
@ -17,6 +21,10 @@ function Entity.new()
__isEntity = true,
}, Entity)
if (world) then
world:addEntity(e)
end
return e
end