Renamed variables, code cleanup
This commit is contained in:
+49
-51
@@ -20,18 +20,18 @@
|
||||
["DETAILS_INSTANCE_CHANGEATTRIBUTE"] = {},
|
||||
["DETAILS_INSTANCE_CHANGEMODE"] = {},
|
||||
["DETAILS_INSTANCE_NEWROW"] = {},
|
||||
|
||||
|
||||
--misc
|
||||
["DETAILS_OPTIONS_MODIFIED"] = {},
|
||||
["UNIT_SPEC"] = {},
|
||||
["UNIT_TALENTS"] = {},
|
||||
["PLAYER_TARGET"] = {},
|
||||
["DETAILS_PROFILE_APPLYED"] = {},
|
||||
|
||||
|
||||
--data
|
||||
["DETAILS_DATA_RESET"] = {},
|
||||
["DETAILS_DATA_SEGMENTREMOVED"] = {},
|
||||
|
||||
|
||||
--combat
|
||||
["COMBAT_ENCOUNTER_START"] = {},
|
||||
["COMBAT_ENCOUNTER_END"] = {},
|
||||
@@ -50,18 +50,18 @@
|
||||
["COMBAT_ARENA_END"] = {},
|
||||
["COMBAT_MYTHICDUNGEON_START"] = {},
|
||||
["COMBAT_MYTHICDUNGEON_END"] = {},
|
||||
|
||||
|
||||
--area
|
||||
["ZONE_TYPE_CHANGED"] = {},
|
||||
|
||||
|
||||
--roster
|
||||
["GROUP_ONENTER"] = {},
|
||||
["GROUP_ONLEAVE"] = {},
|
||||
|
||||
|
||||
--buffs
|
||||
["BUFF_UPDATE"] = {},
|
||||
["BUFF_UPDATE_DEBUFFPOWER"] = {},
|
||||
|
||||
|
||||
--network
|
||||
["REALM_CHANNEL_ENTER"] = {}, --deprecated (realm channels are disabled)
|
||||
["REALM_CHANNEL_LEAVE"] = {}, --deprecated
|
||||
@@ -70,7 +70,7 @@
|
||||
}
|
||||
|
||||
local function AlreadyRegistred (_tables, _object)
|
||||
for index, _this_object in ipairs(_tables) do
|
||||
for index, _this_object in ipairs(_tables) do
|
||||
if (_this_object.__eventtable) then
|
||||
if (_this_object [1] == _object) then
|
||||
return index
|
||||
@@ -141,7 +141,7 @@ local common_events = {
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if (common_events [event]) then
|
||||
if (not AlreadyRegistred (_detalhes.RegistredEvents [event], object)) then
|
||||
if (func) then
|
||||
@@ -168,7 +168,7 @@ local common_events = {
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
elseif (event == "BUFF_UPDATE_DEBUFFPOWER") then
|
||||
if (not AlreadyRegistred (_detalhes.RegistredEvents ["BUFF_UPDATE_DEBUFFPOWER"], object)) then
|
||||
if (func) then
|
||||
@@ -177,7 +177,6 @@ local common_events = {
|
||||
tinsert(_detalhes.RegistredEvents ["BUFF_UPDATE_DEBUFFPOWER"], object)
|
||||
end
|
||||
_detalhes.RecordPlayerAbilityWithBuffs = true
|
||||
_detalhes:UpdateDamageAbilityGears()
|
||||
_detalhes:UpdateParserGears()
|
||||
return true
|
||||
else
|
||||
@@ -191,7 +190,7 @@ local common_events = {
|
||||
--Unregister a Event
|
||||
|
||||
function _detalhes:UnregisterEvent (object, event)
|
||||
|
||||
|
||||
if (not _detalhes.RegistredEvents [event]) then
|
||||
if (object.Msg) then
|
||||
object:Msg("(debug) unknown event", event)
|
||||
@@ -200,7 +199,7 @@ local common_events = {
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if (common_events [event]) then
|
||||
local index = AlreadyRegistred (_detalhes.RegistredEvents [event], object)
|
||||
if (index) then
|
||||
@@ -222,14 +221,13 @@ local common_events = {
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
elseif (event == "BUFF_UPDATE_DEBUFFPOWER") then
|
||||
local index = AlreadyRegistred (_detalhes.RegistredEvents ["BUFF_UPDATE_DEBUFFPOWER"], object)
|
||||
if (index) then
|
||||
table.remove (_detalhes.RegistredEvents ["BUFF_UPDATE_DEBUFFPOWER"], index)
|
||||
if (#_detalhes.RegistredEvents ["BUFF_UPDATE_DEBUFFPOWER"] < 1) then
|
||||
_detalhes.RecordPlayerAbilityWithBuffs = false
|
||||
_detalhes:UpdateDamageAbilityGears()
|
||||
_detalhes:UpdateParserGears()
|
||||
end
|
||||
return true
|
||||
@@ -242,11 +240,11 @@ local common_events = {
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--internal functions
|
||||
|
||||
|
||||
local dispatch_error = function(name, errortext)
|
||||
_detalhes:Msg((name or "<no context>"), " |cFFFF9900error|r: ", errortext)
|
||||
end
|
||||
|
||||
|
||||
--safe call an external func with payload and without telling who is calling
|
||||
function _detalhes:QuickDispatchEvent (func, event, ...)
|
||||
if (type(func) ~= "function") then
|
||||
@@ -254,19 +252,19 @@ local common_events = {
|
||||
elseif (type(event) ~= "string") then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local okay, errortext = pcall(func, event, ...)
|
||||
|
||||
|
||||
if (not okay) then
|
||||
--trigger an error msg
|
||||
dispatch_error (_, errortext)
|
||||
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
--quick dispatch with context, send the caller object within the payload
|
||||
function _detalhes:QuickDispatchEventWithContext (context, func, event, ...)
|
||||
if (type(context) ~= "table") then
|
||||
@@ -276,85 +274,85 @@ local common_events = {
|
||||
elseif (type(event) ~= "string") then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local okay, errortext = pcall(func, context, event, ...)
|
||||
|
||||
|
||||
if (not okay) then
|
||||
--attempt to get the context name
|
||||
local objectName = context.__name or context._name or context.name or context.Name
|
||||
--trigger an error msg
|
||||
dispatch_error (objectName, errortext)
|
||||
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--Send Event
|
||||
function _detalhes:SendEvent(event, object, ...)
|
||||
|
||||
|
||||
--send event to all registred plugins
|
||||
|
||||
|
||||
if (event == "PLUGIN_DISABLED" or event == "PLUGIN_ENABLED") then
|
||||
return object:OnDetailsEvent (event, ...)
|
||||
|
||||
|
||||
elseif (not object) then
|
||||
--iterate among all plugins which registered a function for this event
|
||||
for _, PluginObject in ipairs(_detalhes.RegistredEvents[event]) do
|
||||
|
||||
|
||||
--when __eventtable is true, the plugin registered a function or method name to callback
|
||||
--if is false, we call OnDetailsEvent method on the plugin
|
||||
if (PluginObject.__eventtable) then
|
||||
|
||||
--if is false, we call OnDetailsEvent method on the plugin
|
||||
if (PluginObject.__eventtable) then
|
||||
|
||||
local pluginTable = PluginObject [1]
|
||||
|
||||
|
||||
--check if the plugin is enabled
|
||||
if (pluginTable.Enabled and pluginTable.__enabled) then
|
||||
|
||||
|
||||
--check if fegistered a function
|
||||
if (type(PluginObject [2]) == "function") then
|
||||
local func = PluginObject [2]
|
||||
_detalhes:QuickDispatchEvent (func, event, ...)
|
||||
--PluginObject [2] (event, ...)
|
||||
|
||||
|
||||
--if not it must be a method name
|
||||
else
|
||||
local methodName = PluginObject [2]
|
||||
local func = pluginTable [methodName]
|
||||
|
||||
|
||||
_detalhes:QuickDispatchEventWithContext (pluginTable, func, event, ...)
|
||||
--PluginObject [1] [PluginObject [2]] (PluginObject, event, ...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--if no function(only registred the event) sent the event to OnDetailsEvent
|
||||
else
|
||||
else
|
||||
if (PluginObject.Enabled and PluginObject.__enabled) then
|
||||
_detalhes:QuickDispatchEventWithContext (PluginObject, PluginObject.OnDetailsEvent, event, ...)
|
||||
--PluginObject:OnDetailsEvent (event, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--plugin notifications (does not send to listeners)
|
||||
elseif (type(object) == "string" and object == "SEND_TO_ALL") then
|
||||
|
||||
for _, PluginObject in ipairs(_detalhes.RaidTables.Plugins) do
|
||||
|
||||
for _, PluginObject in ipairs(_detalhes.RaidTables.Plugins) do
|
||||
if (PluginObject.__enabled) then
|
||||
_detalhes:QuickDispatchEventWithContext (PluginObject, PluginObject.OnDetailsEvent, event)
|
||||
--PluginObject:OnDetailsEvent (event)
|
||||
end
|
||||
end
|
||||
|
||||
for _, PluginObject in ipairs(_detalhes.SoloTables.Plugins) do
|
||||
|
||||
for _, PluginObject in ipairs(_detalhes.SoloTables.Plugins) do
|
||||
if (PluginObject.__enabled) then
|
||||
_detalhes:QuickDispatchEventWithContext (PluginObject, PluginObject.OnDetailsEvent, event)
|
||||
--PluginObject:OnDetailsEvent (event)
|
||||
end
|
||||
end
|
||||
|
||||
for _, PluginObject in ipairs(_detalhes.ToolBar.Plugins) do
|
||||
|
||||
for _, PluginObject in ipairs(_detalhes.ToolBar.Plugins) do
|
||||
if (PluginObject.__enabled) then
|
||||
_detalhes:QuickDispatchEventWithContext (PluginObject, PluginObject.OnDetailsEvent, event)
|
||||
--PluginObject:OnDetailsEvent (event)
|
||||
@@ -372,9 +370,9 @@ local common_events = {
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--special cases
|
||||
function _detalhes:SendOptionsModifiedEvent (instance)
|
||||
|
||||
|
||||
_detalhes.last_options_modified = _detalhes.last_options_modified or (GetTime() - 5)
|
||||
|
||||
|
||||
if (_detalhes.last_options_modified + 0.3 < GetTime()) then
|
||||
_detalhes:SendEvent("DETAILS_OPTIONS_MODIFIED", nil, instance)
|
||||
_detalhes.last_options_modified = GetTime()
|
||||
@@ -389,20 +387,20 @@ local common_events = {
|
||||
_detalhes.last_options_modified_schedule = _detalhes:ScheduleTimer("SendOptionsModifiedEvent", 0.31, instance)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--listeners
|
||||
|
||||
local listener_meta = setmetatable({}, _detalhes)
|
||||
listener_meta.__index = listener_meta
|
||||
|
||||
|
||||
function listener_meta:RegisterEvent(event, func)
|
||||
return _detalhes:RegisterEvent(self, event, func)
|
||||
end
|
||||
function listener_meta:UnregisterEvent (event)
|
||||
return _detalhes:UnregisterEvent (self, event)
|
||||
end
|
||||
|
||||
|
||||
function _detalhes:CreateEventListener()
|
||||
local new = {Enabled = true, __enabled = true}
|
||||
setmetatable(new, listener_meta)
|
||||
|
||||
Reference in New Issue
Block a user