mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-28 08:36:11 +00:00
Robust init.lua support
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
local Reconciler = {}
|
local Reconciler = {}
|
||||||
|
|
||||||
local function isInit(item, itemFileName)
|
local function isInit(item, itemFileName)
|
||||||
if item.type == "dir" then
|
if item and item.type == "dir" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -99,12 +99,31 @@ end
|
|||||||
function Reconciler.reconcile(rbx, item, fileName, parent)
|
function Reconciler.reconcile(rbx, item, fileName, parent)
|
||||||
-- Item was deleted!
|
-- Item was deleted!
|
||||||
if not item then
|
if not item then
|
||||||
|
if isInit(item, fileName) then
|
||||||
|
if not parent then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Un-usurp parent!
|
||||||
|
local newParent = Instance.new("Folder")
|
||||||
|
newParent.Name = parent.Name
|
||||||
|
|
||||||
|
for _, child in ipairs(parent:GetChildren()) do
|
||||||
|
child.Parent = newParent
|
||||||
|
end
|
||||||
|
|
||||||
|
newParent.Parent = parent.Parent
|
||||||
|
parent:Destroy()
|
||||||
|
|
||||||
|
return
|
||||||
|
else
|
||||||
if rbx then
|
if rbx then
|
||||||
rbx:Destroy()
|
rbx:Destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if item.type == "dir" then
|
if item.type == "dir" then
|
||||||
-- Folder was created!
|
-- Folder was created!
|
||||||
@@ -120,10 +139,12 @@ function Reconciler.reconcile(rbx, item, fileName, parent)
|
|||||||
if rbx.ClassName == initClassName then
|
if rbx.ClassName == initClassName then
|
||||||
setValues(rbx, initItem, initFileName)
|
setValues(rbx, initItem, initFileName)
|
||||||
else
|
else
|
||||||
|
rbx:Destroy()
|
||||||
return Reconciler._reify(item, fileName, parent)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if rbx.ClassName ~= "Folder" then
|
if rbx.ClassName ~= "Folder" then
|
||||||
|
rbx:Destroy()
|
||||||
return Reconciler._reify(item, fileName, parent)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -150,9 +171,26 @@ function Reconciler.reconcile(rbx, item, fileName, parent)
|
|||||||
return rbx
|
return rbx
|
||||||
elseif item.type == "file" then
|
elseif item.type == "file" then
|
||||||
if isInit(item, fileName) then
|
if isInit(item, fileName) then
|
||||||
-- TODO: usurp parent
|
-- Usurp our container!
|
||||||
|
local _, className = itemToName(item, fileName)
|
||||||
|
|
||||||
|
if parent.ClassName == className then
|
||||||
|
rbx = parent
|
||||||
|
else
|
||||||
|
rbx = Reconciler._reify(item, fileName, parent.Parent)
|
||||||
|
rbx.Name = parent.Name
|
||||||
|
|
||||||
|
for _, child in ipairs(parent:GetChildren()) do
|
||||||
|
child.Parent = rbx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parent:Destroy()
|
||||||
|
end
|
||||||
|
|
||||||
|
setValues(rbx, item, fileName)
|
||||||
|
|
||||||
|
return rbx
|
||||||
|
else
|
||||||
if not rbx then
|
if not rbx then
|
||||||
return Reconciler._reify(item, fileName, parent)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
end
|
end
|
||||||
@@ -160,12 +198,14 @@ function Reconciler.reconcile(rbx, item, fileName, parent)
|
|||||||
local _, className = itemToName(item, fileName)
|
local _, className = itemToName(item, fileName)
|
||||||
|
|
||||||
if rbx.ClassName ~= className then
|
if rbx.ClassName ~= className then
|
||||||
|
rbx:Destroy()
|
||||||
return Reconciler._reify(item, fileName, parent)
|
return Reconciler._reify(item, fileName, parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
setValues(rbx, item, fileName)
|
setValues(rbx, item, fileName)
|
||||||
|
|
||||||
return rbx
|
return rbx
|
||||||
|
end
|
||||||
else
|
else
|
||||||
error("unknown item type " .. tostring(item.type))
|
error("unknown item type " .. tostring(item.type))
|
||||||
end
|
end
|
||||||
@@ -191,17 +231,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, location)
|
Reconciler.reconcile(rbx, item, fileName, location)
|
||||||
|
|
||||||
if newRbx ~= rbx then
|
|
||||||
if rbx then
|
|
||||||
rbx:Destroy()
|
|
||||||
end
|
|
||||||
|
|
||||||
if newRbx then
|
|
||||||
newRbx.Parent = location
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Reconciler
|
return Reconciler
|
||||||
|
|||||||
Reference in New Issue
Block a user