plugin: Implement patch application, which makes live sync work

This commit is contained in:
Lucien Greathouse
2019-10-03 17:13:29 -07:00
parent 1d441b86d2
commit 6f1469a551
2 changed files with 131 additions and 8 deletions

View File

@@ -72,11 +72,40 @@ function ServeSession:start()
game
)
DEBUG_printPatch(hydratePatch)
-- TODO: Prompt user to notify them of this patch, since
-- it's effectively a conflict between the Rojo server and
-- the client.
-- TODO: Apply the patch generated by hydration. We should
-- eventually prompt the user about this since it's a
-- conflict between Rojo and their current place state.
self.__reconciler:applyPatch(hydratePatch)
-- TODO: Applying a patch may eventually only apply part of
-- the patch and start a content negotiation process with
-- the Rojo server. We should handle that!
local function mainLoop()
return self.__apiContext:retrieveMessages()
:andThen(function(messages)
for _, message in ipairs(messages) do
-- TODO: Update server to return patches in
-- correct format so that we don't have to
-- transform them for the reconciler.
local asPatch = {
removed = message.removedInstances,
updated = message.updatedInstances,
added = message.addedInstances,
}
self.__reconciler:applyPatch(asPatch)
end
if self.__status ~= Status.Disconnected then
return mainLoop()
end
end)
end
return mainLoop()
end)
end)
:catch(function(err)