mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 06:35:39 +00:00
Plugin half of configMap
This commit is contained in:
@@ -28,6 +28,7 @@ function ApiContext.new(baseUrl)
|
|||||||
onMessageCallback = nil,
|
onMessageCallback = nil,
|
||||||
serverId = nil,
|
serverId = nil,
|
||||||
rootInstanceId = nil,
|
rootInstanceId = nil,
|
||||||
|
configMap = nil,
|
||||||
connected = false,
|
connected = false,
|
||||||
messageCursor = -1,
|
messageCursor = -1,
|
||||||
partitionRoutes = nil,
|
partitionRoutes = nil,
|
||||||
@@ -69,6 +70,7 @@ function ApiContext:connect()
|
|||||||
self.connected = true
|
self.connected = true
|
||||||
self.partitionRoutes = body.partitions
|
self.partitionRoutes = body.partitions
|
||||||
self.rootInstanceId = body.rootInstanceId
|
self.rootInstanceId = body.rootInstanceId
|
||||||
|
self.configMap = body.configMap
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -126,7 +128,7 @@ function ApiContext:retrieveMessages()
|
|||||||
|
|
||||||
for _, message in ipairs(body.messages) do
|
for _, message in ipairs(body.messages) do
|
||||||
promise = promise:andThen(function()
|
promise = promise:andThen(function()
|
||||||
return self.onMessageCalllback(message)
|
return self.onMessageCallback(message)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -46,12 +46,15 @@ local function setProperty(instance, key, value)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: Pull this from project configuration instead
|
local function shouldClearUnknown(id, configMap)
|
||||||
local function shouldClearUnknown(instance)
|
if configMap[id] then
|
||||||
return instance.ClassName ~= "DataModel" and instance.ClassName ~= "ReplicatedStorage"
|
return not configMap[id].ignoreUnknown
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reify(instanceData, instanceMap, id, parent)
|
local function reify(instanceData, instanceMap, configMap, id, parent)
|
||||||
local data = instanceData[id]
|
local data = instanceData[id]
|
||||||
|
|
||||||
local instance = Instance.new(data.ClassName)
|
local instance = Instance.new(data.ClassName)
|
||||||
@@ -64,7 +67,7 @@ local function reify(instanceData, instanceMap, id, parent)
|
|||||||
instance.Name = data.Name
|
instance.Name = data.Name
|
||||||
|
|
||||||
for _, childId in ipairs(data.Children) do
|
for _, childId in ipairs(data.Children) do
|
||||||
reify(instanceData, instanceMap, childId, instance)
|
reify(instanceData, instanceMap, configMap, childId, instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
setProperty(instance, "Parent", parent)
|
setProperty(instance, "Parent", parent)
|
||||||
@@ -73,7 +76,7 @@ local function reify(instanceData, instanceMap, id, parent)
|
|||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reconcile(instanceData, instanceMap, id, existingInstance)
|
local function reconcile(instanceData, instanceMap, configMap, id, existingInstance)
|
||||||
local data = instanceData[id]
|
local data = instanceData[id]
|
||||||
|
|
||||||
assert(data.ClassName == existingInstance.ClassName)
|
assert(data.ClassName == existingInstance.ClassName)
|
||||||
@@ -108,13 +111,13 @@ local function reconcile(instanceData, instanceMap, id, existingInstance)
|
|||||||
|
|
||||||
if existingChildInstance ~= nil then
|
if existingChildInstance ~= nil then
|
||||||
unvisitedExistingChildren[existingChildInstance] = nil
|
unvisitedExistingChildren[existingChildInstance] = nil
|
||||||
reconcile(instanceData, instanceMap, childId, existingChildInstance)
|
reconcile(instanceData, instanceMap, configMap, childId, existingChildInstance)
|
||||||
else
|
else
|
||||||
reify(instanceData, instanceMap, childId, existingInstance)
|
reify(instanceData, instanceMap, configMap, childId, existingInstance)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if shouldClearUnknown(existingInstance) then
|
if shouldClearUnknown(id, configMap) then
|
||||||
for existingChildInstance in pairs(unvisitedExistingChildren) do
|
for existingChildInstance in pairs(unvisitedExistingChildren) do
|
||||||
instanceMap:removeInstance(existingChildInstance)
|
instanceMap:removeInstance(existingChildInstance)
|
||||||
existingChildInstance:Destroy()
|
existingChildInstance:Destroy()
|
||||||
@@ -165,7 +168,7 @@ function Session.new()
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if instance ~= nil then
|
if instance ~= nil then
|
||||||
reconcile(response.instances, instanceMap, id, instance)
|
reconcile(response.instances, instanceMap, api.configMap, id, instance)
|
||||||
else
|
else
|
||||||
error("TODO: Crawl up to nearest parent, use that?")
|
error("TODO: Crawl up to nearest parent, use that?")
|
||||||
end
|
end
|
||||||
@@ -179,8 +182,8 @@ function Session.new()
|
|||||||
return api:read({api.rootInstanceId})
|
return api:read({api.rootInstanceId})
|
||||||
end)
|
end)
|
||||||
:andThen(function(response)
|
:andThen(function(response)
|
||||||
reconcile(response.instances, instanceMap, api.rootInstanceId, game)
|
reconcile(response.instances, instanceMap, api.configMap, api.rootInstanceId, game)
|
||||||
-- reify(response.instances, instanceMap, api.rootInstanceId, game.ReplicatedStorage)
|
-- reify(response.instances, instanceMap, configMap, api.rootInstanceId, game.ReplicatedStorage)
|
||||||
return api:retrieveMessages()
|
return api:retrieveMessages()
|
||||||
end)
|
end)
|
||||||
:catch(function(message)
|
:catch(function(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user