sonic-radiance/sonic-radiance.love/birb/modules/gui/mixins/elements.lua
2021-08-22 13:02:52 +02:00

40 lines
No EOL
960 B
Lua

local ElementList = Object:extend()
function ElementList:initElements()
self.elements = {}
self.focusedElem = nil
self.nbrElement = 0
end
function ElementList:addElement(name, element)
self.nbrElement = self.nbrElement + 1
self.elements[name] = element
return self.nbrElement
end
function ElementList:deleteElement(name)
self.elements[name] = nil
end
function ElementList:getVisibleElement(topLayer)
local visibleList = {}
for _, element in pairs(self.elements) do
if (element ~= nil) then
if (element:getVisibility() and ((element.depth) < 0 == topLayer)) then
table.insert(visibleList, element)
end
end
end
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)
return visibleList
end
return ElementList