Updated wiring of supply hub commands

This commit is contained in:
2026-08-15 15:04:44 +00:00
committed by dutchie031
parent bb9144e3a0
commit 9e4a8a1876
5 changed files with 44 additions and 36 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ SpearheadConfig = {
--- The time briefings should be displayed by default.
--- Players can always "Clear Messages" through the F10 menu, so setting it to a high value can be
briefingMessageDuration = 30, --default 30
briefingMessageDuration = 60, --default 60
CapConfig = {
--quickly enable of disable the entire CAP Logic
+1 -1
View File
@@ -25,7 +25,7 @@ function GlobalConfig.New()
end
function GlobalConfig:getBriefingTime()
return self._briefingTime or 30
return self._briefingTime or 60
end
@@ -14,7 +14,6 @@ local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHel
---@field updateContinuous fun(self: MissionCommandsHelper, time: number): number @function to update commands continuously
---@field pinnedByGroup table<string, Mission> @table of pinned missions by group ID
---@field private _stageBriefings table<string, string> @table of stage briefings by stage name
---@field private _supplyHubGroups table<string, boolean> @table of supply hub groups by their ID
---@field private _logger Logger @logger instance for logging
---@field private _supplyUnitsTracker SupplyUnitsTracker @supply units tracker instance
local MissionCommandsHelper = {}
@@ -49,11 +48,28 @@ function MissionCommandsHelper.getOrCreate(logLevel)
instance.updateNeeded = false
instance.pinnedByGroup = {}
instance.lastUpdate = 0
instance._supplyHubGroups = {}
instance._stageBriefings = {}
instance._supplyUnitsTracker = SupplyUnitsTracker.getOrCreate(logLevel)
instance._supplyUnitsTracker:AddOnSupplyUnitEventListener(
{
enteredSupplyHub = function(self, unit)
if unit == nil then return end
instance.updateNeeded = true
instance:updateCommandsForGroup(unit:getGroup():getID())
end,
exitedSupplyHub = function(self, unit)
instance.updateNeeded = true
instance:updateCommandsForGroup(unit:getGroup():getID())
end,
supplyUnitSpawned = function(self, unit)
instance.updateNeeded = true
instance:updateCommandsForGroup(unit:getGroup():getID())
end
}
)
---comment
---@param selfA MissionCommandsHelper
---@param time number
@@ -108,32 +124,6 @@ function MissionCommandsHelper:RemoveMissionToCommands(mission)
self.updateNeeded = true
end
---@param groupID number
function MissionCommandsHelper:MarkUnitInSupplyHub(groupID)
self._logger:debug("Marking unit in supply hub: " .. tostring(groupID))
local updateNeeded = false
if self._supplyHubGroups[tostring(groupID)] ~= true then
updateNeeded = true
end
self._supplyHubGroups[tostring(groupID)] = true
if updateNeeded == true then self:updateCommandsForGroup(groupID) end
end
---@param groupID number
function MissionCommandsHelper:MarkUnitOutsideSupplyHub(groupID)
self._logger:debug("Marking unit outide supply hub: " .. tostring(groupID))
local updateNeeded = false
if self._supplyHubGroups[tostring(groupID)] == true then
updateNeeded = true
end
self._supplyHubGroups[tostring(groupID)] = false
if updateNeeded == true then self:updateCommandsForGroup(groupID) end
end
---@param unit Unit
function MissionCommandsHelper:OnPlayerEntersUnit(unit)
@@ -438,7 +428,7 @@ end
---@param groupID integer
function MissionCommandsHelper:AddSupplyHubCommandsIfApplicable(groupID)
if self._supplyHubGroups[tostring(groupID)] ~= true then return end
if self._supplyUnitsTracker:IsGroupLeadInSupplyHub(groupID) ~= true then return end
self._logger:debug("Adding supply hub commands for group: " .. tostring(groupID))
@@ -536,8 +526,7 @@ function MissionCommandsHelper:addMissionFolders(groupId)
missionCommands.addSubMenuForGroup(groupId, folderNames.primary)
missionCommands.addSubMenuForGroup(groupId, folderNames.secondary)
if self._supplyHubGroups[tostring(groupId)] == true then
self._logger:debug("Adding supply hub commands folder for group: " .. tostring(groupId))
if self._supplyUnitsTracker:IsGroupLeadInSupplyHub(groupId) == true then
missionCommands.addSubMenuForGroup(groupId, folderNames.supplyHub)
end
@@ -94,7 +94,7 @@ end
---@param listener SupplyUnitEventListener
function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
function SupplyUnitsTracker:AddOnSupplyUnitEventListener(listener)
if listener == nil then return end
if self._supplyUnitEventsListeners == nil then
@@ -104,6 +104,26 @@ function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
table.insert(self._supplyUnitEventsListeners, listener)
end
---@param unit Unit
---@return boolean
function SupplyUnitsTracker:IsUnitInSupplyHub(unit)
if unit == nil then return false end
local unitIDStr = tostring(unit:getID())
return self._unitInSupplyHub[unitIDStr] == true
end
---@param groupID number
---@return boolean
function SupplyUnitsTracker:IsGroupLeadInSupplyHub(groupID)
local group = DcsUtil.GetPlayerGroupByGroupID(groupID)
if group == nil then return false end
local unit = group:getUnit(1)
if unit == nil then return false end
return self:IsUnitInSupplyHub(unit)
end
function SupplyUnitsTracker:Update()
local players = DcsUtil.getAllPlayerUnits()
for _, player in pairs(players) do
@@ -211,7 +231,6 @@ function SupplyUnitsTracker:CheckUnitsInZones()
if Util.is3dPointInZone(pos, zone) then
if self._unitInSupplyHub[tostring(unit:getID())] ~= true then
self._unitInSupplyHub[tostring(unit:getID())] = true
for _, listener in pairs(self._supplyUnitEventsListeners) do
pcall(function()
if listener.enteredSupplyHub then
@@ -197,7 +197,7 @@ function BuildableMission:SpawnActive()
self._state = "ACTIVE"
self._missionCommandsHelper:AddMissionToCommands(self)
self._supplyUnitsTracker:AddOnSupplyUnitSpawnedListener(self)
self._supplyUnitsTracker:AddOnSupplyUnitEventListener(self)
local units = self._supplyUnitsTracker:GetUnits()
if units then