supplyHub Commands wiring and event triggers wired for more real time updates #15
+1
-1
@@ -6,7 +6,7 @@ SpearheadConfig = {
|
|||||||
|
|
||||||
--- The time briefings should be displayed by default.
|
--- 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
|
--- 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 = {
|
CapConfig = {
|
||||||
--quickly enable of disable the entire CAP Logic
|
--quickly enable of disable the entire CAP Logic
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function GlobalConfig.New()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function GlobalConfig:getBriefingTime()
|
function GlobalConfig:getBriefingTime()
|
||||||
return self._briefingTime or 30
|
return self._briefingTime or 60
|
||||||
end
|
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 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 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 _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 _logger Logger @logger instance for logging
|
||||||
---@field private _supplyUnitsTracker SupplyUnitsTracker @supply units tracker instance
|
---@field private _supplyUnitsTracker SupplyUnitsTracker @supply units tracker instance
|
||||||
local MissionCommandsHelper = {}
|
local MissionCommandsHelper = {}
|
||||||
@@ -49,11 +48,28 @@ function MissionCommandsHelper.getOrCreate(logLevel)
|
|||||||
instance.updateNeeded = false
|
instance.updateNeeded = false
|
||||||
instance.pinnedByGroup = {}
|
instance.pinnedByGroup = {}
|
||||||
instance.lastUpdate = 0
|
instance.lastUpdate = 0
|
||||||
instance._supplyHubGroups = {}
|
|
||||||
instance._stageBriefings = {}
|
instance._stageBriefings = {}
|
||||||
|
|
||||||
instance._supplyUnitsTracker = SupplyUnitsTracker.getOrCreate(logLevel)
|
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
|
---comment
|
||||||
---@param selfA MissionCommandsHelper
|
---@param selfA MissionCommandsHelper
|
||||||
---@param time number
|
---@param time number
|
||||||
@@ -108,32 +124,6 @@ function MissionCommandsHelper:RemoveMissionToCommands(mission)
|
|||||||
self.updateNeeded = true
|
self.updateNeeded = true
|
||||||
end
|
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
|
---@param unit Unit
|
||||||
function MissionCommandsHelper:OnPlayerEntersUnit(unit)
|
function MissionCommandsHelper:OnPlayerEntersUnit(unit)
|
||||||
@@ -438,7 +428,7 @@ end
|
|||||||
---@param groupID integer
|
---@param groupID integer
|
||||||
function MissionCommandsHelper:AddSupplyHubCommandsIfApplicable(groupID)
|
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))
|
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.primary)
|
||||||
missionCommands.addSubMenuForGroup(groupId, folderNames.secondary)
|
missionCommands.addSubMenuForGroup(groupId, folderNames.secondary)
|
||||||
|
|
||||||
if self._supplyHubGroups[tostring(groupId)] == true then
|
if self._supplyUnitsTracker:IsGroupLeadInSupplyHub(groupId) == true then
|
||||||
self._logger:debug("Adding supply hub commands folder for group: " .. tostring(groupId))
|
|
||||||
missionCommands.addSubMenuForGroup(groupId, folderNames.supplyHub)
|
missionCommands.addSubMenuForGroup(groupId, folderNames.supplyHub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---@param listener SupplyUnitEventListener
|
---@param listener SupplyUnitEventListener
|
||||||
function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
|
function SupplyUnitsTracker:AddOnSupplyUnitEventListener(listener)
|
||||||
if listener == nil then return end
|
if listener == nil then return end
|
||||||
|
|
||||||
if self._supplyUnitEventsListeners == nil then
|
if self._supplyUnitEventsListeners == nil then
|
||||||
@@ -104,6 +104,26 @@ function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
|
|||||||
table.insert(self._supplyUnitEventsListeners, listener)
|
table.insert(self._supplyUnitEventsListeners, listener)
|
||||||
end
|
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()
|
function SupplyUnitsTracker:Update()
|
||||||
local players = DcsUtil.getAllPlayerUnits()
|
local players = DcsUtil.getAllPlayerUnits()
|
||||||
for _, player in pairs(players) do
|
for _, player in pairs(players) do
|
||||||
@@ -211,7 +231,6 @@ function SupplyUnitsTracker:CheckUnitsInZones()
|
|||||||
if Util.is3dPointInZone(pos, zone) then
|
if Util.is3dPointInZone(pos, zone) then
|
||||||
if self._unitInSupplyHub[tostring(unit:getID())] ~= true then
|
if self._unitInSupplyHub[tostring(unit:getID())] ~= true then
|
||||||
self._unitInSupplyHub[tostring(unit:getID())] = true
|
self._unitInSupplyHub[tostring(unit:getID())] = true
|
||||||
|
|
||||||
for _, listener in pairs(self._supplyUnitEventsListeners) do
|
for _, listener in pairs(self._supplyUnitEventsListeners) do
|
||||||
pcall(function()
|
pcall(function()
|
||||||
if listener.enteredSupplyHub then
|
if listener.enteredSupplyHub then
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ function BuildableMission:SpawnActive()
|
|||||||
self._state = "ACTIVE"
|
self._state = "ACTIVE"
|
||||||
|
|
||||||
self._missionCommandsHelper:AddMissionToCommands(self)
|
self._missionCommandsHelper:AddMissionToCommands(self)
|
||||||
self._supplyUnitsTracker:AddOnSupplyUnitSpawnedListener(self)
|
self._supplyUnitsTracker:AddOnSupplyUnitEventListener(self)
|
||||||
|
|
||||||
local units = self._supplyUnitsTracker:GetUnits()
|
local units = self._supplyUnitsTracker:GetUnits()
|
||||||
if units then
|
if units then
|
||||||
|
|||||||
Reference in New Issue
Block a user