2021-08-21 12:45:49 +02:00
|
|
|
local ElementList = Object:extend()
|
|
|
|
|
|
|
|
function ElementList:initElements()
|
|
|
|
self.elements = {}
|
|
|
|
self.focusedElem = nil
|
2021-08-22 12:39:44 +02:00
|
|
|
self.nbrElement = 0
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:addElement(name, element)
|
2021-08-22 12:39:44 +02:00
|
|
|
self.nbrElement = self.nbrElement + 1
|
2021-08-21 12:45:49 +02:00
|
|
|
self.elements[name] = element
|
2021-08-22 12:39:44 +02:00
|
|
|
return self.nbrElement
|
2021-08-21 12:45:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:deleteElement(name)
|
|
|
|
self.elements[name] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function ElementList:getVisibleElement(topLayer)
|
|
|
|
local visibleList = {}
|
|
|
|
for _, element in ipairs(self.elements) do
|
|
|
|
if (element ~= nil) then
|
|
|
|
if (element:getVisibility() and ((element.depth) < 0 == topLayer)) then
|
|
|
|
table.insert(visibleList, element)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-08-22 12:39:44 +02:00
|
|
|
|
|
|
|
table.sort(visibleList, function (a, b)
|
|
|
|
if (a.depth == b.depth) then
|
|
|
|
return (a.creationId < b.creationId)
|
|
|
|
else
|
|
|
|
return (a.depth > b.depth)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-08-21 12:45:49 +02:00
|
|
|
return visibleList
|
|
|
|
end
|
|
|
|
|
|
|
|
return ElementList
|