From 10cc1138022d562923a6e9ba1fc0e62fa01744c8 Mon Sep 17 00:00:00 2001 From: NoM0Re Date: Thu, 23 Jan 2025 20:33:10 +0100 Subject: [PATCH] from retail --- WeakAuras/GenericTrigger.lua | 109 +++++++++++++++++------------------ WeakAuras/Prototypes.lua | 100 ++++++++++++++++++++++---------- 2 files changed, 121 insertions(+), 88 deletions(-) diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 07c8539..9128158 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -842,18 +842,23 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 return updateTriggerState; end +local function getGameEventFromComposedEvent(composedEvent) + local separatorPosition = composedEvent:find(":", 1, true) + return separatorPosition == nil and composedEvent or composedEvent:sub(1, separatorPosition - 1) +end + function WeakAuras.ScanEvents(event, arg1, arg2, ...) - local orgEvent = event; - Private.StartProfileSystem("generictrigger " .. orgEvent ) + local system = getGameEventFromComposedEvent(event) + Private.StartProfileSystem("generictrigger " .. system) local event_list = loaded_events[event]; if (not event_list) then - Private.StopProfileSystem("generictrigger " .. orgEvent ) + Private.StopProfileSystem("generictrigger " .. system) return end if(event == "COMBAT_LOG_EVENT_UNFILTERED") then event_list = event_list[arg2]; if (not event_list) then - Private.StopProfileSystem("generictrigger " .. orgEvent ) + Private.StopProfileSystem("generictrigger " .. system) return; end WeakAuras.ScanEventsInternal(event_list, event, arg1, arg2, ...); @@ -867,7 +872,7 @@ function WeakAuras.ScanEvents(event, arg1, arg2, ...) else WeakAuras.ScanEventsInternal(event_list, event, arg1, arg2, ...); end - Private.StopProfileSystem("generictrigger " .. orgEvent ) + Private.StopProfileSystem("generictrigger " .. system) end function WeakAuras.ScanUnitEvents(event, unit, ...) @@ -1333,6 +1338,15 @@ function LoadEvent(id, triggernum, data) loaded_events[event][id][triggernum] = data; end end + -- this special internal_events function is run when aura load instead of when it is added + if data.loadInternalEventFunc then + local internal_events = data.loadInternalEventFunc(data.trigger) + for index, event in pairs(internal_events) do + loaded_events[event] = loaded_events[event] or {}; + loaded_events[event][id] = loaded_events[event][id] or {}; + loaded_events[event][id][triggernum] = data; + end + end if data.unit_events then local includePets = data.includePets for unit, events in pairs(data.unit_events) do @@ -1552,7 +1566,7 @@ function GenericTrigger.Add(data, region) local includePets local trigger_subevents = {}; local force_events = false; - local durationFunc, overlayFuncs, nameFunc, iconFunc, textureFunc, stacksFunc, loadFunc; + local durationFunc, overlayFuncs, nameFunc, iconFunc, textureFunc, stacksFunc, loadFunc, loadInternalEventFunc; local tsuConditionVariables; local prototype = nil local automaticAutoHide @@ -1592,6 +1606,7 @@ function GenericTrigger.Add(data, region) textureFunc = prototype.textureFunc; stacksFunc = prototype.stacksFunc; loadFunc = prototype.loadFunc; + loadInternalEventFunc = prototype.loadInternalEventFunc; if (prototype.overlayFuncs) then overlayFuncs = {}; @@ -1795,6 +1810,7 @@ function GenericTrigger.Add(data, region) event = trigger.event, events = trigger_events, internal_events = internal_events, + loadInternalEventFunc = loadInternalEventFunc, force_events = force_events, unit_events = trigger_unit_events, includePets = includePets, @@ -1878,26 +1894,6 @@ do end end -local combatLogUpgrade = { - ["sourceunit"] = "sourceUnit", - ["source"] = "sourceName", - ["destunit"] = "destUnit", - ["dest"] = "destName" -} - -local oldPowerTriggers = { - ["Combo Points"] = 4, - ["Holy Power"] = 9, - ["Insanity"] = 13, - ["Chi Power"] = 12, - ["Astral Power"] = 8, - ["Maelstrom"] = 11, - ["Arcane Charges"] = 16, - ["Fury"] = 17, - ["Pain"] = 18, - ["Shards"] = 7, -} - --############################# --# Support code for triggers # --############################# @@ -2365,7 +2361,7 @@ do end end end - elseif(event == "UNIT_INVENTORY_CHANGED" or event == "BAG_UPDATE_COOLDOWN" or event == "PLAYER_EQUIPMENT_CHANGED") then + elseif(event == "UNIT_INVENTORY_CHANGED" and ... and ... == "player" or event == "BAG_UPDATE_COOLDOWN" or event == "PLAYER_EQUIPMENT_CHANGED") then Private.CheckItemSlotCooldowns(); end Private.StopProfileSystem("generictrigger cd tracking"); @@ -2480,14 +2476,14 @@ do itemCdDurs[id] = nil; itemCdExps[id] = nil; itemCdEnabled[id] = 1; - WeakAuras.ScanEvents("ITEM_COOLDOWN_READY", id); + WeakAuras.ScanEvents("ITEM_COOLDOWN_READY:" .. id, id); end local function ItemSlotCooldownFinished(id) itemSlotsCdHandles[id] = nil; itemSlotsCdDurs[id] = nil; itemSlotsCdExps[id] = nil; - WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_READY", id); + WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_READY:" .. id, id); end function Private.CheckRuneCooldown() @@ -2588,7 +2584,7 @@ do end if changed and not WeakAuras.IsPaused() then - WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED", id) + WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED:" .. id, id) end end end @@ -2613,20 +2609,20 @@ do if not WeakAuras.IsPaused() then if nowReady then - WeakAuras.ScanEvents("SPELL_COOLDOWN_READY", id); + WeakAuras.ScanEvents("SPELL_COOLDOWN_READY:" .. id, id) end if changed or chargesChanged then - WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED", id); + WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED:" .. id, id) end if (chargesDifference ~= 0 ) then - WeakAuras.ScanEvents("SPELL_CHARGES_CHANGED", id, chargesDifference, spellCount or 0); + WeakAuras.ScanEvents("SPELL_CHARGES_CHANGED:" .. id, id, chargesDifference, spellCount or 0); end end end - function Private.CheckSpellCooldows(runeDuration) + function Private.CheckSpellCooldowns(runeDuration) for id, _ in pairs(spells) do Private.CheckSpellCooldown(id, runeDuration) end @@ -2660,7 +2656,7 @@ do itemCdExps[id] = endTime; itemCdHandles[id] = timer:ScheduleTimer(ItemCooldownFinished, endTime - time, id); if not WeakAuras.IsPaused() then - WeakAuras.ScanEvents("ITEM_COOLDOWN_STARTED", id) + WeakAuras.ScanEvents("ITEM_COOLDOWN_STARTED:" .. id, id) end itemCdEnabledChanged = false; elseif(itemCdExps[id] ~= endTime) then @@ -2672,7 +2668,7 @@ do itemCdExps[id] = endTime; itemCdHandles[id] = timer:ScheduleTimer(ItemCooldownFinished, endTime - time, id); if not WeakAuras.IsPaused() then - WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED", id) + WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED:" .. id, id) end itemCdEnabledChanged = false; end @@ -2690,7 +2686,7 @@ do end end if (itemCdEnabledChanged and not WeakAuras.IsPaused()) then - WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED", id); + WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED:" .. id, id); end end end @@ -2715,7 +2711,7 @@ do itemSlotsCdExps[id] = endTime; itemSlotsCdHandles[id] = timer:ScheduleTimer(ItemSlotCooldownFinished, endTime - time, id); if not WeakAuras.IsPaused() then - WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_STARTED", id) + WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_STARTED:" .. id, id) end elseif(itemSlotsCdExps[id] ~= endTime) then -- Cooldown is now different @@ -2726,7 +2722,7 @@ do itemSlotsCdExps[id] = endTime; itemSlotsCdHandles[id] = timer:ScheduleTimer(ItemSlotCooldownFinished, endTime - time, id); if not WeakAuras.IsPaused() then - WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_CHANGED", id) + WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_CHANGED:" .. id, id) end end elseif(duration > 0) then @@ -2745,7 +2741,7 @@ do local newItemId = GetInventoryItemID("player", id); if (itemId ~= newItemId) then if not WeakAuras.IsPaused() then - WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_ITEM_CHANGED") + WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_ITEM_CHANGED:" .. id, id) end itemSlots[id] = newItemId or 0; end @@ -2755,7 +2751,7 @@ do function Private.CheckCooldownReady() CheckGCD(); Private.CheckRuneCooldown(); - Private.CheckSpellCooldows(); + Private.CheckSpellCooldowns(); Private.CheckItemCooldowns(); Private.CheckItemSlotCooldowns(); end @@ -3143,7 +3139,7 @@ do end local function tenchUpdate() - Private.StartProfileSystem("generictrigger"); + Private.StartProfileSystem("generictrigger temporary enchant"); local _, mh_rem, oh_rem, rw_rem, re_charges _, mh_rem, mh_charges, _, oh_rem, oh_charges, _, rw_rem, rw_charges = GetWeaponEnchantInfo(); local time = GetTime(); @@ -3181,13 +3177,14 @@ do rw_icon = GetInventoryItemTexture("player", rw) end WeakAuras.ScanEvents("TENCH_UPDATE"); - Private.StopProfileSystem("generictrigger"); + Private.StopProfileSystem("generictrigger temporary enchant"); end - tenchFrame:SetScript("OnEvent", function() - Private.StartProfileSystem("generictrigger"); + tenchFrame:SetScript("OnEvent", function(_, unit, ...) + if unit and unit ~= "player" then return end + Private.StartProfileSystem("generictrigger temporary enchant"); timer:ScheduleTimer(tenchUpdate, 0.1); - Private.StopProfileSystem("generictrigger"); + Private.StopProfileSystem("generictrigger temporary enchant"); end); tenchUpdate(); @@ -3217,9 +3214,9 @@ do petFrame:RegisterEvent("UNIT_PET") petFrame:SetScript("OnEvent", function(_, event, unit) if unit ~= "player" then return end - Private.StartProfileSystem("generictrigger") + Private.StartProfileSystem("generictrigger pet update") WeakAuras.ScanEvents("PET_UPDATE", "pet") - Private.StopProfileSystem("generictrigger") + Private.StopProfileSystem("generictrigger pet update") end) end end @@ -3319,7 +3316,7 @@ do local isMounted = IsMounted(); local function checkForMounted(self, elaps) - Private.StartProfileSystem("generictrigger"); + Private.StartProfileSystem("generictrigger mounted"); elapsed = elapsed + elaps if(isMounted ~= IsMounted()) then isMounted = IsMounted(); @@ -3329,7 +3326,7 @@ do if(elapsed > delay) then mountedFrame:SetScript("OnUpdate", nil); end - Private.StopProfileSystem("generictrigger"); + Private.StopProfileSystem("generictrigger mounted"); end function WeakAuras.WatchForMounts() @@ -3350,13 +3347,13 @@ do local playerMovingFrame = nil local function PlayerMoveSpeedUpdate() - Private.StartProfileSystem("generictrigger"); + Private.StartProfileSystem("generictrigger player moving"); local speed = GetUnitSpeed("player") if speed ~= playerMovingFrame.speed then playerMovingFrame.speed = speed WeakAuras.ScanEvents("PLAYER_MOVE_SPEED_UPDATE") end - Private.StopProfileSystem("generictrigger"); + Private.StopProfileSystem("generictrigger player moving"); end function WeakAuras.WatchPlayerMoveSpeed() @@ -3460,10 +3457,10 @@ function WeakAuras.RegisterItemCountWatch() itemCountWatchFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED"); itemCountWatchFrame:SetScript("OnEvent", function(_, _, unit) if unit ~= "player" then return end - Private.StartProfileSystem("generictrigger"); + Private.StartProfileSystem("generictrigger item count"); timer:ScheduleTimer(WeakAuras.ScanEvents, 0.2, "ITEM_COUNT_UPDATE"); timer:ScheduleTimer(WeakAuras.ScanEvents, 0.5, "ITEM_COUNT_UPDATE"); - Private.StopProfileSystem("generictrigger"); + Private.StopProfileSystem("generictrigger item count"); end); end end @@ -3505,7 +3502,7 @@ do end queuedActionFrame:RegisterEvent("ACTIONBAR_SLOT_CHANGED") queuedActionFrame:SetScript("OnEvent", function(_, _, slotID) - Private.StartProfileSystem("generictrigger"); + Private.StartProfileSystem("generictrigger queued action"); local spellID = GetActionSpellID(slotID) if spellID then buttonIDList[slotID] = spellID @@ -3514,7 +3511,7 @@ do spellIDList[buttonIDList[slotID]] = nil buttonIDList[slotID] = nil end - Private.StopProfileSystem("generictrigger"); + Private.StopProfileSystem("generictrigger queued action"); end) end diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 1d23a90..1da752a 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -3118,10 +3118,17 @@ Private.event_prototypes = { ["Cooldown Progress (Spell)"] = { type = "spell", events = {}, - internal_events = function(trigger, untrigger) + loadInternalEventFunc = function(trigger, untrigger) + trigger.spellName = type(trigger.spellName) ~= "table" and trigger.spellName or 0; + local spellName; + if (trigger.use_exact_spellName) then + spellName = trigger.spellName; + else + spellName = type(trigger.spellName) == "number" and GetSpellInfo(trigger.spellName) or trigger.spellName; + end local events = { - "SPELL_COOLDOWN_CHANGED", - "COOLDOWN_REMAINING_CHECK", + "SPELL_COOLDOWN_CHANGED:" .. spellName, + "COOLDOWN_REMAINING_CHECK:" .. spellName, "WA_DELAYED_PLAYER_ENTERING_WORLD" }; if (trigger.use_showgcd) then @@ -3204,11 +3211,12 @@ Private.event_prototypes = { remaining = expirationTime - GetTime(); local remainingCheck = %s; if(remaining >= remainingCheck and remaining > 0) then - Private.ExecEnv.ScheduleScan(expirationTime - remainingCheck); + local event = "COOLDOWN_REMAINING_CHECK:" .. %s + Private.ExecEnv.ScheduleScan(expirationTime - remainingCheck, event); end end ]]; - ret = ret..ret2:format(tonumber(trigger.remaining or 0) or 0); + ret = ret..ret2:format(tonumber(trigger.remaining or 0) or 0, spellName); end return ret; @@ -3397,9 +3405,16 @@ Private.event_prototypes = { ["Cooldown Ready (Spell)"] = { type = "spell", events = {}, - internal_events = { - "SPELL_COOLDOWN_READY", - }, + loadInternalEventFunc = function(trigger, untrigger) + trigger.spellName = trigger.spellName or 0; + local spellName; + if (trigger.use_exact_spellName) then + spellName = trigger.spellName; + else + spellName = type(trigger.spellName) == "number" and GetSpellInfo(trigger.spellName) or trigger.spellName; + end + return { "SPELL_COOLDOWN_READY:" .. spellName } + end, name = L["Cooldown Ready Event"], loadFunc = function(trigger) trigger.spellName = trigger.spellName or 0; @@ -3466,9 +3481,16 @@ Private.event_prototypes = { ["Charges Changed"] = { type = "spell", events = {}, - internal_events = { - "SPELL_CHARGES_CHANGED", - }, + loadInternalEventFunc = function(trigger, untrigger) + trigger.spellName = trigger.spellName or 0; + local spellName; + if (trigger.use_exact_spellName) then + spellName = trigger.spellName; + else + spellName = type(trigger.spellName) == "number" and GetSpellInfo(trigger.spellName) or trigger.spellName; + end + return { "SPELL_CHARGES_CHANGED:" .. spellName } + end, name = L["Charges Changed Event"], loadFunc = function(trigger) trigger.spellName = trigger.spellName or 0; @@ -3552,11 +3574,13 @@ Private.event_prototypes = { type = "item", events = {}, internal_events = function(trigger, untrigger) + trigger.itemName = trigger.itemName or 0; + local itemName = type(trigger.itemName) == "number" and trigger.itemName or "[["..trigger.itemName.."]]"; local events = { - "ITEM_COOLDOWN_READY", - "ITEM_COOLDOWN_CHANGED", - "ITEM_COOLDOWN_STARTED", - "COOLDOWN_REMAINING_CHECK", + "ITEM_COOLDOWN_READY:" .. itemName, + "ITEM_COOLDOWN_CHANGED:" .. itemName, + "ITEM_COOLDOWN_STARTED:" .. itemName, + "COOLDOWN_REMAINING_CHECK:" .. itemName, } if (trigger.use_showgcd) then tinsert(events, "GCD_START"); @@ -3569,7 +3593,6 @@ Private.event_prototypes = { name = L["Cooldown Progress (Item)"], loadFunc = function(trigger) trigger.itemName = trigger.itemName or 0; - local itemName = type(trigger.itemName) == "number" and trigger.itemName or "[["..trigger.itemName.."]]"; WeakAuras.WatchItemCooldown(trigger.itemName); if (trigger.use_showgcd) then WeakAuras.WatchGCD(); @@ -3591,10 +3614,11 @@ Private.event_prototypes = { local remaining = expirationTime > 0 and (expirationTime - GetTime()) or 0; local remainingCheck = %s; if(remaining >= remainingCheck and remaining > 0) then - Private.ExecEnv.ScheduleScan(expirationTime - remainingCheck); + local event = "COOLDOWN_REMAINING_CHECK:" .. %s + Private.ExecEnv.ScheduleScan(expirationTime - remainingCheck, event); end ]]; - ret = ret..ret2:format(tonumber(trigger.remaining or 0) or 0); + ret = ret..ret2:format(tonumber(trigger.remaining or 0) or 0, itemName); end return ret:format(itemName, trigger.use_showgcd and "true" or "false", @@ -3722,12 +3746,13 @@ Private.event_prototypes = { } }, internal_events = function(trigger, untrigger) + local slot = trigger.itemSlot or 0 local events = { - "ITEM_SLOT_COOLDOWN_STARTED", - "ITEM_SLOT_COOLDOWN_CHANGED", - "COOLDOWN_REMAINING_CHECK", - "ITEM_SLOT_COOLDOWN_ITEM_CHANGED", - "ITEM_SLOT_COOLDOWN_READY", + "ITEM_SLOT_COOLDOWN_STARTED:" .. slot, + "ITEM_SLOT_COOLDOWN_CHANGED:" .. slot, + "COOLDOWN_REMAINING_CHECK:" .. slot, + "ITEM_SLOT_COOLDOWN_ITEM_CHANGED:" .. slot, + "ITEM_SLOT_COOLDOWN_READY:" .. slot, "WA_DELAYED_PLAYER_ENTERING_WORLD" } @@ -3760,10 +3785,11 @@ Private.event_prototypes = { local remaining = expirationTime > 0 and (expirationTime - GetTime()) or 0; local remainingCheck = %s; if(remaining >= remainingCheck and remaining > 0) then - Private.ExecEnv.ScheduleScan(expirationTime - remainingCheck); + local event = "COOLDOWN_REMAINING_CHECK:" .. %s + Private.ExecEnv.ScheduleScan(expirationTime - remainingCheck, event); end ]]; - ret = ret..ret2:format(tonumber(trigger.remaining or 0) or 0); + ret = ret..ret2:format(tonumber(trigger.remaining or 0) or 0, trigger.itemSlot or 0); end return ret:format(trigger.use_showgcd and "true" or "false", trigger.itemSlot or "0", @@ -3876,9 +3902,10 @@ Private.event_prototypes = { ["Cooldown Ready (Item)"] = { type = "item", events = {}, - internal_events = { - "ITEM_COOLDOWN_READY", - }, + internal_events = function(trigger) + trigger.itemName = trigger.itemName or 0 + return { "ITEM_COOLDOWN_READY:" .. trigger.itemName } + end, name = L["Cooldown Ready Event (Item)"], loadFunc = function(trigger) trigger.itemName = trigger.itemName or 0; @@ -4130,9 +4157,16 @@ Private.event_prototypes = { ["player"] = { "UNIT_POWER", "UNIT_ENERGY", "UNIT_MANA", "UNIT_RAGE" } } }, - internal_events = { - "SPELL_COOLDOWN_CHANGED", - }, + loadInternalEventFunc = function(trigger) + trigger.spellName = trigger.spellName or 0; + local spellName + if (trigger.use_exact_spellName) then + spellName = trigger.spellName + else + spellName = type(trigger.spellName) == "number" and GetSpellInfo(trigger.spellName) or trigger.spellName; + end + return { "SPELL_COOLDOWN_CHANGED:" .. spellName } + end, force_events = "SPELL_UPDATE_USABLE", name = L["Action Usable"], statesParameter = "one", @@ -5343,8 +5377,10 @@ Private.event_prototypes = { type = "item", events = { ["events"] = { - "UNIT_INVENTORY_CHANGED", "PLAYER_EQUIPMENT_CHANGED", + }, + ["unit_events"] = { + ["player"] = {"UNIT_INVENTORY_CHANGED"} } }, internal_events = { "WA_DELAYED_PLAYER_ENTERING_WORLD", },