mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
First past at implementing init.lua support
This commit is contained in:
@@ -1,5 +1,27 @@
|
|||||||
local Reconciler = {}
|
local Reconciler = {}
|
||||||
|
|
||||||
|
local function isInit(item, itemFileName)
|
||||||
|
if item.type == "dir" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return not not itemFileName:find("^init%.")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function findInit(item)
|
||||||
|
if item.type ~= "dir" then
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
for childFileName, childItem in pairs(item.children) do
|
||||||
|
if isInit(childItem, childFileName) then
|
||||||
|
return childItem, childFileName
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
local function itemToName(item, fileName)
|
local function itemToName(item, fileName)
|
||||||
if item and item.type == "dir" then
|
if item and item.type == "dir" then
|
||||||
return fileName, "Folder"
|
return fileName, "Folder"
|
||||||
@@ -30,11 +52,19 @@ end
|
|||||||
|
|
||||||
function Reconciler._reifyShallow(item, fileName)
|
function Reconciler._reifyShallow(item, fileName)
|
||||||
if item.type == "dir" then
|
if item.type == "dir" then
|
||||||
-- TODO: handle init
|
local initItem, initFileName = findInit(item)
|
||||||
|
|
||||||
|
if initItem then
|
||||||
|
local rbx = Reconciler._reify(initItem, initFileName)
|
||||||
|
rbx.Name = fileName
|
||||||
|
|
||||||
|
return rbx
|
||||||
|
else
|
||||||
local rbx = Instance.new("Folder")
|
local rbx = Instance.new("Folder")
|
||||||
rbx.Name = fileName
|
rbx.Name = fileName
|
||||||
|
|
||||||
return rbx
|
return rbx
|
||||||
|
end
|
||||||
elseif item.type == "file" then
|
elseif item.type == "file" then
|
||||||
local objectName, className = itemToName(item, fileName)
|
local objectName, className = itemToName(item, fileName)
|
||||||
|
|
||||||
@@ -49,22 +79,24 @@ function Reconciler._reifyShallow(item, fileName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Reconciler._reify(item, fileName)
|
function Reconciler._reify(item, fileName, parent)
|
||||||
local rbx = Reconciler._reifyShallow(item, fileName)
|
local rbx = Reconciler._reifyShallow(item, fileName)
|
||||||
|
|
||||||
if item.type == "dir" then
|
if item.type == "dir" then
|
||||||
for childName, child in pairs(item.children) do
|
for childFileName, childItem in pairs(item.children) do
|
||||||
local childRbx = Reconciler._reify(child, childName)
|
if not isInit(childItem, childFileName) then
|
||||||
|
local childRbx = Reconciler._reify(childItem, childFileName)
|
||||||
childRbx.Parent = rbx
|
childRbx.Parent = rbx
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO: handle init
|
rbx.Parent = parent
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return rbx
|
return rbx
|
||||||
end
|
end
|
||||||
|
|
||||||
function Reconciler.reconcile(rbx, item, fileName)
|
function Reconciler.reconcile(rbx, item, fileName, parent)
|
||||||
-- Item was deleted!
|
-- Item was deleted!
|
||||||
if not item then
|
if not item then
|
||||||
if rbx then
|
if rbx then
|
||||||
@@ -74,26 +106,38 @@ function Reconciler.reconcile(rbx, item, fileName)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Item was created!
|
if item.type == "dir" then
|
||||||
|
-- Folder was created!
|
||||||
if not rbx then
|
if not rbx then
|
||||||
return Reconciler._reify(item, fileName)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
if item.type == "dir" then
|
local initItem, initFileName = findInit(item)
|
||||||
-- TODO: handle init
|
|
||||||
|
|
||||||
|
if initItem then
|
||||||
|
local _, initClassName = itemToName(initItem, initFileName)
|
||||||
|
|
||||||
|
if rbx.ClassName == initClassName then
|
||||||
|
setValues(rbx, initItem, initFileName)
|
||||||
|
else
|
||||||
|
return Reconciler._reify(item, fileName, parent)
|
||||||
|
end
|
||||||
|
else
|
||||||
if rbx.ClassName ~= "Folder" then
|
if rbx.ClassName ~= "Folder" then
|
||||||
return Reconciler._reify(item, fileName)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local visitedChildren = {}
|
local visitedChildren = {}
|
||||||
|
|
||||||
for childFileName, childItem in pairs(item.children) do
|
for childFileName, childItem in pairs(item.children) do
|
||||||
|
if not isInit(childItem, childFileName) then
|
||||||
local childName = itemToName(childItem, childFileName)
|
local childName = itemToName(childItem, childFileName)
|
||||||
|
|
||||||
visitedChildren[childName] = true
|
visitedChildren[childName] = true
|
||||||
|
|
||||||
Reconciler.reconcile(rbx:FindFirstChild(childName), childItem, childFileName)
|
Reconciler.reconcile(rbx:FindFirstChild(childName), childItem, childFileName, rbx)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, childRbx in ipairs(rbx:GetChildren()) do
|
for _, childRbx in ipairs(rbx:GetChildren()) do
|
||||||
@@ -105,10 +149,18 @@ function Reconciler.reconcile(rbx, item, fileName)
|
|||||||
|
|
||||||
return rbx
|
return rbx
|
||||||
elseif item.type == "file" then
|
elseif item.type == "file" then
|
||||||
|
if isInit(item, fileName) then
|
||||||
|
-- TODO: usurp parent
|
||||||
|
end
|
||||||
|
|
||||||
|
if not rbx then
|
||||||
|
return Reconciler._reify(item, fileName, parent)
|
||||||
|
end
|
||||||
|
|
||||||
local _, className = itemToName(item, fileName)
|
local _, className = itemToName(item, fileName)
|
||||||
|
|
||||||
if rbx.ClassName ~= className then
|
if rbx.ClassName ~= className then
|
||||||
return Reconciler._reify(item, fileName)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
setValues(rbx, item, fileName)
|
setValues(rbx, item, fileName)
|
||||||
@@ -139,7 +191,7 @@ function Reconciler.reconcileRoute(route, item)
|
|||||||
|
|
||||||
local name = itemToName(item, fileName)
|
local name = itemToName(item, fileName)
|
||||||
local rbx = location:FindFirstChild(name)
|
local rbx = location:FindFirstChild(name)
|
||||||
local newRbx = Reconciler.reconcile(rbx, item, fileName)
|
local newRbx = Reconciler.reconcile(rbx, item, fileName, location)
|
||||||
|
|
||||||
if newRbx ~= rbx then
|
if newRbx ~= rbx then
|
||||||
if rbx then
|
if rbx then
|
||||||
|
|||||||
Reference in New Issue
Block a user