Fixed sync with server after setup to prevent issues with medical check
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -29,12 +29,18 @@ function ServerDataHandler.AddTable(key, table)
|
||||
--TOC_DEBUG.printTable(table)
|
||||
|
||||
-- Set that the data has been modified and it's updated on the server
|
||||
table.isUpdateFromServer = true
|
||||
table.isUpdateFromServer = true -- FIX this is useless
|
||||
|
||||
ModData.add(key, table) -- Add it to the server mod data
|
||||
ServerDataHandler.modData[key] = table
|
||||
|
||||
|
||||
-- if table.isInitializing == true then
|
||||
-- TOC_DEBUG.print("Applied data after setup")
|
||||
-- table.isInitializing = false
|
||||
-- end
|
||||
|
||||
|
||||
-- Since this could be triggered by a different client than the one referenced in the key, we're gonna
|
||||
-- apply the changes back to the key client again to be sure that everything is in sync
|
||||
local username = CommandsData.GetUsername(key)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
---@alias limbsTable {Hand_L : partDataType, ForeArm_L : partDataType, UpperArm_L : partDataType, Hand_R : partDataType, ForeArm_R : partDataType, UpperArm_R : partDataType }
|
||||
---@alias prosthesisData {isProstEquipped : boolean, prostFactor : number }
|
||||
---@alias prosthesesTable {Top_L : prosthesisData, Top_R : prosthesisData } -- TODO add Bottom_L and Bottom_R
|
||||
---@alias tocModDataType { limbs : limbsTable, prostheses : prosthesesTable, isIgnoredPartInfected : boolean, isAnyLimbCut : boolean, isUpdateFromServer : boolean }
|
||||
---@alias tocModDataType { limbs : limbsTable, prostheses : prosthesesTable, isIgnoredPartInfected : boolean, isAnyLimbCut : boolean, isUpdateFromServer : boolean, isInitializing : boolean}
|
||||
---------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user