From dd0fcf2547ccfe5f6f9cb52fb1a72a0271f777f2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 22 Aug 2021 16:38:27 +0200 Subject: [PATCH] feat: add transformation from list --- sonic-radiance.love/birb/modules/gui/init.lua | 20 +++++++++++++++++++ sonic-radiance.love/birb/structures/tween.lua | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 sonic-radiance.love/birb/structures/tween.lua diff --git a/sonic-radiance.love/birb/modules/gui/init.lua b/sonic-radiance.love/birb/modules/gui/init.lua index ebccac2..a826238 100644 --- a/sonic-radiance.love/birb/modules/gui/init.lua +++ b/sonic-radiance.love/birb/modules/gui/init.lua @@ -28,6 +28,7 @@ local ScreenList = require "birb.modules.gui.mixins.screens" Gui:implement(ScreenList) Gui:implement(ElementList) +local TransformDataStruct = require "birb.structures.tween" function Gui:new(scene) self.scene = scene @@ -50,6 +51,25 @@ end -- TWEEN FUNCTIONS -- Handle tweening +function Gui:transform(data) + for _, rawTransform in ipairs(data) do + self:transformOne(rawTransform) + end +end + +function Gui:transformOne(rawTransform) + local struct = TransformDataStruct[rawTransform[2]] + assert(struct ~= nil, "Structure " .. rawTransform[1] .. " doesn't exists ") + local transform = utils.table.parse(rawTransform, struct, 0) + if transform.type == "tween" then + self:newTween(transform.name, transform.start, transform.duration, transform.target, transform.easing) + elseif transform.type == "movement" then + self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing) + elseif transform.type == "switch" then + self:newSwitch(transform.name, transform.start, transform.bools) + end +end + function Gui:newTween(element, start, duration, target, easing) self.elements[element]:newTween(start, duration, target, easing) end diff --git a/sonic-radiance.love/birb/structures/tween.lua b/sonic-radiance.love/birb/structures/tween.lua new file mode 100644 index 0000000..2b84b41 --- /dev/null +++ b/sonic-radiance.love/birb/structures/tween.lua @@ -0,0 +1,5 @@ +return { + tween = {"name", "type", "start", "duration", "target", "easing"}, + movement = {"name", "type", "start", "duration", "x", "y", "easing"}, + switch = {"name", "type", "start", "bools"}, +} \ No newline at end of file