mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Event fix, version 1 pre-alpha test version...
This commit is contained in:
parent
73d1b3b439
commit
553435bbcb
@ -429,7 +429,7 @@ function EVENT:Init( EventID, EventClass )
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not self.Events[EventID][EventPriority][EventClass] then
|
if not self.Events[EventID][EventPriority][EventClass] then
|
||||||
self.Events[EventID][EventPriority][EventClass] = setmetatable( {}, { __mode = "v" } )
|
self.Events[EventID][EventPriority][EventClass] = {}
|
||||||
end
|
end
|
||||||
return self.Events[EventID][EventPriority][EventClass]
|
return self.Events[EventID][EventPriority][EventClass]
|
||||||
end
|
end
|
||||||
@ -449,32 +449,30 @@ end
|
|||||||
|
|
||||||
--- Removes an Events entry for a UNIT.
|
--- Removes an Events entry for a UNIT.
|
||||||
-- @param #EVENT self
|
-- @param #EVENT self
|
||||||
-- @param #string UnitName The name of the UNIT.
|
|
||||||
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
|
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
|
||||||
-- @param Dcs.DCSWorld#world.event EventID
|
-- @param Dcs.DCSWorld#world.event EventID
|
||||||
-- @return #EVENT.Events
|
-- @return #EVENT.Events
|
||||||
function EVENT:RemoveForUnit( UnitName, EventClass, EventID )
|
function EVENT:RemoveForUnit( EventClass, EventID )
|
||||||
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
|
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
|
||||||
|
|
||||||
local EventClass = EventClass
|
local EventClass = EventClass
|
||||||
local EventPriority = EventClass:GetEventPriority()
|
local EventPriority = EventClass:GetEventPriority()
|
||||||
local Event = self.Events[EventID][EventPriority][EventClass]
|
local Event = self.Events[EventID][EventPriority][EventClass]
|
||||||
Event.EventUnit[UnitName] = nil
|
Event.EventUnit = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Removes an Events entry for a GROUP.
|
--- Removes an Events entry for a GROUP.
|
||||||
-- @param #EVENT self
|
-- @param #EVENT self
|
||||||
-- @param #string GroupName The name of the GROUP.
|
|
||||||
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
|
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
|
||||||
-- @param Dcs.DCSWorld#world.event EventID
|
-- @param Dcs.DCSWorld#world.event EventID
|
||||||
-- @return #EVENT.Events
|
-- @return #EVENT.Events
|
||||||
function EVENT:RemoveForGroup( GroupName, EventClass, EventID )
|
function EVENT:RemoveForGroup( EventClass, EventID )
|
||||||
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
|
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
|
||||||
|
|
||||||
local EventClass = EventClass
|
local EventClass = EventClass
|
||||||
local EventPriority = EventClass:GetEventPriority()
|
local EventPriority = EventClass:GetEventPriority()
|
||||||
local Event = self.Events[EventID][EventPriority][EventClass]
|
local Event = self.Events[EventID][EventPriority][EventClass]
|
||||||
Event.EventGroup[GroupName] = nil
|
Event.EventGroup = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Clears all event subscriptions for a @{Base#BASE} derived object.
|
--- Clears all event subscriptions for a @{Base#BASE} derived object.
|
||||||
@ -519,7 +517,6 @@ function EVENT:OnEventGeneric( EventFunction, EventClass, EventID )
|
|||||||
|
|
||||||
local EventData = self:Init( EventID, EventClass )
|
local EventData = self:Init( EventID, EventClass )
|
||||||
EventData.EventFunction = EventFunction
|
EventData.EventFunction = EventFunction
|
||||||
EventData.EventClass = EventClass
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -536,12 +533,8 @@ function EVENT:OnEventForUnit( UnitName, EventFunction, EventClass, EventID )
|
|||||||
self:F2( UnitName )
|
self:F2( UnitName )
|
||||||
|
|
||||||
local EventData = self:Init( EventID, EventClass )
|
local EventData = self:Init( EventID, EventClass )
|
||||||
if not EventData.EventUnit then
|
EventData.EventUnit = true
|
||||||
EventData.EventUnit = {}
|
EventData.EventFunction = EventFunction
|
||||||
end
|
|
||||||
EventData.EventUnit[UnitName] = {}
|
|
||||||
EventData.EventUnit[UnitName].EventFunction = EventFunction
|
|
||||||
EventData.EventUnit[UnitName].EventClass = EventClass
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -556,12 +549,8 @@ function EVENT:OnEventForGroup( GroupName, EventFunction, EventClass, EventID )
|
|||||||
self:F2( GroupName )
|
self:F2( GroupName )
|
||||||
|
|
||||||
local Event = self:Init( EventID, EventClass )
|
local Event = self:Init( EventID, EventClass )
|
||||||
if not Event.EventGroup then
|
Event.EventGroup = true
|
||||||
Event.EventGroup = {}
|
Event.EventFunction = EventFunction
|
||||||
end
|
|
||||||
Event.EventGroup[GroupName] = {}
|
|
||||||
Event.EventGroup[GroupName].EventFunction = EventFunction
|
|
||||||
Event.EventGroup[GroupName].EventClass = EventClass
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -810,167 +799,72 @@ function EVENT:onEvent( Event )
|
|||||||
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
|
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
|
||||||
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
|
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
|
||||||
|
|
||||||
|
self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } )
|
||||||
|
|
||||||
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
|
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
|
||||||
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
|
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
|
||||||
|
|
||||||
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
|
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
|
||||||
if ( Event.IniDCSUnitName and EventData.EventUnit and EventData.EventUnit[Event.IniDCSUnitName] ) or
|
if ( Event.IniDCSUnitName and EventData.EventUnit ) or
|
||||||
( Event.TgtDCSUnitName and EventData.EventUnit and EventData.EventUnit[Event.TgtDCSUnitName] ) then
|
( Event.TgtDCSUnitName and EventData.EventUnit ) then
|
||||||
|
|
||||||
if EventData.EventUnit[Event.IniDCSUnitName] then
|
local UnitName = EventClass:GetName()
|
||||||
|
if UnitName then
|
||||||
|
if UnitName == Event.IniDCSUnitName or UnitName == Event.TgtDCSUnitName then
|
||||||
|
-- First test if a EventFunction is Set, otherwise search for the default function
|
||||||
|
if EventData.EventFunction then
|
||||||
|
|
||||||
-- First test if a EventFunction is Set, otherwise search for the default function
|
|
||||||
if EventData.EventUnit[Event.IniDCSUnitName].EventFunction then
|
|
||||||
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
|
||||||
self:E( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
|
|
||||||
end
|
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
|
||||||
function()
|
|
||||||
return EventData.EventUnit[Event.IniDCSUnitName].EventFunction( EventClass, Event )
|
|
||||||
end, ErrorHandler )
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
|
||||||
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
|
|
||||||
if EventFunction and type( EventFunction ) == "function" then
|
|
||||||
|
|
||||||
-- Now call the default event function.
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
if Event.IniObjectCategory ~= 3 then
|
||||||
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
self:E( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
|
||||||
end
|
end
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
local Result, Value = xpcall(
|
||||||
function()
|
function()
|
||||||
return EventFunction( EventClass, Event )
|
return EventData.EventFunction( EventClass, Event )
|
||||||
end, ErrorHandler )
|
end, ErrorHandler )
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if EventData.EventUnit[Event.TgtDCSUnitName] then
|
else
|
||||||
|
|
||||||
-- First test if a EventFunction is Set, otherwise search for the default function
|
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
||||||
if EventData.EventUnit[Event.TgtDCSUnitName].EventFunction then
|
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
|
||||||
|
if EventFunction and type( EventFunction ) == "function" then
|
||||||
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
-- Now call the default event function.
|
||||||
self:E( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.TgtUnitName, EventPriority } )
|
if Event.IniObjectCategory ~= 3 then
|
||||||
end
|
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
||||||
|
end
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
local Result, Value = xpcall(
|
||||||
function()
|
function()
|
||||||
return EventData.EventUnit[Event.TgtDCSUnitName].EventFunction( EventClass, Event )
|
return EventFunction( EventClass, Event )
|
||||||
end, ErrorHandler )
|
end, ErrorHandler )
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
|
||||||
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
|
|
||||||
if EventFunction and type( EventFunction ) == "function" then
|
|
||||||
|
|
||||||
-- Now call the default event function.
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
|
||||||
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
|
||||||
function()
|
|
||||||
return EventFunction( EventClass, Event )
|
|
||||||
end, ErrorHandler )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
self:RemoveForUnit( EventClass, Event.id )
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
|
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
|
||||||
if ( Event.IniDCSUnitName and Event.IniDCSGroupName and Event.IniGroupName and EventData.EventGroup and EventData.EventGroup[Event.IniGroupName] ) or
|
if ( Event.IniDCSUnitName and Event.IniDCSGroupName and Event.IniGroupName and EventData.EventGroup ) or
|
||||||
( Event.TgtDCSUnitName and Event.TgtDCSGroupName and Event.TgtGroupName and EventData.EventGroup and EventData.EventGroup[Event.TgtGroupName] ) then
|
( Event.TgtDCSUnitName and Event.TgtDCSGroupName and Event.TgtGroupName and EventData.EventGroup ) then
|
||||||
|
|
||||||
if EventData.EventGroup[Event.IniGroupName] then
|
|
||||||
-- First test if a EventFunction is Set, otherwise search for the default function
|
|
||||||
if EventData.EventGroup[Event.IniGroupName].EventFunction then
|
|
||||||
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
|
||||||
self:E( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
|
|
||||||
end
|
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
|
||||||
function()
|
|
||||||
return EventData.EventGroup[Event.IniGroupName].EventFunction( EventClass, Event )
|
|
||||||
end, ErrorHandler )
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
|
||||||
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
|
|
||||||
if EventFunction and type( EventFunction ) == "function" then
|
|
||||||
|
|
||||||
-- Now call the default event function.
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
|
||||||
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
|
|
||||||
end
|
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
|
||||||
function()
|
|
||||||
return EventFunction( EventClass, Event )
|
|
||||||
end, ErrorHandler )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if EventData.EventGroup[Event.TgtGroupName] then
|
|
||||||
if EventData.EventGroup[Event.TgtGroupName].EventFunction then
|
|
||||||
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
|
||||||
self:E( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.TgtUnitName, EventPriority } )
|
|
||||||
end
|
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
|
||||||
function()
|
|
||||||
return EventData.EventGroup[Event.TgtGroupName].EventFunction( EventClass, Event )
|
|
||||||
end, ErrorHandler )
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
|
||||||
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
|
|
||||||
if EventFunction and type( EventFunction ) == "function" then
|
|
||||||
|
|
||||||
-- Now call the default event function.
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
|
||||||
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
|
|
||||||
end
|
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
|
||||||
function()
|
|
||||||
return EventFunction( EventClass, Event )
|
|
||||||
end, ErrorHandler )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
-- If the EventData is not bound to a specific unit, then call the EventClass EventFunction.
|
|
||||||
-- Note that here the EventFunction will need to implement and determine the logic for the relevant source- or target unit, or weapon.
|
|
||||||
if (Event.IniDCSUnit or Event.WeaponUNIT) and not EventData.EventUnit then
|
|
||||||
|
|
||||||
if EventClass == EventData.EventClass then
|
|
||||||
|
|
||||||
|
local GroupName = EventClass:GetName()
|
||||||
|
if GroupName then
|
||||||
|
if GroupName == Event.IniDCSGroupName or GroupName == Event.TgtDCSGroupName then
|
||||||
-- First test if a EventFunction is Set, otherwise search for the default function
|
-- First test if a EventFunction is Set, otherwise search for the default function
|
||||||
if EventData.EventFunction then
|
if EventData.EventFunction then
|
||||||
|
|
||||||
-- There is an EventFunction defined, so call the EventFunction.
|
|
||||||
if Event.IniObjectCategory ~= 3 then
|
if Event.IniObjectCategory ~= 3 then
|
||||||
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
self:E( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
|
||||||
end
|
end
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
local Result, Value = xpcall(
|
||||||
function()
|
function()
|
||||||
return EventData.EventFunction( EventClass, Event )
|
return EventData.EventFunction( EventClass, Event )
|
||||||
end, ErrorHandler )
|
end, ErrorHandler )
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
||||||
@ -979,17 +873,55 @@ function EVENT:onEvent( Event )
|
|||||||
|
|
||||||
-- Now call the default event function.
|
-- Now call the default event function.
|
||||||
if Event.IniObjectCategory ~= 3 then
|
if Event.IniObjectCategory ~= 3 then
|
||||||
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
|
||||||
end
|
end
|
||||||
|
|
||||||
local Result, Value = xpcall(
|
local Result, Value = xpcall(
|
||||||
function()
|
function()
|
||||||
local Result, Value = EventFunction( EventClass, Event )
|
return EventFunction( EventClass, Event )
|
||||||
return Result, Value
|
|
||||||
end, ErrorHandler )
|
end, ErrorHandler )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
self:RemoveForGroup( EventClass, Event.id )
|
||||||
|
end
|
||||||
|
else
|
||||||
|
|
||||||
|
-- If the EventData is not bound to a specific unit, then call the EventClass EventFunction.
|
||||||
|
-- Note that here the EventFunction will need to implement and determine the logic for the relevant source- or target unit, or weapon.
|
||||||
|
if (Event.IniDCSUnit or Event.WeaponUNIT) and not EventData.EventUnit then
|
||||||
|
|
||||||
|
-- First test if a EventFunction is Set, otherwise search for the default function
|
||||||
|
if EventData.EventFunction then
|
||||||
|
|
||||||
|
-- There is an EventFunction defined, so call the EventFunction.
|
||||||
|
if Event.IniObjectCategory ~= 3 then
|
||||||
|
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
||||||
|
end
|
||||||
|
local Result, Value = xpcall(
|
||||||
|
function()
|
||||||
|
return EventData.EventFunction( EventClass, Event )
|
||||||
|
end, ErrorHandler )
|
||||||
|
else
|
||||||
|
|
||||||
|
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
|
||||||
|
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
|
||||||
|
if EventFunction and type( EventFunction ) == "function" then
|
||||||
|
|
||||||
|
-- Now call the default event function.
|
||||||
|
if Event.IniObjectCategory ~= 3 then
|
||||||
|
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
|
||||||
|
end
|
||||||
|
|
||||||
|
local Result, Value = xpcall(
|
||||||
|
function()
|
||||||
|
local Result, Value = EventFunction( EventClass, Event )
|
||||||
|
return Result, Value
|
||||||
|
end, ErrorHandler )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
|
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20170405_0934' )
|
env.info( 'Moose Generation Timestamp: 20170410_0953' )
|
||||||
|
|
||||||
local base = _G
|
local base = _G
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user