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

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
local activatedMods = getActivatedMods()
TOC_DEBUG.print("Checking for mods compatibility")
--[[
Brutal hands has a TOC_COMPAT but its check is wrong and uses an old API.
]]
if activatedMods:contains('BrutalHandwork') then
TOC_DEBUG.print("found BrutalHandwork, activating compat module")
BrutalHands = BrutalHands or {}
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
--- Was handled inside old TOC
function Compat.FancyHandwork()
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
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 CommandsData = require("TOC/CommandsData")
local DataController = require("TOC/Controllers/DataController")
local CachedDataHandler = require("TOC/Handlers/CachedDataHandler")
local Compat = require("TOC/Compat")
local CutLimbInteractionHandler = require("TOC/UI/Interactions/CutLimbInteractionHandler")
local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleaningInteractionHandler")
@@ -11,6 +11,9 @@ local WoundCleaningInteractionHandler = require("TOC/UI/Interactions/WoundCleani
local isReady = false
function SetHealthPanelTOC()
-- depending on compatibility
isReady = true
end
@@ -128,23 +131,23 @@ function ISHealthPanel:render()
end
local og_ISHealthPanel_update = ISHealthPanel.update
function ISHealthPanel:update()
og_ISHealthPanel_update(self)
-- TODO Listen for changes on other player side instead of looping this
-- local og_ISHealthPanel_update = ISHealthPanel.update
-- function ISHealthPanel:update()
-- og_ISHealthPanel_update(self)
-- -- TODO Listen for changes on other player side instead of looping this
-- FIX Re-enable it, just for test
if self.character then
local locPlUsername = getPlayer():getUsername()
local remPlUsername = self.character:getUsername()
if locPlUsername ~= remPlUsername and self:isReallyVisible() then
-- Request update for TOC DATA
local key = CommandsData.GetKey(remPlUsername)
--ModData.request(key)
end
end
end
-- -- FIX Re-enable it, just for test
-- if self.character then
-- local locPlUsername = getPlayer():getUsername()
-- local remPlUsername = self.character:getUsername()
-- if locPlUsername ~= remPlUsername and self:isReallyVisible() then
-- -- Request update for TOC DATA
-- local key = CommandsData.GetKey(remPlUsername)
-- --ModData.request(key)
-- end
-- end
-- end
@@ -252,10 +255,10 @@ end
local og_ISHealthPanel_getDamagedParts = ISHealthPanel.getDamagedParts
function ISHealthPanel:getDamagedParts()
-- TODO Overriding it is a lot easier, but ew
if isReady then
-- 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
return og_ISHealthPanel_getDamagedParts(self)
elseif isReady then
local result = {}
local bodyParts = self:getPatient():getBodyDamage():getBodyParts()
if isClient() and not self:getPatient():isLocalPlayer() then
@@ -274,8 +277,5 @@ function ISHealthPanel:getDamagedParts()
end
end
return result
else
return og_ISHealthPanel_getDamagedParts(self)
end
end