-- Fix issue SET_AIRBASE does not update #817.

This commit is contained in:
FlightControl_Master 2018-03-27 15:03:07 +02:00
parent 08cc4e3530
commit e22e7f2c58

View File

@ -152,13 +152,15 @@ function SET_BASE:Remove( ObjectName )
local Object = self.Set[ObjectName]
self:F3( { ObjectName, Object } )
self:F( { ObjectName, Object } )
if Object then
for Index, Key in ipairs( self.Index ) do
self:F( { Index = Index, Key = Key } )
if Key == ObjectName then
table.remove( self.Index, Index )
self.Set[ObjectName] = nil
self:Flush(self)
break
end
end
@ -3864,7 +3866,7 @@ function SET_AIRBASE:RemoveAirbasesByName( RemoveAirbaseNames )
local RemoveAirbaseNamesArray = ( type( RemoveAirbaseNames ) == "table" ) and RemoveAirbaseNames or { RemoveAirbaseNames }
for RemoveAirbaseID, RemoveAirbaseName in pairs( RemoveAirbaseNamesArray ) do
self:Remove( RemoveAirbaseName.AirbaseName )
self:Remove( RemoveAirbaseName )
end
return self
@ -3926,12 +3928,41 @@ end
function SET_AIRBASE:FilterStart()
if _DATABASE then
self:_FilterStart()
-- We use the BaseCaptured event, which is generated by DCS when a base got captured.
self:HandleEvent( EVENTS.BaseCaptured )
-- We initialize the first set.
for ObjectName, Object in pairs( self.Database ) do
if self:IsIncludeObject( Object ) then
self:Add( ObjectName, Object )
else
self:RemoveAirbasesByName( ObjectName )
end
end
end
return self
end
--- Starts the filtering.
-- @param #SET_AIRBASE self
-- @param Core.Event#EVENT EventData
-- @return #SET_AIRBASE self
function SET_AIRBASE:OnEventBaseCaptured(EventData)
-- When a base got captured, we reevaluate the set.
for ObjectName, Object in pairs( self.Database ) do
if self:IsIncludeObject( Object ) then
-- We add captured bases on yet in the set.
self:Add( ObjectName, Object )
else
-- We remove captured bases that are not anymore part of the set.
self:RemoveAirbasesByName( ObjectName )
end
end
end
--- Handles the Database to check on an event (birth) that the Object was added in the Database.
-- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event!