mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
Add Entity:getComponents
This commit is contained in:
parent
073aadf74b
commit
bb508ee947
1 changed files with 14 additions and 5 deletions
|
@ -13,6 +13,8 @@ function Entity.new()
|
||||||
local e = setmetatable({
|
local e = setmetatable({
|
||||||
world = nil,
|
world = nil,
|
||||||
|
|
||||||
|
__components = {},
|
||||||
|
|
||||||
__isDirty = true,
|
__isDirty = true,
|
||||||
__wasAdded = false,
|
__wasAdded = false,
|
||||||
__wasRemoved = false,
|
__wasRemoved = false,
|
||||||
|
@ -23,15 +25,18 @@ function Entity.new()
|
||||||
return e
|
return e
|
||||||
end
|
end
|
||||||
|
|
||||||
local function give(e, component, ...)
|
local function give(e, baseComponent, ...)
|
||||||
local comp = component:__initialize(...)
|
local component = baseComponent:__initialize(...)
|
||||||
e[component] = comp
|
|
||||||
|
e[baseComponent] = component
|
||||||
|
e.__components[baseComponent] = component
|
||||||
|
|
||||||
e.__isDirty = true
|
e.__isDirty = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function remove(e, component)
|
local function remove(e, baseComponent)
|
||||||
e[component] = nil
|
e[baseComponent] = nil
|
||||||
|
e.__components[baseComponent] = nil
|
||||||
|
|
||||||
e.__isDirty = true
|
e.__isDirty = true
|
||||||
end
|
end
|
||||||
|
@ -119,6 +124,10 @@ function Entity:has(component)
|
||||||
return self[component] ~= nil
|
return self[component] ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Entity:getComponents()
|
||||||
|
return self.__components
|
||||||
|
end
|
||||||
|
|
||||||
return setmetatable(Entity, {
|
return setmetatable(Entity, {
|
||||||
__call = function(_, ...)
|
__call = function(_, ...)
|
||||||
return Entity.new(...)
|
return Entity.new(...)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue