1
0
Fork 0
mirror of https://github.com/Reuh/ubiquitousse.git synced 2025-10-27 09:09:30 +00:00

Fix error if onRemove in subsystem call :remove again

This commit is contained in:
Étienne Fildadut 2021-04-13 01:55:29 +02:00
parent f607058753
commit 366bb63ed5

View file

@ -243,28 +243,32 @@ let system_mt = {
-- Returns all removed entities. -- Returns all removed entities.
-- Complexity: O(1) per system. -- Complexity: O(1) per system.
remove = :(e, ...) remove = :(e, ...)
if e ~= nil and @_previous[e] then if e ~= nil then
-- remove from subsystems if @_previous[e] then
for _, s in ipairs(@systems) do -- remove from subsystems
s:remove(e) for _, s in ipairs(@systems) do
end s:remove(e)
-- remove from linked list
let prev = @_previous[e]
if prev == true then
@_first = @_first[2]
if @_first then
@_previous[@_first[1]] = true
end
else
prev[2] = prev[2][2]
if prev[2] then
@_previous[prev[2][1]] = prev
end end
end end
-- notify removal if @_previous[e] then -- recheck in case it was removed already from a subsystem onRemove callback
@_previous[e] = nil -- remove from linked list
@entityCount -= 1 let prev = @_previous[e]
@onRemove(e[@name]) if prev == true then
@_first = @_first[2]
if @_first then
@_previous[@_first[1]] = true
end
else
prev[2] = prev[2][2]
if prev[2] then
@_previous[prev[2][1]] = prev
end
end
-- notify removal
@_previous[e] = nil
@entityCount -= 1
@onRemove(e[@name])
end
end end
if ... then if ... then
return e, @remove(...) return e, @remove(...)