diff --git a/dev_stuff/healthPanelHide.psd b/dev_stuff/healthPanelHide.psd new file mode 100644 index 0000000..ab18f59 Binary files /dev/null and b/dev_stuff/healthPanelHide.psd differ diff --git a/media/lua/client/TOC_Main.lua b/media/lua/client/TOC_Main.lua index 5ae6fdf..30261cf 100644 --- a/media/lua/client/TOC_Main.lua +++ b/media/lua/client/TOC_Main.lua @@ -39,8 +39,6 @@ end function Main.Start() Main.SetupTraits() - - -- Starts initialization for local client Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer) diff --git a/media/lua/client/TOC_ModDataHandler.lua b/media/lua/client/TOC_ModDataHandler.lua index ee39b4d..66897fb 100644 --- a/media/lua/client/TOC_ModDataHandler.lua +++ b/media/lua/client/TOC_ModDataHandler.lua @@ -1,13 +1,14 @@ local StaticData = require("TOC_StaticData") ---------------- ----@alias amputationTable { isCut : boolean?, isInfected : boolean?, isOperated : boolean?, isCicatrized : boolean?, isCauterized : boolean?, isDependant : boolean? } - +---@alias partData { isCut : boolean?, isInfected : boolean?, isOperated : boolean?, isCicatrized : boolean?, isCauterized : boolean?, isDependant : boolean?, cicatrizationTime : number } +---@alias tocModData {Hand_L : partData, ForeArm_L : partData, UpperArm_L : partData, Hand_R : partData, ForeArm_R : partData, UpperArm_R : partData, isIgnoredPartInfected : boolean} ---------------- -- TODO This class should handle all the stuff related to the mod data ---@class ModDataHandler ---@field playerObj IsoPlayer +---@field tocData tocModData local ModDataHandler = {} ---@param playerObj IsoPlayer @@ -18,6 +19,7 @@ function ModDataHandler:new(playerObj) self.__index = self o.playerObj = playerObj + o.tocData = playerObj:getModData()[StaticData.MOD_NAME] ModDataHandler.instance = o @@ -25,9 +27,10 @@ function ModDataHandler:new(playerObj) end ---Setup a newly instanced ModDataHandler -function ModDataHandler:setup() - local modData = self.playerObj:getModData()[StaticData.MOD_NAME] - if modData == nil or modData.Hand_L == nil or modData.Hand_L.isCut == nil then +---@param force boolean? +function ModDataHandler:setup(force) + local tocData = self.playerObj:getModData()[StaticData.MOD_NAME] + if force or tocData == nil or tocData.Hand_L == nil or tocData.Hand_L.isCut == nil then self:createData() end -- TODO Check compatibility or do we just skip it at this point? @@ -44,7 +47,7 @@ function ModDataHandler:createData() isIgnoredPartInfected = false } - ---@type amputationTable + ---@type partData local defaultParams = {isCut = false, isInfected = false, isOperated = false, isCicatrized = false, isCauterized = false, isDependant = false} @@ -54,6 +57,8 @@ function ModDataHandler:createData() modData[StaticData.MOD_NAME][limbName] = {} self:setLimbParams(StaticData.LIMBS_STRINGS[i], defaultParams, 0) end + + self.tocData = self.playerObj:getModData()[StaticData.MOD_NAME] end @@ -64,20 +69,20 @@ end ---@param limbName string ---@param isCut boolean function ModDataHandler:setIsCut(limbName, isCut) - self.playerObj:getModData()[StaticData.MOD_NAME][limbName].isCut = isCut + self.tocData[limbName].isCut = isCut end ---Set isInfected ---@param limbName string ---@param isInfected boolean function ModDataHandler:setIsInfected(limbName, isInfected) - self.playerObj:getModData()[StaticData.MOD_NAME][limbName].isInfected = isInfected + self.tocData[limbName].isInfected = isInfected end ----Set isInfected +---Set isIgnoredPartInfected ---@param isIgnoredPartInfected boolean function ModDataHandler:setIsIgnoredPartInfected(isIgnoredPartInfected) - self.playerObj:getModData()[StaticData.MOD_NAME].setIsIgnoredPartInfected = isIgnoredPartInfected + self.tocData.isIgnoredPartInfected = isIgnoredPartInfected end ----------------- @@ -86,13 +91,13 @@ end ---@param limbName string ---@return boolean function ModDataHandler:getIsCut(limbName) - return self.playerObj:getModData()[StaticData.MOD_NAME][limbName].isCut + return self.tocData[limbName].isCut end ---Get isIgnoredPartInfected ---@return boolean function ModDataHandler:getIsIgnoredPartInfected() - return self.playerObj:getModData()[StaticData.MOD_NAME].isIgnoredPartInfected + return self.tocData.isIgnoredPartInfected end @@ -112,12 +117,10 @@ function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauteri cicatrizationTime = StaticData.LIMBS_CICATRIZATION_TIME[limbName] - surgeonFactor end - ---@type amputationTable + ---@type partData local params = {isCut = true, isInfected = false, isOperated = isOperated, isCicatrized = isCicatrized, isCauterized = isCauterized, isDependant = false} self:setLimbParams(limbName, params, cicatrizationTime) - local t = StaticData.LIMBS_DEPENDENCIES - print(t) for i=1, #StaticData.LIMBS_DEPENDENCIES[limbName] do local dependedLimbName = StaticData.LIMBS_DEPENDENCIES[limbName][i] @@ -125,16 +128,19 @@ function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauteri -- Same story for cicatrizationTime, which will be 0 self:setLimbParams(dependedLimbName, {isCut = true, isInfected = false, isDependant = true}, 0) end + + -- Set the highest amputation and caches them. + ISHealthPanel.GetHighestAmputation() end ---Internal use only, set a limb data ---@param limbName string ----@param ampStatus amputationTable {isCut, isInfected, isOperated, isCicatrized, isCauterized, isDependant} +---@param ampStatus partData {isCut, isInfected, isOperated, isCicatrized, isCauterized, isDependant} ---@param cicatrizationTime integer? ---@private function ModDataHandler:setLimbParams(limbName, ampStatus, cicatrizationTime) - local limbData = self.playerObj:getModData()[StaticData.MOD_NAME][limbName] + local limbData = self.tocData[limbName] if ampStatus.isCut ~= nil then limbData.isCut = ampStatus.isCut end if ampStatus.isInfected ~= nil then limbData.isInfected = ampStatus.isInfected end if ampStatus.isOperated ~= nil then limbData.isOperated = ampStatus.isOperated end diff --git a/media/lua/client/TOC_PlayerHandler.lua b/media/lua/client/TOC_PlayerHandler.lua index 2df4438..96ecfb5 100644 --- a/media/lua/client/TOC_PlayerHandler.lua +++ b/media/lua/client/TOC_PlayerHandler.lua @@ -9,9 +9,15 @@ local PlayerHandler = {} ---Setup player modData ---@param _ nil ---@param playerObj IsoPlayer -function PlayerHandler.InitializePlayer(_, playerObj) +---@param isForced boolean? +function PlayerHandler.InitializePlayer(_, playerObj, isForced) PlayerHandler.modDataHandler = ModDataHandler:new(playerObj) - PlayerHandler.modDataHandler:setup() + PlayerHandler.modDataHandler:setup(isForced) + + -- Since isForced is used to reset an existing player data, we're gonna clean their ISHealthPanel table too + if isForced then + ISHealthPanel.highestAmputations = {} + end end ---Cut a limb for a trait @@ -90,7 +96,7 @@ function PlayerHandler.CheckInfection(character, damageType, damage) -- This fucking event barely works. Bleeding seems to be the only thing that triggers it if character ~= getPlayer() then return end - + local bd = character:getBodyDamage() for i=1, #StaticData.LIMBS_STRINGS do diff --git a/media/lua/client/TOC_StaticData.lua b/media/lua/client/TOC_StaticData.lua index b63a44e..23b62d6 100644 --- a/media/lua/client/TOC_StaticData.lua +++ b/media/lua/client/TOC_StaticData.lua @@ -78,7 +78,11 @@ end StaticData.HEALTH_PANEL_TEXTURES = { Hand_L = getTexture("media/ui/Hand_L.png"), ForeArm_L = getTexture("media/ui/ForeArm_L.png"), - UpeerArm_L = getTexture("media/ui/UpperArm_L.png") + UpeerArm_L = getTexture("media/ui/UpperArm_L.png"), + + Hand_R = getTexture("media/ui/Hand_R.png"), + ForeArm_R = getTexture("media/ui/ForeArm_R.png"), + UpeerArm_R = getTexture("media/ui/UpperArm_R.png") } diff --git a/media/lua/client/TOC_Test.lua b/media/lua/client/TOC_Test.lua index 77e20ba..8da74de 100644 --- a/media/lua/client/TOC_Test.lua +++ b/media/lua/client/TOC_Test.lua @@ -10,12 +10,10 @@ TestFramework.registerTestModule("Functionality", "Amputation", function() local Tests = {} function Tests.InitializePlayer() - return true - -- TODO This breaks the Test Framework mod for some reason. - -- local pl = getPlayer() - -- PlayerHandler.InitializePlayer(nil, pl) - -- return true + local pl = getPlayer() + PlayerHandler.InitializePlayer(_, pl, true) + return true end function Tests.CutLeftHand() diff --git a/media/lua/client/UI/TOC_HealthPanel.lua b/media/lua/client/UI/TOC_HealthPanel.lua index 01e0b60..f3e751c 100644 --- a/media/lua/client/UI/TOC_HealthPanel.lua +++ b/media/lua/client/UI/TOC_HealthPanel.lua @@ -39,11 +39,11 @@ end -- TODO We need male variations ----@return {partL : string?, partR : string?} -local function GetHighestAmputation() + +function ISHealthPanel.GetHighestAmputation() -- TODO Cache this instead of doing it here! - local tab = {} + ISHealthPanel.highestAmputations = {} local prevDepSize = {} for i=1, #StaticData.LIMBS_STRINGS do local limbName = StaticData.LIMBS_STRINGS[i] @@ -51,20 +51,19 @@ local function GetHighestAmputation() if string.find(limbName, "_L") then index = "L" else index = "R" end if PlayerHandler.modDataHandler:getIsCut(limbName) then - if tab[index] ~= nil then + if ISHealthPanel.highestAmputations[index] ~= nil then local cDependencySize = #StaticData.LIMBS_DEPENDENCIES[limbName] if cDependencySize > prevDepSize[index] then - tab[index] = limbName + ISHealthPanel.highestAmputations[index] = limbName prevDepSize[index] = StaticData.LIMBS_DEPENDENCIES[limbName] end else - tab[index] = limbName + ISHealthPanel.highestAmputations[index] = limbName prevDepSize[index] = #StaticData.LIMBS_DEPENDENCIES[limbName] end end end - return tab end @@ -74,21 +73,25 @@ function ISHealthPanel:render() -- TODO Handle another player health panel - local highestAmputations = GetHighestAmputation() + if ISHealthPanel.highestAmputations then + -- Left Texture + if ISHealthPanel.highestAmputations["L"] then + local textureL = StaticData.HEALTH_PANEL_TEXTURES[ISHealthPanel.highestAmputations["L"]] + self:drawTextureScaled(textureL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 123, 302, 1, 1, 0, 0) + end - -- Left Texture - if highestAmputations["L"] then - local textureL = StaticData.HEALTH_PANEL_TEXTURES[highestAmputations["L"]] - self:drawTextureScaled(textureL, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 123, 302, 1, 1, 0, 0) - end - - if highestAmputations["R"] then - + -- Right Texture + if ISHealthPanel.highestAmputations["R"] then + local textureR = StaticData.HEALTH_PANEL_TEXTURES[ISHealthPanel.highestAmputations["R"]] + self:drawTextureScaled(textureR, self.healthPanel.x/2 - 2, self.healthPanel.y/2, 123, 302, 1, 1, 0, 0) + end + else + ISHealthPanel.GetHighestAmputation() end - -- Right Texture + end diff --git a/media/ui/ForeArm_R.png b/media/ui/ForeArm_R.png new file mode 100644 index 0000000..59119bd Binary files /dev/null and b/media/ui/ForeArm_R.png differ diff --git a/media/ui/Hand_L.png b/media/ui/Hand_L.png index ff67b58..6d83393 100644 Binary files a/media/ui/Hand_L.png and b/media/ui/Hand_L.png differ diff --git a/media/ui/Hand_R.png b/media/ui/Hand_R.png new file mode 100644 index 0000000..de4c38d Binary files /dev/null and b/media/ui/Hand_R.png differ diff --git a/media/ui/UpperArm_R.png b/media/ui/UpperArm_R.png new file mode 100644 index 0000000..d6266ad Binary files /dev/null and b/media/ui/UpperArm_R.png differ diff --git a/media/ui/test_render.png b/media/ui/test_render.png deleted file mode 100644 index a845b2d..0000000 Binary files a/media/ui/test_render.png and /dev/null differ diff --git a/media/ui/test_render2.png b/media/ui/test_render2.png deleted file mode 100644 index bd72e22..0000000 Binary files a/media/ui/test_render2.png and /dev/null differ