Some fixes to ModDataHandler, preventing desync with the table from ModData
This commit is contained in:
@@ -21,24 +21,32 @@ function ModDataHandler:new(username, isResetForced)
|
|||||||
o.username = username
|
o.username = username
|
||||||
local key = CommandsData.GetKey(username)
|
local key = CommandsData.GetKey(username)
|
||||||
|
|
||||||
ModData.request(key)
|
-- We don't want to request ModData if we're in SP, or if we're forcing a reset
|
||||||
o.tocData = ModData.get(key)
|
if isClient() and not isResetForced then
|
||||||
|
ModData.request(key)
|
||||||
|
end
|
||||||
|
|
||||||
|
o.tocData = ModData.get(key) -- TODO This is working like a placeholder at the moment, it's gonna get replaced later in reapplyTocData
|
||||||
|
|
||||||
if isResetForced or o.tocData == nil or o.tocData.limbs == nil or o.tocData.limbs.Hand_L == nil or o.tocData.limbs.Hand_L.isCut == nil then
|
if isResetForced or o.tocData == nil or o.tocData.limbs == nil or o.tocData.limbs.Hand_L == nil or o.tocData.limbs.Hand_L.isCut == nil then
|
||||||
TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now")
|
TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now")
|
||||||
o:setup(key)
|
o:setup(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
TOC_DEBUG.print("initialized ModDataHandler for " .. username)
|
|
||||||
|
|
||||||
-- Transmit it to the server
|
-- Transmit it to the server
|
||||||
ModData.transmit(key)
|
ModData.transmit(key)
|
||||||
|
TOC_DEBUG.print("initialized ModDataHandler for " .. username)
|
||||||
|
|
||||||
ModDataHandler.instances[username] = o
|
ModDataHandler.instances[username] = o
|
||||||
|
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ModDataHandler:initialize()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
---Setup a new toc mod data data class
|
---Setup a new toc mod data data class
|
||||||
---@param key string
|
---@param key string
|
||||||
function ModDataHandler:setup(key)
|
function ModDataHandler:setup(key)
|
||||||
@@ -79,6 +87,13 @@ function ModDataHandler:setup(key)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---In case of desync between the table on ModData and the table here
|
||||||
|
---@param key string
|
||||||
|
---@param tocData tocModData
|
||||||
|
function ModDataHandler:reapplyTocData(key, tocData)
|
||||||
|
ModData.add(key, tocData)
|
||||||
|
self.tocData = ModData.get(key)
|
||||||
|
end
|
||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
--* Setters *--
|
--* Setters *--
|
||||||
@@ -273,6 +288,7 @@ function ModDataHandler.ReceiveData(key, table)
|
|||||||
if not isClient() then
|
if not isClient() then
|
||||||
TOC_DEBUG.print("SP, skipping ModDataHandler.ReceiveData")
|
TOC_DEBUG.print("SP, skipping ModDataHandler.ReceiveData")
|
||||||
end
|
end
|
||||||
|
TOC_DEBUG.print("receiving data from server")
|
||||||
|
|
||||||
if key == "TOC_Bob" then return end -- TODO Fix this
|
if key == "TOC_Bob" then return end -- TODO Fix this
|
||||||
|
|
||||||
@@ -281,9 +297,10 @@ function ModDataHandler.ReceiveData(key, table)
|
|||||||
TOC_DEBUG.print("table is nil... returning")
|
TOC_DEBUG.print("table is nil... returning")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
ModData.add(key, table) -- Add it to the client mod data (not sure)
|
|
||||||
|
-- Create ModDataHandler instance if there was none for that user and reapply the correct ModData table as a reference
|
||||||
local username = key:sub(5)
|
local username = key:sub(5)
|
||||||
ModDataHandler.GetInstance(username)
|
ModDataHandler.GetInstance(username):reapplyTocData(key, table) --tocData = table -- TODO Ugly, use a setter
|
||||||
end
|
end
|
||||||
Events.OnReceiveGlobalModData.Add(ModDataHandler.ReceiveData)
|
Events.OnReceiveGlobalModData.Add(ModDataHandler.ReceiveData)
|
||||||
|
|
||||||
|
|||||||
@@ -115,10 +115,12 @@ end)
|
|||||||
--------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
if not getActivatedMods():contains("PerfTestFramework") or not isDebugEnabled() then return end
|
if not getActivatedMods():contains("PerfTestFramework") or not isDebugEnabled() then return end
|
||||||
local PerfTest = require("PerfTest/main")
|
local PerfTest = require("PerfTest/main") -- SHould be global anyway
|
||||||
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
|
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
|
||||||
|
|
||||||
PerfTest.Init()
|
PerfTest.Init()
|
||||||
PerfTest.RegisterMethod("PlayerHandler", PlayerHandler, "UpdateCicatrization")
|
|
||||||
PerfTest.RegisterMethod("CachedDataHandler", CachedDataHandler, "CalculateHighestAmputatedLimbs")
|
|
||||||
PerfTest.RegisterMethod("ISHealthPanel", ISHealthPanel, "render")
|
--PerfTest.RegisterMethod("PlayerHandler", PlayerHandler, "UpdateCicatrization")
|
||||||
|
--PerfTest.RegisterMethod("CachedDataHandler", CachedDataHandler, "CalculateHighestAmputatedLimbs")
|
||||||
|
--PerfTest.RegisterMethod("ISHealthPanel", ISHealthPanel, "render")
|
||||||
@@ -14,7 +14,10 @@ end
|
|||||||
---@param key string
|
---@param key string
|
||||||
---@param table tocModData
|
---@param table tocModData
|
||||||
function ServerDataHandler.AddTable(key, table)
|
function ServerDataHandler.AddTable(key, table)
|
||||||
TOC_DEBUG.print("Adding table with key: " .. tostring(key))
|
print("TOC: received ModData => " .. key)
|
||||||
|
|
||||||
|
TOC_DEBUG.printTable(table)
|
||||||
|
--TOC_DEBUG.print("Adding table with key: " .. tostring(key))
|
||||||
ModData.add(key, table) -- Add it to the server mod data
|
ModData.add(key, table) -- Add it to the server mod data
|
||||||
ServerDataHandler.modData[key] = table
|
ServerDataHandler.modData[key] = table
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user