mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 04:13:58 -04:00
Add Component:removed() callback
Fixes #37 I also added a reference to the Entity inside the Component which will help with #38
This commit is contained in:
parent
50249d5ad3
commit
c4594da19d
2 changed files with 29 additions and 10 deletions
|
@ -35,17 +35,28 @@ function Entity.new(world)
|
|||
end
|
||||
|
||||
local function give(e, name, componentClass, ...)
|
||||
local component = componentClass:__initialize(...)
|
||||
local component = componentClass:__initialize(e, ...)
|
||||
local hadComponent = not not e[name]
|
||||
|
||||
if hadComponent then
|
||||
e[name]:removed()
|
||||
end
|
||||
|
||||
e[name] = component
|
||||
|
||||
e:__dirty()
|
||||
if not hadComponent then
|
||||
e:__dirty()
|
||||
end
|
||||
end
|
||||
|
||||
local function remove(e, name)
|
||||
e[name] = nil
|
||||
if e[name] then
|
||||
e[name]:removed()
|
||||
|
||||
e:__dirty()
|
||||
e[name] = nil
|
||||
|
||||
e:__dirty()
|
||||
end
|
||||
end
|
||||
|
||||
--- Gives an Entity a Component.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue