From da9dbb30b8ce0eb11877638b2c26f22321c6370b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:56:11 +0200 Subject: [PATCH] improvement: better element data parsing --- .../birb/modules/gui/screen.lua | 33 ++++++++++++++----- .../birb/structures/elementData.lua | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 sonic-radiance.love/birb/structures/elementData.lua diff --git a/sonic-radiance.love/birb/modules/gui/screen.lua b/sonic-radiance.love/birb/modules/gui/screen.lua index 9ecddf6..3a2c08e 100644 --- a/sonic-radiance.love/birb/modules/gui/screen.lua +++ b/sonic-radiance.love/birb/modules/gui/screen.lua @@ -6,6 +6,9 @@ GuiScreen:implement(ElementList) local TweenManager = require "birb.classes.time" +local elementDataStruct = require "birb.structures.elementData" + + function GuiScreen:new(name, controller) self.controller = controller or self:getGui() self.name = name @@ -69,16 +72,30 @@ end function GuiScreen:registerElements() local elementList = self:createElements() - for _, element in ipairs(elementList) do - if (element.is ~= nil) then - self:addElement(element.name, element) - element.screen = self + for _, rawElement in ipairs(elementList) do + if (rawElement.is ~= nil) then + self:addElement(rawElement.name, rawElement) + rawElement.screen = self else - self:addElement(element[1].name, element[1]) - if (element[2] == false) then - element[1].isVisible = false + local elemData = utils.table.parse(rawElement, elementDataStruct, 3) + local element = elemData.element + self:addElement(element.name, element) + if (elemData.delay > 0) then + element.isVisible = false + element:newSwitch(elemData.delay, {"isVisible"}) + print(elemData.delay) end - element[1].screen = self + if (elemData.depth ~= nil) then + element.depth = elemData.depth + end + print(element, element.name, elemData.depth, elemData.focus) + if (elemData.focus == true) then + element:getFocus() + end + if (elemData.keypress ~= nil) then + element:setKeyPressAction(elemData.keypress) + end + element.screen = self end end end diff --git a/sonic-radiance.love/birb/structures/elementData.lua b/sonic-radiance.love/birb/structures/elementData.lua new file mode 100644 index 0000000..63eff97 --- /dev/null +++ b/sonic-radiance.love/birb/structures/elementData.lua @@ -0,0 +1 @@ +return {"element", "delay", "depth", "focus", "keypress"} \ No newline at end of file