Initialization remade
This commit is contained in:
@@ -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 = {}
|
local Main = {}
|
||||||
|
|
||||||
|
|
||||||
function Main.Start()
|
|
||||||
-- Starts initialization for local client
|
|
||||||
Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer)
|
|
||||||
Main.SetupTraits()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
---Setups the custom traits
|
---Setups the custom traits
|
||||||
function Main.SetupTraits()
|
function Main.SetupTraits()
|
||||||
-- Perks.Left_Hand is defined in perks.txt
|
-- Perks.Left_Hand is defined in perks.txt
|
||||||
@@ -42,6 +35,16 @@ function Main.SetupTraits()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Main.Start()
|
||||||
|
Main.SetupTraits()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Starts initialization for local client
|
||||||
|
Events.OnCreatePlayer.Add(PlayerHandler.InitializePlayer)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
--* Events *--
|
--* Events *--
|
||||||
|
|
||||||
Events.OnGameBoot.Add(Main.Start)
|
Events.OnGameBoot.Add(Main.Start)
|
||||||
@@ -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
|
-- TODO This class should handle all the stuff related to the mod data
|
||||||
|
|
||||||
---...
|
---@class ModDataHandler
|
||||||
|
---@field playerObj IsoPlayer
|
||||||
|
local ModDataHandler = {}
|
||||||
|
|
||||||
---@param playerObj IsoPlayer
|
---@param playerObj IsoPlayer
|
||||||
function ModDataHandler.Setup(playerObj)
|
---@return ModDataHandler
|
||||||
ModDataHandler.player = playerObj
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
function ModDataHandler.GetModData()
|
---Internal use only
|
||||||
return ModDataHandler.player:getModData()[StaticData.MOD_NAME]
|
---@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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ModDataHandler
|
||||||
@@ -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
|
---@class PlayerHandler
|
||||||
local PlayerHandler = {}
|
local PlayerHandler = {}
|
||||||
|
|
||||||
|
|
||||||
---Setup player modData
|
---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
|
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
|
||||||
|
|
||||||
|
-- -- 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
|
||||||
@@ -3,6 +3,43 @@ local StaticData = {}
|
|||||||
|
|
||||||
StaticData.MOD_NAME = "TOC"
|
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
|
return StaticData
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user