Fixed sync with server after setup to prevent issues with medical check

This commit is contained in:
ZioPao
2024-05-05 00:14:37 +02:00
parent 20bed84910
commit aadbe02df4
3 changed files with 22 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ function DataController:setup(key)
---@type tocModDataType
self.tocData = {
-- Generic stuff that does not belong anywhere else
isInitializing = true,
isIgnoredPartInfected = false,
isAnyLimbCut = false,
limbs = {},
@@ -86,9 +87,16 @@ function DataController:setup(key)
}
end
-- Add it to global mod data
-- Add it to client global mod data
ModData.add(key, self.tocData)
-- Sync with the server
self:apply()
-- -- Disable lock
-- self.tocData.isInitializing = false
-- ModData.add(key, self.tocData)
end
---In case of desync between the table on ModData and the table here
@@ -100,7 +108,7 @@ function DataController:applyOnlineData(tocData)
end
---@param key string
function DataController:loadLocalData(key)
function DataController:tryLoadLocalData(key)
self.tocData = ModData.get(key)
--TOC_DEBUG.printTable(self.tocData)
@@ -389,6 +397,7 @@ function DataController.ReceiveData(key, data)
-- TODO Add update from server scenario
if handler.isResetForced then
TOC_DEBUG.print("Forced reset")
handler:setup(key)
elseif data then
if data.isUpdateFromServer then
@@ -396,7 +405,8 @@ function DataController.ReceiveData(key, data)
end
handler:applyOnlineData(data)
elseif username == getPlayer():getUsername() then
handler:loadLocalData(key)
TOC_DEBUG.print("loading local data")
handler:tryLoadLocalData(key)
end
@@ -436,7 +446,7 @@ Events.OnReceiveGlobalModData.Add(DataController.ReceiveData)
--- SP Only initialization
---@param key string
function DataController:initSinglePlayer(key)
self:loadLocalData(key)
self:tryLoadLocalData(key)
if self.tocData == nil or self.isResetForced then
self:setup(key)
end