diff --git a/src/entity.lua b/src/entity.lua index a6c6b29..14619cf 100644 --- a/src/entity.lua +++ b/src/entity.lua @@ -13,6 +13,8 @@ function Entity.new() local e = setmetatable({ world = nil, + __components = {}, + __isDirty = true, __wasAdded = false, __wasRemoved = false, @@ -23,15 +25,18 @@ function Entity.new() return e end -local function give(e, component, ...) - local comp = component:__initialize(...) - e[component] = comp +local function give(e, baseComponent, ...) + local component = baseComponent:__initialize(...) + + e[baseComponent] = component + e.__components[baseComponent] = component e.__isDirty = true end -local function remove(e, component) - e[component] = nil +local function remove(e, baseComponent) + e[baseComponent] = nil + e.__components[baseComponent] = nil e.__isDirty = true end @@ -119,6 +124,10 @@ function Entity:has(component) return self[component] ~= nil end +function Entity:getComponents() + return self.__components +end + return setmetatable(Entity, { __call = function(_, ...) return Entity.new(...)