mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 09:09:30 +00:00
Keep metatables in ecs.default copy
This commit is contained in:
parent
d9eba04966
commit
ef413838d4
1 changed files with 13 additions and 5 deletions
18
ecs/ecs.can
18
ecs/ecs.can
|
|
@ -70,15 +70,22 @@ let nextEntity = (s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Recursively copy content of a into b if it isn't already present. No cycle detection.
|
--- Recursively copy content of a into b if it isn't already present.
|
||||||
let copy = (a, b)
|
-- Don't copy keys, will preserve metatable but not copy them.
|
||||||
|
let copy = (a, b, cache={})
|
||||||
for k, v in pairs(a) do
|
for k, v in pairs(a) do
|
||||||
if type(v) == "table" then
|
if type(v) == "table" then
|
||||||
if b[k] == nil then
|
if b[k] == nil then
|
||||||
b[k] = {}
|
if cache[v] then
|
||||||
copy(v, b[k])
|
b[k] = cache[v]
|
||||||
|
else
|
||||||
|
cache[v] = {}
|
||||||
|
b[k] = cache[v]
|
||||||
|
copy(v, b[k], cache)
|
||||||
|
setmetatable(b[k], getmetatable(v))
|
||||||
|
end
|
||||||
elseif b[k] == "table" then
|
elseif b[k] == "table" then
|
||||||
copy(v, b[k])
|
copy(v, b[k], cache)
|
||||||
end
|
end
|
||||||
elseif b[k] == nil then
|
elseif b[k] == nil then
|
||||||
b[k] = v
|
b[k] = v
|
||||||
|
|
@ -132,6 +139,7 @@ let system_mt = {
|
||||||
visible = true,
|
visible = true,
|
||||||
|
|
||||||
--- Defaults value to put into the entities's system table when they are added. Will recursively fill missing values.
|
--- Defaults value to put into the entities's system table when they are added. Will recursively fill missing values.
|
||||||
|
-- Metatables will be preserved during the copy but not copied themselves.
|
||||||
--
|
--
|
||||||
-- When an entity is added to a system, a `.entity` field is always set in the system table, referring to the full entity table.
|
-- When an entity is added to a system, a `.entity` field is always set in the system table, referring to the full entity table.
|
||||||
--
|
--
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue