diff --git a/media/lua/client/TOC/Handlers/ModDataHandler.lua b/media/lua/client/TOC/Handlers/ModDataHandler.lua index 00614d7..efc038e 100644 --- a/media/lua/client/TOC/Handlers/ModDataHandler.lua +++ b/media/lua/client/TOC/Handlers/ModDataHandler.lua @@ -29,6 +29,8 @@ function ModDataHandler:new(username, isResetForced) TOC_DEBUG.print("tocData in ModDataHandler for " .. username .. " is nil, creating it now") self:setup(key) end + -- Transmit it to the server + ModData.transmit(key) ModDataHandler.instances[username] = o @@ -59,8 +61,7 @@ function ModDataHandler:setup(key) -- Add it to global mod data ModData.add(key, self.tocData) - -- Transmit it to the server - ModData.transmit(key) + end @@ -169,12 +170,26 @@ function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime) end ---* Global Mod Data Apply *-- +--* Global Mod Data Handling *-- function ModDataHandler:apply() ModData.transmit(CommandsData.GetKey(self.username)) end + +function ModDataHandler.ReceiveData(key, table) + TOC_DEBUG.print("receive data for " .. key) + if table == {} or table == nil then + TOC_DEBUG.print("table is nil... returning") + return + end + ModData.add(key, table) -- Add it to the client mod data (not sure) + local username = key:sub(5) + ModDataHandler.GetInstance(username) +end +Events.OnReceiveGlobalModData.Add(ModDataHandler.ReceiveData) + + ---@param username string? ---@return ModDataHandler function ModDataHandler.GetInstance(username) diff --git a/media/lua/client/TOC/Handlers/PlayerHandler.lua b/media/lua/client/TOC/Handlers/PlayerHandler.lua index 27f66b6..70f403e 100644 --- a/media/lua/client/TOC/Handlers/PlayerHandler.lua +++ b/media/lua/client/TOC/Handlers/PlayerHandler.lua @@ -18,7 +18,7 @@ local PlayerHandler = {} PlayerHandler.amputatedLimbs = {} ----Setup the Player Handler and modData +---Setup the Player Handler and modData, only for local client ---@param playerObj IsoPlayer ---@param isForced boolean? function PlayerHandler.InitializePlayer(playerObj, isForced) @@ -27,15 +27,9 @@ function PlayerHandler.InitializePlayer(playerObj, isForced) TOC_DEBUG.print("initializing " .. username) local modDataHandler = ModDataHandler:new(username, isForced) PlayerHandler.playerObj = playerObj - -- Calculate amputated limbs at startup - PlayerHandler.amputatedLimbs[username] = {} - for i=1, #StaticData.LIMBS_STRINGS do - local limbName = StaticData.LIMBS_STRINGS[i] - if modDataHandler:getIsCut(limbName) then - PlayerHandler.AddLocalAmputatedLimb(username, limbName) - end - end + -- Calculate amputated limbs at startup + PlayerHandler.CacheAmputatedLimbs(username) -- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too if isForced then @@ -60,8 +54,23 @@ function PlayerHandler.ManageTraits(playerObj) end end +---Cycle through all the limbs and caches the ones that the player cut off +---@param username string +function PlayerHandler.CacheAmputatedLimbs(username) + PlayerHandler.amputatedLimbs[username] = {} + local modDataHandler = ModDataHandler.GetInstance(username) + for i=1, #StaticData.LIMBS_STRINGS do + local limbName = StaticData.LIMBS_STRINGS[i] + if modDataHandler:getIsCut(limbName) then + PlayerHandler.AddLocalAmputatedLimb(username, limbName) + end + end +end + + ---Cache the currently amputated limbs ---@param limbName string +---@private function PlayerHandler.AddLocalAmputatedLimb(username, limbName) TOC_DEBUG.print("added " .. limbName .. " to known amputated limbs for " .. username) table.insert(PlayerHandler.amputatedLimbs[username], limbName) -- TODO This should be player specific, not generic diff --git a/media/lua/client/TOC/UI/HealthPanel.lua b/media/lua/client/TOC/UI/HealthPanel.lua index 9a7f1d5..c9e6fd6 100644 --- a/media/lua/client/TOC/UI/HealthPanel.lua +++ b/media/lua/client/TOC/UI/HealthPanel.lua @@ -2,7 +2,6 @@ local PlayerHandler = require("TOC/Handlers/PlayerHandler") local StaticData = require("TOC/StaticData") local CommonMethods = require("TOC/CommonMethods") local ModDataHandler = require("TOC/Handlers/ModDataHandler") -local CommandsData = require("TOC/CommandsData") ---@diagnostic disable: duplicate-set-field local CutLimbHandler = require("TOC/UI/CutLimbInteractions") @@ -48,15 +47,12 @@ end function ISHealthPanel:setHighestAmputation() --TOC_DEBUG.print("setHighestAmputation for " .. self.tocUsername) - - if self.otherPlayer ~= nil then - self.tocUsername = self.otherPlayer:getUsername() - else - self.tocUsername = self.character:getUsername() - end + + -- character is always the patient. + self.tocUsername = self.character:getUsername() if PlayerHandler.amputatedLimbs == nil or PlayerHandler.amputatedLimbs[self.tocUsername] == nil then - TOC_DEBUG.print("PlayerHandler.amputatedLimbs is still nil or wasn't initialized for that player") + TOC_DEBUG.print("PlayerHandler.amputatedLimbs is still nil or wasn't initialized for " .. self.tocUsername) return end local amputatedLimbs = PlayerHandler.amputatedLimbs[self.tocUsername] @@ -111,6 +107,8 @@ local og_ISHealthPanel_render = ISHealthPanel.render function ISHealthPanel:render() og_ISHealthPanel_render(self) + --print("Rendering ISHealthPanel") + if self.highestAmputations ~= nil and self.highestAmputations[self.tocUsername] ~= nil then -- Left Texture @@ -134,4 +132,45 @@ local og_ISCharacterInfoWindow_render = ISCharacterInfoWindow.prerender function ISCharacterInfoWindow:prerender() og_ISCharacterInfoWindow_render(self) self.backgroundColor.a = 1 +end + +-- We need to override this to force the alpha to 1 for the Medical Check in particular +local og_ISHealthPanel_prerender = ISHealthPanel.prerender +function ISHealthPanel:prerender() + og_ISHealthPanel_prerender(self) + self.backgroundColor.a = 1 +end + + +--- The medical check wrap the health panel into this. We need to override its color +local overrideBackgroundColor = true +local og_ISUIElement_wrapInCollapsableWindow = ISUIElement.wrapInCollapsableWindow +function ISUIElement:wrapInCollapsableWindow(title, resizable, subClass) + local panel = og_ISUIElement_wrapInCollapsableWindow(self, title, resizable, subClass) + + if overrideBackgroundColor then + TOC_DEBUG.print("Overriding color for panel - " .. title) + self.backgroundColor.a = 1 + panel.backgroundColor.a = 1 + end + + return panel +end + + + + + + + +-- This is run when a player is trying the Medical Check action on another player +local og_ISMedicalCheckAction_perform = ISMedicalCheckAction.perform +function ISMedicalCheckAction:perform() + local username = self.otherPlayer:getUsername() + TOC_DEBUG.print("creating instance for " .. username ) + ModDataHandler.GetInstance(username) + + -- We need to recalculate them here before we can create the highest amputations point + PlayerHandler.CacheAmputatedLimbs(username) + og_ISMedicalCheckAction_perform(self) end \ No newline at end of file diff --git a/media/lua/server/TOC/DebugCommands.lua b/media/lua/server/TOC/DebugCommands.lua index b0cbd44..7239a02 100644 --- a/media/lua/server/TOC/DebugCommands.lua +++ b/media/lua/server/TOC/DebugCommands.lua @@ -1,15 +1,26 @@ local CommandsData = require("TOC/CommandsData") +local ServerDataHandler = require("TOC/ServerDataHandler") + +---------------------------- local DebugCommands = {} +---comment +---@param playerObj IsoPlayer +---@param args table +function DebugCommands.PrintAllTocData(playerObj, args) + TOC_DEBUG.printTable(ServerDataHandler.modData) +end + ---comment ---@param playerObj IsoPlayer ----@param args {username : string} +---@param args printTocDataParams function DebugCommands.PrintTocData(playerObj, args) - local data = ModData.get(CommandsData.GetKey(args.username)) - TOC_DEBUG.printTable(data) + local key = CommandsData.GetKey(args.username) + local tocData = ServerDataHandler.GetTable(key) + TOC_DEBUG.printTable(tocData) end -------------------- diff --git a/media/lua/server/TOC/ServerDataCommands.lua b/media/lua/server/TOC/ServerDataCommands.lua deleted file mode 100644 index d09ffe0..0000000 --- a/media/lua/server/TOC/ServerDataCommands.lua +++ /dev/null @@ -1,54 +0,0 @@ --- TODO Switch EVERYTHING to global mod data - -local CommandsData = require("TOC/CommandsData") - -local ServerDataCommands = {} -local moduleName = "test_sync" - - -local function PrintModDataTable(key, table) - print("Received key: " .. key) -end - - -Events.OnReceiveGlobalModData.Add(PrintModDataTable) - - - --- TODO Consider delays - - - - --- TODO Use transmit from client --- ---comment --- ---@param playerObj IsoPlayer --- ---@param args any --- function ServerDataCommands.AddTable(playerObj, args) --- ModData.add(GetKey(playerObj), args.tocData) --- end - - --- function ServerDataCommands.GetTable(playerObj, args) --- local requestedPlayer = getSpecificPlayer(args.playerNum) --- local data = ModData.get(CommandsData.GetKey(requestedPlayer)) - --- -- TODO Request from that client again just to be sure that it's synced? - --- sendServerCommand() --- end - - - ------------------------------- - --- local function OnClientDataCommand(module, command, playerObj, args) --- if module == moduleName and ServerDataCommands[command] then --- ServerDataCommands[command](playerObj, args) --- end --- end - --- Events.OnClientCommand.Add(OnClientDataCommand) - - - diff --git a/media/lua/server/TOC/ServerDataHandler.lua b/media/lua/server/TOC/ServerDataHandler.lua new file mode 100644 index 0000000..70e1a1e --- /dev/null +++ b/media/lua/server/TOC/ServerDataHandler.lua @@ -0,0 +1,26 @@ +if isClient() then return end + + + + + +local ServerDataHandler = {} +ServerDataHandler.modData = {} + +---Get the server mod data table containing that player TOC data +---@param key string +---@return tocModData +function ServerDataHandler.GetTable(key) + return ServerDataHandler.modData[key] +end + + +function ServerDataHandler.AddTable(key, table) + ModData.add(key, table) -- Add it to the server mod data + ServerDataHandler.modData[key] = table +end + +Events.OnReceiveGlobalModData.Add(ServerDataHandler.AddTable) + + +return ServerDataHandler diff --git a/media/lua/shared/TOC/CommandsData.lua b/media/lua/shared/TOC/CommandsData.lua index 871ec0f..274c27f 100644 --- a/media/lua/shared/TOC/CommandsData.lua +++ b/media/lua/shared/TOC/CommandsData.lua @@ -23,7 +23,8 @@ CommandsData.server = { }, Debug = { - PrintTocData = "PrintTocData" ---@alias printTocDataParams {username : string} + PrintTocData = "PrintTocData", ---@alias printTocDataParams {username : string} + PrintAllTocData = "PrintAllTocData" } } @@ -34,4 +35,13 @@ function CommandsData.GetKey(username) return StaticData.MOD_NAME .. "_" .. username end +-- ---comment +-- ---@param key string +-- ---@return string +-- function CommandsData.GetUsernameFromKey(key) +-- local subSize = #StaticData.MOD_NAME + 1 +-- local username = key:sub(subSize) +-- return username +-- end + return CommandsData \ No newline at end of file diff --git a/media/lua/shared/TOC/Debug.lua b/media/lua/shared/TOC/Debug.lua index 8256cd9..ff3d7b1 100644 --- a/media/lua/shared/TOC/Debug.lua +++ b/media/lua/shared/TOC/Debug.lua @@ -28,10 +28,16 @@ function TOC_DEBUG.printTable(table, indent) end end -function TOC_DEBUG.printGlobalModDataServer(username) - local CommandsData = require("TOC/CommandsData") - ---@type printTocDataParams - local params = {username = username} - sendClientCommand(CommandsData.modules.TOC_DEBUG, CommandsData.server.Debug.PrintTocData, params) + +--* Debug server commands *-- + +local CommandsData = require("TOC/CommandsData") + +function TOC_DEBUG.printPlayerServerModData(username) + sendClientCommand(CommandsData.modules.TOC_DEBUG, CommandsData.server.Debug.PrintTocData, {username = username}) +end + +function TOC_DEBUG.printAllServerModData() + sendClientCommand(CommandsData.modules.TOC_DEBUG, CommandsData.server.Debug.PrintAllTocData, {}) end \ No newline at end of file diff --git a/media/lua/shared/TOC/StaticData.lua b/media/lua/shared/TOC/StaticData.lua index 2a0bd1e..8c4f347 100644 --- a/media/lua/shared/TOC/StaticData.lua +++ b/media/lua/shared/TOC/StaticData.lua @@ -92,6 +92,16 @@ StaticData.HEALTH_PANEL_TEXTURES = { ForeArm_L = getTexture("media/ui/ForeArm_L.png"), UpperArm_L = getTexture("media/ui/UpperArm_L.png"), + Hand_R = getTexture("media/ui/Hand_R.png"), + ForeArm_R = getTexture("media/ui/ForeArm_R.png"), + UpperArm_R = getTexture("media/ui/UpperArm_R.png") + }, + + Male = { + Hand_L = getTexture("media/ui/Hand_L.png"), + ForeArm_L = getTexture("media/ui/ForeArm_L.png"), + UpperArm_L = getTexture("media/ui/UpperArm_L.png"), + Hand_R = getTexture("media/ui/Hand_R.png"), ForeArm_R = getTexture("media/ui/ForeArm_R.png"), UpperArm_R = getTexture("media/ui/UpperArm_R.png")