diff --git a/media/lua/client/TOC_Main.lua b/media/lua/client/TOC_Main.lua index cd8cd77..37c4d02 100644 --- a/media/lua/client/TOC_Main.lua +++ b/media/lua/client/TOC_Main.lua @@ -1,4 +1,4 @@ -local PlayerHandler = require("TOC_PlayerHandler.lua") +local PlayerHandler = require("TOC_PlayerHandler") ------------------ @@ -6,13 +6,6 @@ local PlayerHandler = require("TOC_PlayerHandler.lua") local Main = {} -function Main.Start() - -- Starts initialization for local client - Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer) - Main.SetupTraits() - -end - ---Setups the custom traits function Main.SetupTraits() -- Perks.Left_Hand is defined in perks.txt @@ -42,6 +35,16 @@ function Main.SetupTraits() end +function Main.Start() + Main.SetupTraits() + + + + -- Starts initialization for local client + Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer) + +end + --* Events *-- Events.OnGameBoot.Add(Main.Start) \ No newline at end of file diff --git a/media/lua/client/TOC_ModDataHandler.lua b/media/lua/client/TOC_ModDataHandler.lua index c2a22f2..4272ff3 100644 --- a/media/lua/client/TOC_ModDataHandler.lua +++ b/media/lua/client/TOC_ModDataHandler.lua @@ -1,21 +1,91 @@ -local StaticData = require("TOC_StaticData.lua") +local StaticData = require("TOC_StaticData") ---------------- - ----@class ModDataHandler -local ModDataHandler = {} - -- TODO This class should handle all the stuff related to the mod data ----... +---@class ModDataHandler +---@field playerObj IsoPlayer +local ModDataHandler = {} + ---@param playerObj IsoPlayer -function ModDataHandler.Setup(playerObj) - ModDataHandler.player = playerObj +---@return ModDataHandler +function ModDataHandler:new(playerObj) + local o = {} + setmetatable(o, self) + self.__index = self + + o.playerObj = playerObj + ModDataHandler.instance = o + + return o +end + +---Setup a newly instanced ModDataHandler +function ModDataHandler:setup() + if self.modData == nil then self:createData() end + -- TODO Check compatibility or do we just skip it at this point? + +end + +function ModDataHandler:createData() + print("TOC: createData") + + self.playerObj:getModData()[StaticData.MOD_NAME] = {} + + -- Initialize limbs + for i=1, #StaticData.BP_STRINGS do + self:setLimbParams(StaticData.BP_STRINGS[i], false, false, false, false, false, false) + end +end + +------ + +---Set a limb and its dependend limbs as cut +---@param limbName string +function ModDataHandler:setCutLimb(limbName, isOperated, isCicatrized, isCauterized) + self:setLimbParams(limbName, true, false, isOperated, isCicatrized, isCauterized, false) + + for i=1, #StaticData.LIMB_DEPENDENCIES.limbName do + local dependedLimbName = StaticData.LIMB_DEPENDENCIES.limbName[i] + + -- We don't care about isOperated, isCicatrized and isCauterized since this is depending on another limb + self:setLimbParams(dependedLimbName, true, false, nil, nil, nil, true) + end end --------------------- -function ModDataHandler.GetModData() - return ModDataHandler.player:getModData()[StaticData.MOD_NAME] -end \ No newline at end of file +---Internal use only +---@param limbName string +---@param isCut boolean? +---@param isInfected boolean? +---@param isOperated boolean? +---@param isCicatrized boolean? +---@param isCauterized boolean? +---@param isDependant boolean? +---@private +function ModDataHandler:setLimbParams(limbName, isCut, isInfected, isOperated, isCicatrized, isCauterized, isDependant) + local limbData = self.playerObj:getModData()[StaticData.MOD_NAME][limbName] + if isCut ~= nil then + limbData.isCut = isCut + end + if isInfected ~= nil then + limbData.isInfected = isInfected + end + if isOperated ~= nil then + limbData.isOperated = isOperated + end + if isCicatrized ~= nil then + limbData.isCicatrized = isCicatrized + end + if isCauterized ~= nil then + limbData.isCauterized = isCauterized + end + if isDependant ~= nil then + limbData.isDependant = isDependant + end +end + + + +return ModDataHandler \ No newline at end of file diff --git a/media/lua/client/TOC_PlayerHandler.lua b/media/lua/client/TOC_PlayerHandler.lua index b91426d..8ac6ee4 100644 --- a/media/lua/client/TOC_PlayerHandler.lua +++ b/media/lua/client/TOC_PlayerHandler.lua @@ -1,10 +1,46 @@ --- TODO Should manage Player modData and stuff like that +local ModDataHandler = require("TOC_ModDataHandler") +local StaticData = require("TOC_StaticData") +----------- + ---@class PlayerHandler local PlayerHandler = {} ---Setup player modData -function PlayerHandler.InitializePlayer(playerIndex, playerObj) +---@param _ nil +---@param playerObj IsoPlayer +function PlayerHandler.InitializePlayer(_, playerObj) + + PlayerHandler.modDataHandler = ModDataHandler:new(playerObj) + PlayerHandler.modDataHandler:setup() + +end + +---... +---@param playerObj IsoPlayer +function PlayerHandler.ManageTraits(playerObj) + + for k,v in pairs(StaticData.TRAITS_BP) do + if playerObj:HasTrait(k) then PlayerHandler.ForceCutLimb(v) end + end -end \ No newline at end of file + -- -- Setup traits + -- if player:HasTrait("Amputee_Hand") then + -- TOC.CutLimbForTrait(player, modData.TOC, "Left_Hand") + -- elseif player:HasTrait("Amputee_LowerArm") then + -- TOC.CutLimbForTrait(player, modData.TOC, "Left_LowerArm") + -- elseif player:HasTrait("Amputee_UpperArm") then + -- TOC.CutLimbForTrait(player, modData.TOC, "Left_UpperArm") + -- end +end + +---comment +---@param limbName string +function PlayerHandler.ForceCutLimb(limbName) + PlayerHandler.modDataHandler:setCutLimb(limbName, true, true, true) + -- TODO Spawn amputation item +end + + +return PlayerHandler \ No newline at end of file diff --git a/media/lua/client/TOC_StaticData.lua b/media/lua/client/TOC_StaticData.lua index 4ef9146..943910b 100644 --- a/media/lua/client/TOC_StaticData.lua +++ b/media/lua/client/TOC_StaticData.lua @@ -3,6 +3,43 @@ local StaticData = {} StaticData.MOD_NAME = "TOC" +---@enum +StaticData.BP_STRINGS = { + RightHand = "RightHand", + RightLowerArm = "RightLowerArm", + RightUpperArm = "RightUpperArm", + + LeftHand = "LeftHand", + LeftLowerArm = "LeftLowerArm", + LeftUpperArm = "LeftUpperArm" +} + +-- Body Parts Strings +-- StaticData.BP_STRINGS = { +-- "RightHand", "RightLowerArm", "RightUpperArm", +-- "LeftHand", "LeftLowerArm", "LeftUpperArm" +-- } + +-- Link a trait to a specific body part +StaticData.TRAITS_BP = { + AmputeeHand = "LeftHand", + AmputeeLowerArm = "LeftLowerArm", + AmputeeUpeerArm = "LeftUpperArm" +} + + +StaticData.LIMB_DEPENDENCIES = { + RightHand = {}, + RightLowerArm = {StaticData.BP_STRINGS.RightHand}, + RightUpperArm = {StaticData.BP_STRINGS.RightHand, StaticData.BP_STRINGS.RightLowerArm}, + + LeftHand = {}, + LeftLowerArm = {StaticData.BP_STRINGS.LeftHand}, + LeftUpperArm = {StaticData.BP_STRINGS.LeftHand, StaticData.BP_STRINGS.LeftLowerArm}, + +} + + return StaticData diff --git a/mod.info b/mod.info index f6003b2..66cab32 100644 --- a/mod.info +++ b/mod.info @@ -1,6 +1,5 @@ name=The Only Cure poster=generic.png -require=UIAPI description=Bitten? Not a problem! id=TOC icon=icon.png