From 5593b3bbfb9c55d95557327372e96aab0e878338 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 15 May 2023 03:51:53 +1000 Subject: [PATCH 1/2] Child layouts --- Basalt/plugins/xml.lua | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Basalt/plugins/xml.lua b/Basalt/plugins/xml.lua index db97a78..f829c80 100644 --- a/Basalt/plugins/xml.lua +++ b/Basalt/plugins/xml.lua @@ -207,10 +207,10 @@ return { end, untracked = function(getter) - local prevEffect = currentEffect + local parentEffect = currentEffect currentEffect = nil local value = getter() - currentEffect = prevEffect + currentEffect = parentEffect return value end, @@ -218,10 +218,10 @@ return { local effect = {dependencies = {}} local execute = function() clearEffectDependencies(effect) - local prevEffect = currentEffect + local parentEffect = currentEffect currentEffect = effect effectFn() - currentEffect = prevEffect + currentEffect = parentEffect end effect.execute = execute effect.execute() @@ -347,6 +347,25 @@ return { end end + local function insertChildLayout(self, layout, node, renderContext) + local props = {} + for _, prop in ipairs(node:properties()) do + props[prop.name] = prop.value + end + local updateFns = {} + for prop, expression in pairs(node:reactiveProperties()) do + updateFns[prop] = basalt.derived(function() + return load("return " .. expression, nil, "t", renderContext.env)() + end) + end + setmetatable(props, { + __index = function(_, k) + return updateFns[k]() + end + }) + self:loadLayout(layout.path, props) + end + local object = { setValuesByXMLData = function(self, data, renderContext) lastXMLReferences = {} @@ -358,8 +377,11 @@ return { for _, childNode in pairs(children) do local tagName = childNode.___name if (tagName ~= "animation") then + local layout = renderContext.env[tagName] local objectKey = tagName:gsub("^%l", string.upper) - if (_OBJECTS[objectKey] ~= nil) then + if (layout ~= nil) then + insertChildLayout(self, layout, childNode, renderContext) + elseif (_OBJECTS[objectKey] ~= nil) then local addFn = self["add" .. objectKey] addXMLObjectType(childNode, addFn, self, renderContext) end From ede6c87c88dcca4ae14aae9458d551bdcd103aa8 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 15 May 2023 03:55:39 +1000 Subject: [PATCH 2/2] OOps left this out --- Basalt/plugins/xml.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Basalt/plugins/xml.lua b/Basalt/plugins/xml.lua index f829c80..112900b 100644 --- a/Basalt/plugins/xml.lua +++ b/Basalt/plugins/xml.lua @@ -183,6 +183,12 @@ end return { basalt = function(basalt) local object = { + layout = function(path) + return { + path = path, + } + end, + reactive = function(initialValue) local value = initialValue local observerEffects = {}