added lua check CI step (#49)
Publish Release / build (push) Failing after 3s

Reviewed-on: #49
Co-authored-by: dutchie031 <timrorije@gmail.com>
This commit was merged in pull request #49.
This commit is contained in:
2026-09-20 16:08:04 +00:00
committed by dutchie031
parent 9b2540d461
commit 9549e8c48e
61 changed files with 1058 additions and 881 deletions
+68 -43
View File
@@ -32,7 +32,9 @@ do
---@field OnStageNumberChanged fun(self:OnStageChangedListener, number:integer, laneIdentifier:string?)
do -- STAGE NUMBER CHANGED
---@type Array<OnStageChangedListener>
local OnStageNumberChangedListeners = {}
---@type Array<fun(number:integer, laneIdentifier:string?)>
local OnStageNumberChangedHandlers = {}
---Add a stage zone number changed listener
---@param listener OnStageChangedListener object with function OnStageNumberChanged(self, number, stageLaneIdentifier)
@@ -46,7 +48,8 @@ do
---@class OnStageNumberChangeCompleteListener
---@field OnStageNumberChangeComplete fun(self:OnStageNumberChangeCompleteListener, number:integer, laneIdentifier:string?)
---@type Array<OnStageNumberChangeCompleteListener>
local OnStageNumberChangeCompleteListeners = {}
---@param listener OnStageNumberChangeCompleteListener
SpearheadEvents.AddStageNumberChangeCompleteListener = function(listener)
@@ -65,7 +68,7 @@ do
end)
for _, callable in pairs(OnStageNumberChangedListeners) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnStageNumberChanged(newStageNumber, laneIdentifier)
end)
if err then
@@ -74,14 +77,14 @@ do
end
for _, callable in pairs(OnStageNumberChangedHandlers) do
local succ, err = pcall(callable, newStageNumber, laneIdentifier)
local _, err = pcall(callable, newStageNumber, laneIdentifier)
if err then
logError(err)
end
end
for _, callable in pairs(OnStageNumberChangeCompleteListeners) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnStageNumberChangeComplete(newStageNumber, laneIdentifier)
end)
if err then
@@ -110,9 +113,12 @@ do
table.insert(onWeaponFiredListeners, weaponFiredListener)
end
---@param unit Unit
---@param weapon Weapon
---@param target Unit?
local triggerWeaponFired = function(unit, weapon, target)
for _, callable in pairs(onWeaponFiredListeners) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnWeaponFired(unit, weapon, target)
end)
@@ -121,12 +127,15 @@ do
end
end
end
---@class OnLandEventListener
---@field OnUnitLanded fun(self:OnLandEventListener, initiatorUnit:Unit, airbase:Airbase)
---@type table<string,Array<OnLandEventListener>>
local onLandEventListeners = {}
---Add an event listener to a specific unit
---@param unitName string to call when the unit lands
---@param landListener table table with function OnUnitLanded(self, initiatorUnit, airbase)
---@param landListener OnLandEventListener table with function OnUnitLanded(self, initiatorUnit, airbase)
SpearheadEvents.addOnUnitLandEventListener = function(unitName, landListener)
if type(landListener) ~= "table" then
warn("Event handler not of type table/object")
@@ -162,6 +171,11 @@ do
end
do -- ON RTB
---@class OnGroupRTBListener
---@field OnGroupRTB fun(self:OnGroupRTBListener, groupName:string)
---@type table<string,Array<OnGroupRTBListener>>
local OnGroupRTBListeners = {}
---Adds a function to the events listener that triggers when a group publishes themselves RTB.
---This is only available when a ROUTE is created via the Spearhead.RouteUtil
@@ -186,7 +200,7 @@ do
if groupName ~= nil then
if OnGroupRTBListeners[groupName] then
for _, callable in pairs(OnGroupRTBListeners[groupName]) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnGroupRTB(groupName)
end)
if err then
@@ -197,11 +211,15 @@ do
end
end
---@class OnGroupRTBInTenListener
---@field OnGroupRTBInTen fun(self:OnGroupRTBInTenListener, groupName:string)
---@type table<string,Array<OnGroupRTBInTenListener>>
local OnGroupRTBInTenListeners = {}
---Adds a function to the events listener that triggers when a group publishes themselves RTB.
---This is only available when a ROUTE is created via the Spearhead.RouteUtil
---@param groupName string the groupname to expect
---@param handlingObject table object with OnGroupRTBInTen(self, groupName)
---@param handlingObject OnGroupRTBInTenListener object with OnGroupRTBInTen(self, groupName)
SpearheadEvents.addOnGroupRTBInTenListener = function(groupName, handlingObject)
if type(handlingObject) ~= "table" then
warn("Event handler not of type table/object")
@@ -221,7 +239,7 @@ do
if groupName ~= nil then
if OnGroupRTBInTenListeners[groupName] then
for _, callable in pairs(OnGroupRTBInTenListeners[groupName]) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnGroupRTBInTen(groupName)
end)
if err then
@@ -234,10 +252,17 @@ do
end
do -- ON Station
---@class OnGroupOnStationListener
---@field OnGroupOnStation fun(self:OnGroupOnStationListener, groupName:string)
---@type table<string,Array<OnGroupOnStationListener>>
local OnGroupOnStationListeners = {}
---Adds a function to the events listener that triggers when a group publishes themselves RTB.
---This is only available when a ROUTE is created via the Spearhead.RouteUtil
---@param groupName string the groupname to expect
---@param handlingObject OnGroupOnStationListener object with OnGroupOnStation(self, groupName)
SpearheadEvents.addOnGroupOnStationListener = function(groupName, handlingObject)
if type(handlingObject) ~= "table" then
warn("Event handler not of type table/object")
@@ -257,7 +282,7 @@ do
if groupName ~= nil then
if OnGroupOnStationListeners[groupName] then
for _, callable in pairs(OnGroupOnStationListeners[groupName]) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnGroupOnStation(groupName)
end)
if err then
@@ -270,15 +295,18 @@ do
end
do -- PLAYER ENTER UNIT
---@class OnPlayerEnterUnitListener
---@field OnPlayerEntersUnit fun(self:OnPlayerEnterUnitListener, unit:Unit)
---@type Array<OnPlayerEnterUnitListener>
local playerEnterUnitListeners = {}
---comment
---@param listener table object with OnPlayerEntersUnit(self, unit)
---@param listener OnPlayerEnterUnitListener object with OnPlayerEntersUnit(self, unit)
SpearheadEvents.AddOnPlayerEnterUnitListener = function(listener)
if type(listener) ~= "table" then
warn("Unit lost Event listener not of type table/object")
return
end
table.insert(playerEnterUnitListeners, listener)
end
@@ -286,7 +314,7 @@ do
if unit ~= nil then
if playerEnterUnitListeners then
for _, callable in pairs(playerEnterUnitListeners) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnPlayerEntersUnit(unit)
end)
if err then
@@ -299,7 +327,7 @@ do
end
do -- Ejection events
local unitEjectListeners = {}
SpearheadEvents.AddOnUnitEjectedListener = function(listener)
if type(listener) ~= "table" then
@@ -315,13 +343,13 @@ do
local e = {}
function e:onEvent(event)
if event.id == world.event.S_EVENT_LAND or event.id == world.event.S_EVENT_RUNWAY_TOUCH then
local unit = event.initiator
local airbase = event.place
local unit = event.initiator --[[@as Unit]]
local airbase = event.place --[[@as Airbase]]
if unit ~= nil then
local name = unit:getName()
if onLandEventListeners[name] then
for _, callable in pairs(onLandEventListeners[name]) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnUnitLanded(unit, airbase)
end)
if err then
@@ -336,15 +364,15 @@ do
event.id == world.event.S_EVENT_CRASH or
event.id == world.event.S_EVENT_EJECTION or
event.id == world.event.S_EVENT_UNIT_LOST then
local object = event.initiator
local object = event.initiator --[[@as Unit]]
if object and object.getName then
logDebug("Receiving death event from: " .. object:getName())
end
if object and object.getName and OnUnitLostListeners[object:getName()] then
for _, callable in pairs(OnUnitLostListeners[object:getName()]) do
local succ, err = pcall(function()
local _, err = pcall(function()
callable:OnUnitLost(object)
end)
@@ -355,15 +383,11 @@ do
end
end
if event.id == world.event.S_EVENT_EJECTION then
end
if event.id == world.event.S_EVENT_SHOT then
local shooter = event.initiator
local weapon = event.weapon
local target = event.target
local shooter = event.initiator --[[@as Unit]]
local weapon = event.weapon --[[@as Weapon]]
local target = event.target --[[@as Unit?]]
triggerWeaponFired(shooter, weapon, target)
end
@@ -372,28 +396,32 @@ do
Persistence.UpdateNow()
end
---@type table<string, boolean>
local AI_GROUPS = {}
local function CheckAndTriggerSpawnAsync(unit, time)
local function isPlayer(unit)
if unit == nil then return false, "unit is nil" end
if unit.getGroup == nil then return false, 'no get group function in unit object, most likely static' end
if Object.getCategory(unit) ~= Object.Category.UNIT then
---@param unit Unit
---@param _ any
local function CheckAndTriggerSpawnAsync(unit, _)
---@param checkUnit Unit
---@return boolean, string?
local function isPlayer(checkUnit)
if checkUnit == nil then return false, "unit is nil" end
if checkUnit.getGroup == nil then return false, 'no get group function in unit object, most likely static' end
if Object.getCategory(checkUnit) ~= Object.Category.UNIT then
return false, "object is not a unit"
end
if unit:isExist() ~= true then return false, "unit does not exist" end
local group = unit:getGroup()
if checkUnit:isExist() ~= true then return false, "unit does not exist" end
local group = checkUnit:getGroup()
if group ~= nil then
if AI_GROUPS[group:getName()] == true then
return false
end
local players = DcsUtil.getAllPlayerUnits()
local unitName = unit:getName()
for i, unit in pairs(players) do
if unit:getName() == unitName then
local unitName = checkUnit:getName()
for _, playerUnit in pairs(players) do
if playerUnit:getName() == unitName then
return true
end
end
@@ -403,11 +431,8 @@ do
end
if isPlayer(unit) == true then
local groupId = unit:getGroup():getID()
SpearheadEvents.TriggerPlayerEntersUnit(unit)
end
return nil
end
if event.id == world.event.S_EVENT_BIRTH then