Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/HP_Compatibility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local function modLooksActive(mod)
if mod.isLoaded ~= nil then return mod.isLoaded == true end
if mod.isActive ~= nil then return mod.isActive == true end
if mod.isSelected ~= nil then return mod.isSelected == true end
return true
return false
end

local function scanLoadedModTable()
Expand Down
35 changes: 27 additions & 8 deletions scripts/HP_IntegrationAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ local function hpApiPrint(message)
print(LOG .. tostring(message))
end

local function isCompatibilityBlocked()
return HP_Compatibility ~= nil and HP_Compatibility:isBlocked()
end

local function normalizeSlot(slot)
if HP_SlotRegistry ~= nil and HP_SlotRegistry.normalise ~= nil then
return HP_SlotRegistry:normalise(slot, HP_SlotRegistry.TARGET_COUNT)
Expand All @@ -23,6 +27,7 @@ local function normalizeSlot(slot)
end

local function getProfiles()
if isCompatibilityBlocked() then return {} end
if HelperProfiles == nil or type(HelperProfiles.getProfiles) ~= "function" then return {} end
local ok, profiles = pcall(HelperProfiles.getProfiles, HelperProfiles)
return ok and type(profiles) == "table" and profiles or {}
Expand Down Expand Up @@ -194,7 +199,8 @@ local function buildApi()
and HP_RosterExpansion:getStatus() or nil

return {
available = true,
available = not isCompatibilityBlocked(),
disabledReason = isCompatibilityBlocked() and HP_Compatibility:getReason() or nil,
apiVersion = self.apiVersion,
modName = self.modName,
modVersion = self.modVersion,
Expand Down Expand Up @@ -256,6 +262,7 @@ local function buildApi()
end

function api:getSlots()
if isCompatibilityBlocked() then return {} end
local profiles = getProfiles()
local slots = {}
for index = 1, getManagedSlotCount(profiles) do
Expand All @@ -267,7 +274,21 @@ local function buildApi()
return api
end

function HP_IntegrationAPI:unpublish()
if g_currentMission ~= nil then
if g_currentMission.helperProfilesAPI == self.api then g_currentMission.helperProfilesAPI = nil end
if g_currentMission.fs25HelperProfilesAPI == self.api then g_currentMission.fs25HelperProfilesAPI = nil end
end
if rawget(_G, "FS25_HelperProfiles_API") == self.api then _G.FS25_HelperProfiles_API = nil end
if rawget(_G, "FS25_HelperProfilesAPI") == self.api then _G.FS25_HelperProfilesAPI = nil end
self.published = false
end

function HP_IntegrationAPI:publish(reason)
if isCompatibilityBlocked() then
self:unpublish()
return false
end
if g_currentMission == nil then return false end
self.api = self.api or buildApi()
self.api.modVersion = self.modVersion
Expand All @@ -294,6 +315,10 @@ end
function HP_IntegrationAPI:loadMap() self:publish("loadMap") end

function HP_IntegrationAPI:update()
if isCompatibilityBlocked() then
self:unpublish()
return
end
if not self.published or g_currentMission == nil
or g_currentMission.helperProfilesAPI ~= self.api
or g_currentMission.fs25HelperProfilesAPI ~= self.api then
Expand All @@ -302,13 +327,7 @@ function HP_IntegrationAPI:update()
end

function HP_IntegrationAPI:deleteMap()
if g_currentMission ~= nil then
if g_currentMission.helperProfilesAPI == self.api then g_currentMission.helperProfilesAPI = nil end
if g_currentMission.fs25HelperProfilesAPI == self.api then g_currentMission.fs25HelperProfilesAPI = nil end
end
if rawget(_G, "FS25_HelperProfiles_API") == self.api then _G.FS25_HelperProfiles_API = nil end
if rawget(_G, "FS25_HelperProfilesAPI") == self.api then _G.FS25_HelperProfilesAPI = nil end
self.published = false
self:unpublish()
end

addModEventListener(HP_IntegrationAPI)
12 changes: 12 additions & 0 deletions scripts/HP_UI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ end
-- ===== Render ================================================================

function HP_UI:render(dtMillis)
if HP_Compatibility ~= nil and HP_Compatibility:isBlocked() then
self.visible = false
self.flashText = nil
self.flashTime = 0
return
end

if self.flashTime ~= nil and self.flashTime > 0 then
local dt = tonumber(dtMillis) or 16
self.flashTime = math.max(0, self.flashTime - dt * 0.001)
Expand Down Expand Up @@ -720,6 +727,11 @@ end
-- ===== Engine hooks ==========================================================

function HP_UI:loadMap()
if HP_Compatibility ~= nil and HP_Compatibility:isBlocked() then
self.visible = false
return
end

if HP_Config ~= nil and HP_Config.read ~= nil and HP_Config.applyToUI ~= nil and HP_Config.init ~= nil then
HP_Config:init()
local config = HP_Config:read()
Expand Down
10 changes: 10 additions & 0 deletions scripts/RegisterPlayerActionEvents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ local function _isHpModifierDown()
or _isPhysicalKeyPressed("KEY_ralt")
end

local function _isCompatibilityBlocked()
return HP_Compatibility ~= nil and HP_Compatibility:isBlocked()
end

local function _onCycle(_, actionName, inputValue, callbackState, isAnalog)
if not _isPress(inputValue, callbackState) then return end
if _isCompatibilityBlocked() then return end

-- GIANTS action bindings are not exclusive: KEY_semicolon can still fire
-- when KEY_shift/KEY_ctrl/KEY_alt + KEY_semicolon is pressed.
Expand All @@ -63,20 +68,23 @@ local function _onCycle(_, actionName, inputValue, callbackState, isAnalog)
end

local function _onToggle(_, actionName, inputValue, callbackState, isAnalog)
if _isCompatibilityBlocked() then return end
if HP_UI and HP_UI.onToggleAction then
HP_UI:onToggleAction(actionName, inputValue, callbackState, isAnalog)
end
end

local function _onMode(_, actionName, inputValue, callbackState, isAnalog)
if not _isPress(inputValue, callbackState) then return end
if _isCompatibilityBlocked() then return end
if HelperProfiles and HelperProfiles.togglePickMode then
HelperProfiles:togglePickMode()
end
end

local function _onAppearanceMenu(_, actionName, inputValue, callbackState, isAnalog)
if not _isPress(inputValue, callbackState) then return end
if _isCompatibilityBlocked() then return end
if HP_AppearanceBindingsGui ~= nil and HP_AppearanceBindingsGui.open ~= nil then
HP_AppearanceBindingsGui:open()
elseif HP_AppearanceMenu ~= nil and HP_AppearanceMenu.toggle ~= nil then
Expand Down Expand Up @@ -120,6 +128,7 @@ local function _unregisterPlayerAction(field, label)
end

local function _registerPlayerActions()
if _isCompatibilityBlocked() then return end
_registerPlayerAction("_playerCycleId", InputAction.OPEN_HELPER_MENU, HelperProfiles, _onCycle, "OPEN_HELPER_MENU")
_registerPlayerAction("_playerToggleId", InputAction.HP_TOGGLE_OVERLAY, HP_UI, _onToggle, "HP_TOGGLE_OVERLAY")
_registerPlayerAction("_playerModeId", InputAction.HP_TOGGLE_MODE, HelperProfiles, _onMode, "HP_TOGGLE_MODE")
Expand Down Expand Up @@ -186,6 +195,7 @@ local function _addVehicleAction(vehicle, spec, inputAction, target, callback, l
end

local function _registerVehicleActions(vehicle, isActiveForInput)
if _isCompatibilityBlocked() then return end
if not isActiveForInput or vehicle == nil or vehicle.addActionEvent == nil then return end
local spec = _ensureVehicleSpec(vehicle)

Expand Down
Loading