From 574526aca0972341f34065d974f59aa70c6d6ed2 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Fri, 31 May 2024 10:50:51 +0200 Subject: [PATCH] Fix: traits handling --- .../lua/client/TOC/Controllers/DataController.lua | 9 +-------- .../TOC/Controllers/LocalPlayerController.lua | 15 +++++++++++---- media/lua/client/TOC/Events.lua | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/media/lua/client/TOC/Controllers/DataController.lua b/media/lua/client/TOC/Controllers/DataController.lua index 9c89188..e996b7f 100644 --- a/media/lua/client/TOC/Controllers/DataController.lua +++ b/media/lua/client/TOC/Controllers/DataController.lua @@ -97,14 +97,7 @@ function DataController:setup(key) -- self.tocData.isInitializing = false -- ModData.add(key, self.tocData) - - - -- FIX THIS THING HERE ISN'T REALLY CORRECT BUT IT'S A WORKAROUND UNTIL WE FIGURE IT OUT - -- The issue is that we need to do this once, not every single time we load data. - -- Manage their traits - local LocalPlayerController = require("TOC/Controller/LocalPlayerController") - LocalPlayerController.ManageTraits(getPlayer()) - + triggerEvent("OnSetupTocData") end ---In case of desync between the table on ModData and the table here diff --git a/media/lua/client/TOC/Controllers/LocalPlayerController.lua b/media/lua/client/TOC/Controllers/LocalPlayerController.lua index b4b8a3b..2bed9fa 100644 --- a/media/lua/client/TOC/Controllers/LocalPlayerController.lua +++ b/media/lua/client/TOC/Controllers/LocalPlayerController.lua @@ -46,11 +46,13 @@ function LocalPlayerController.InitializePlayer(isForced) SetHealthPanelTOC() end ----Handles the traits ----@param playerObj IsoPlayer -function LocalPlayerController.ManageTraits(playerObj) - -- FIX This can fail if we haven't initialized TOC in time` + +---Handles the traits +function LocalPlayerController.ManageTraits() + + -- Local player + local playerObj = getPlayer() local AmputationHandler = require("TOC/Handlers/AmputationHandler") for k, v in pairs(StaticData.TRAITS_BP) do @@ -67,6 +69,11 @@ function LocalPlayerController.ManageTraits(playerObj) end end +-- We need to manage traits when we're done setupping everything +-- It shouldn't be done every single time we initialize the player, fetching data, etc. +Events.OnSetupTocData.Add(LocalPlayerController.ManageTraits) + + ---------------------------------------------------------- --* Health *-- diff --git a/media/lua/client/TOC/Events.lua b/media/lua/client/TOC/Events.lua index 0d3b4c9..b4e19cf 100644 --- a/media/lua/client/TOC/Events.lua +++ b/media/lua/client/TOC/Events.lua @@ -2,3 +2,4 @@ LuaEventManager.AddEvent("OnAmputatedLimb") --Triggered when a limb has been amputated LuaEventManager.AddEvent("OnProsthesisUnequipped") LuaEventManager.AddEvent("OnReceivedTocData") -- Triggered when TOC data is ready +LuaEventManager.AddEvent("OnSetupTocData") -- Triggered when TOC has been setupped \ No newline at end of file