Bunch of stuff for the UI

This commit is contained in:
ZioPao
2023-11-07 01:19:19 +01:00
parent 835c57faaa
commit 4f6910c806
13 changed files with 60 additions and 45 deletions

View File

@@ -39,8 +39,6 @@ end
function Main.Start()
Main.SetupTraits()
-- Starts initialization for local client
Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer)

View File

@@ -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

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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()

View File

@@ -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