Added preliminary compatibility with iMeds

This commit is contained in:
ZioPao
2024-07-15 10:54:34 +02:00
parent 3f7bf56be2
commit 9a74710c1e
3 changed files with 97 additions and 53 deletions

9
.vscode/tasks.json vendored
View File

@@ -59,6 +59,15 @@
"problemMatcher": [ "problemMatcher": [
"$eslint-stylish" "$eslint-stylish"
] ]
},
{
"label": "Run Zomboid Test Server 3",
"options": {"statusbar": {"label": "$(run) Zomboid Server (TOC+FH+BH+iMedsFixed)"}},
"type": "shell",
"command":"\"${config:zomboid_server_folder}\\StartServer64_nosteam_custom.bat\" TOC_FH_BH_imeds",
"problemMatcher": [
"$eslint-stylish"
]
} }
] ]
} }

View File

@@ -1,39 +1,74 @@
---@class Compat
---@field handlers table<string, {fun : function, isActive : boolean}>
local Compat = {
handlers = {}
}
local function HandleModCompatibility() --- Brutal hands has a TOC_COMPAT but its check is wrong and uses an old API.
function Compat.BrutalHandwork()
BrutalHands = BrutalHands or {}
BrutalHands.TOC = require("TOC/API")
end
--- Was handled inside old TOC
local activatedMods = getActivatedMods() function Compat.FancyHandwork()
TOC_DEBUG.print("Checking for mods compatibility") require("TimedActions/FHSwapHandsAction")
local og_FHSwapHandsAction_isValid = FHSwapHandsAction.isValid
--[[ function FHSwapHandsAction:isValid()
Brutal hands has a TOC_COMPAT but its check is wrong and uses an old API. local tocApi = require("TOC/API")
]] if tocApi.hasBothHands(self.character) then
if activatedMods:contains('BrutalHandwork') then return og_FHSwapHandsAction_isValid(self)
TOC_DEBUG.print("found BrutalHandwork, activating compat module") else
BrutalHands = BrutalHands or {} return false
BrutalHands.TOC = require("TOC/API")
end
--[[
Was handled inside old TOC
]]
if activatedMods:contains('FancyHandwork') then
TOC_DEBUG.print("found FancyHandwork, activating compat module")
require("TimedActions/FHSwapHandsAction")
local og_FHSwapHandsAction_isValid = FHSwapHandsAction.isValid
function FHSwapHandsAction:isValid()
local tocApi = require("TOC/API")
if tocApi.hasBothHands(self.character) then
return og_FHSwapHandsAction_isValid(self)
else
return false
end
end end
end end
end end
Events.OnGameStart.Add(HandleModCompatibility)
function Compat.iMeds()
end
------------------------------
Compat.handlers = {
["BrutalHandwork"] = {
fun = Compat.BrutalHandwork,
isActive = false},
["FancyHandwork"] = {
fun = Compat.FancyHandwork,
isActive = false},
-- either or
['iMeds'] = {
fun = Compat.iMeds,
isActive = false},
['iMedsFixed'] = {
fun = Compat.iMeds,
isActive = false}
}
function Compat.RunModCompatibility()
local activatedMods = getActivatedMods()
TOC_DEBUG.print("Checking for mods compatibility")
for k, modCompatHandler in pairs(Compat.handlers) do
if activatedMods:contains(k) then
TOC_DEBUG.print("Found " .. k .. ", running compatibility handler")
modCompatHandler.fun()
modCompatHandler.isActive = true
end
end
end
Events.OnGameStart.Add(Compat.RunModCompatibility)
return Compat

View File

@@ -1,7 +1,7 @@
local StaticData = require("TOC/StaticData") local StaticData = require("TOC/StaticData")
local CommandsData = require("TOC/CommandsData")
local DataController = require("TOC/Controllers/DataController") local DataController = require("TOC/Controllers/DataController")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler") local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local Compat = require("TOC/Compat")
local CutLimbInteractionHandler = require("TOC/UI/Interactions/CutLimbInteractionHandler") local CutLimbInteractionHandler = require("TOC/UI/Interactions/CutLimbInteractionHandler")
local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleaningInteractionHandler") local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleaningInteractionHandler")
@@ -11,6 +11,9 @@ local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleani
local isReady = false local isReady = false
function SetHealthPanelTOC() function SetHealthPanelTOC()
-- depending on compatibility
isReady = true isReady = true
end end
@@ -128,23 +131,23 @@ function ISHealthPanel:render()
end end
local og_ISHealthPanel_update = ISHealthPanel.update -- local og_ISHealthPanel_update = ISHealthPanel.update
function ISHealthPanel:update() -- function ISHealthPanel:update()
og_ISHealthPanel_update(self) -- og_ISHealthPanel_update(self)
-- TODO Listen for changes on other player side instead of looping this -- -- TODO Listen for changes on other player side instead of looping this
-- FIX Re-enable it, just for test -- -- FIX Re-enable it, just for test
if self.character then -- if self.character then
local locPlUsername = getPlayer():getUsername() -- local locPlUsername = getPlayer():getUsername()
local remPlUsername = self.character:getUsername() -- local remPlUsername = self.character:getUsername()
if locPlUsername ~= remPlUsername and self:isReallyVisible() then -- if locPlUsername ~= remPlUsername and self:isReallyVisible() then
-- Request update for TOC DATA -- -- Request update for TOC DATA
local key = CommandsData.GetKey(remPlUsername) -- local key = CommandsData.GetKey(remPlUsername)
--ModData.request(key) -- --ModData.request(key)
end -- end
end -- end
end -- end
@@ -252,10 +255,10 @@ end
local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts
function ISHealthPanel:getDamagedParts() function ISHealthPanel:getDamagedParts()
-- TODO Overriding it is a lot easier, but ew -- check for imeds or if TOC is ready to display its stuff on the health panel
if isReady == false or Compat.handlers['iMeds'].isActive or Compat.handlers['iMedsFixed'].isActive then
if isReady then return og_ISHealthPanel_getDamagedParts(self)
elseif isReady then
local result = {} local result = {}
local bodyParts = self:getPatient():getBodyDamage():getBodyParts() local bodyParts = self:getPatient():getBodyDamage():getBodyParts()
if isClient() and not self:getPatient():isLocalPlayer() then if isClient() and not self:getPatient():isLocalPlayer() then
@@ -274,8 +277,5 @@ function ISHealthPanel:getDamagedParts()
end end
end end
return result return result
else
return og_ISHealthPanel_getDamagedParts(self)
end end
end end