fixed nil pointer issue
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
|
||||
local SpearheadEvents = {}
|
||||
do
|
||||
local SpearheadLogger = Spearhead.LoggerTemplate:new("Spearhead Events",
|
||||
Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
||||
|
||||
do -- STAGE NUMBER CHANGED
|
||||
local OnStageNumberChangedListeners = {}
|
||||
local OnStageNumberChangedHandlers = {}
|
||||
@@ -48,18 +45,24 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
local warn = function(text)
|
||||
env.warn("[Spearhead][Events] " .. (text or "nil"))
|
||||
end
|
||||
|
||||
local error = function(text)
|
||||
env.error("[Spearhead][Events] " .. (text or "nil"))
|
||||
end
|
||||
|
||||
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)
|
||||
SpearheadEvents.addOnUnitLandEventListener = function(unitName, landListener)
|
||||
if type(landListener) ~= "table" then
|
||||
SpearheadLogger:warn("Event handler not of type table/object")
|
||||
warn("Event handler not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
SpearheadLogger:debug("Added Land event handler for unit: " .. unitName)
|
||||
|
||||
if onLandEventListeners[unitName] == nil then
|
||||
onLandEventListeners[unitName] = {}
|
||||
end
|
||||
@@ -92,7 +95,7 @@ do
|
||||
---@param handlingObject table object with OnGroupRTB(self, groupName)
|
||||
SpearheadEvents.addOnGroupRTBListener = function(groupName, handlingObject)
|
||||
if type(handlingObject) ~= "table" then
|
||||
SpearheadLogger:warn("Event handler not of type table/object")
|
||||
warn("Event handler not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -106,7 +109,6 @@ do
|
||||
---Publish the Group to RTB
|
||||
---@param groupName string
|
||||
SpearheadEvents.PublishRTB = function(groupName)
|
||||
SpearheadLogger:debug("Publishing RTB event for group " .. groupName)
|
||||
if groupName ~= nil then
|
||||
if OnGroupRTBListeners[groupName] then
|
||||
for _, callable in pairs(OnGroupRTBListeners[groupName]) do
|
||||
@@ -114,7 +116,7 @@ do
|
||||
callable:OnGroupRTB(groupName)
|
||||
end)
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -128,7 +130,7 @@ do
|
||||
---@param handlingObject table object with OnGroupRTBInTen(self, groupName)
|
||||
SpearheadEvents.addOnGroupRTBInTenListener = function(groupName, handlingObject)
|
||||
if type(handlingObject) ~= "table" then
|
||||
SpearheadLogger:warn("Event handler not of type table/object")
|
||||
warn("Event handler not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -142,7 +144,6 @@ do
|
||||
---Publish the Group is RTB
|
||||
---@param groupName string
|
||||
SpearheadEvents.PublishRTBInTen = function(groupName)
|
||||
SpearheadLogger:debug("Publishing RTB in TEN event for group " .. groupName)
|
||||
if groupName ~= nil then
|
||||
if OnGroupRTBInTenListeners[groupName] then
|
||||
for _, callable in pairs(OnGroupRTBInTenListeners[groupName]) do
|
||||
@@ -150,7 +151,7 @@ do
|
||||
callable:OnGroupRTBInTen(groupName)
|
||||
end)
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -165,7 +166,7 @@ do
|
||||
---@param groupName string the groupname to expect
|
||||
SpearheadEvents.addOnGroupOnStationListener = function(groupName, handlingObject)
|
||||
if type(handlingObject) ~= "table" then
|
||||
SpearheadLogger:warn("Event handler not of type table/object")
|
||||
warn("Event handler not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -179,7 +180,6 @@ do
|
||||
---Publish the Group to RTB
|
||||
---@param groupName string
|
||||
SpearheadEvents.PublishOnStation = function(groupName)
|
||||
SpearheadLogger:debug("Publishing onStation event for group " .. groupName)
|
||||
if groupName ~= nil then
|
||||
if OnGroupOnStationListeners[groupName] then
|
||||
for _, callable in pairs(OnGroupOnStationListeners[groupName]) do
|
||||
@@ -187,7 +187,7 @@ do
|
||||
callable:OnGroupOnStation(groupName)
|
||||
end)
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -202,7 +202,7 @@ do
|
||||
---@param listener table object with OnStatusRequestReceived(self, groupId)
|
||||
SpearheadEvents.AddOnStatusRequestReceivedListener = function(listener)
|
||||
if type(listener) ~= "table" then
|
||||
SpearheadLogger:warn("Unit lost Event listener not of type table/object")
|
||||
warn("Unit lost Event listener not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -234,7 +234,7 @@ do
|
||||
---@param listener table object with OnPlayerEnterUnit(self, unit)
|
||||
SpearheadEvents.AddOnPlayerEnterUnitListener = function(listener)
|
||||
if type(listener) ~= "table" then
|
||||
SpearheadLogger:warn("Unit lost Event listener not of type table/object")
|
||||
warn("Unit lost Event listener not of type table/object")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -249,7 +249,7 @@ do
|
||||
callable:OnPlayerEnterUnit(unit)
|
||||
end)
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -270,7 +270,7 @@ do
|
||||
callable:OnUnitLanded(unit, airbase)
|
||||
end)
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -289,7 +289,7 @@ do
|
||||
end)
|
||||
|
||||
if err then
|
||||
SpearheadLogger:error(err)
|
||||
error(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user