From 57b67eca07f13fa4f0930c58f918be667a470441 Mon Sep 17 00:00:00 2001 From: NoM0Re Date: Mon, 3 Mar 2025 13:55:49 +0100 Subject: [PATCH] add mounted load condition, add more wow api for load and organize it better --- WeakAuras/GenericTrigger.lua | 30 +++++++++++++++----------- WeakAuras/Prototypes.lua | 12 ++++++++--- WeakAuras/WeakAuras.lua | 42 ++++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 35f95e4..7a7e8f2 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -1184,6 +1184,7 @@ function HandleEvent(frame, event, arg1, arg2, ...) if (event == "PLAYER_ENTERING_WORLD") then timer:ScheduleTimer(function() Private.CreateTalentCache() + WeakAuras.WatchForMounts() HandleEvent(frame, "WA_DELAYED_PLAYER_ENTERING_WORLD"); Private.ScanForLoads(nil, "WA_DELAYED_PLAYER_ENTERING_WORLD") Private.StartProfileSystem("generictrigger WA_DELAYED_PLAYER_ENTERING_WORLD"); @@ -3542,27 +3543,30 @@ do local isMounted = IsMounted(); local function checkForMounted(self, elaps) - Private.StartProfileSystem("generictrigger mounted"); + Private.StartProfileSystem("generictrigger mounted") elapsed = elapsed + elaps if(isMounted ~= IsMounted()) then - isMounted = IsMounted(); - Private.ScanEvents("MOUNTED_UPDATE"); - mountedFrame:SetScript("OnUpdate", nil); + isMounted = IsMounted() + Private.ScanForLoads(nil, "MOUNTED_UPDATE") + Private.ScanEvents("MOUNTED_UPDATE") + mountedFrame:SetScript("OnUpdate", nil) end if(elapsed > delay) then - mountedFrame:SetScript("OnUpdate", nil); + mountedFrame:SetScript("OnUpdate", nil) end - Private.StopProfileSystem("generictrigger mounted"); + Private.StopProfileSystem("generictrigger mounted") end function WeakAuras.WatchForMounts() - if not(mountedFrame) then - mountedFrame = CreateFrame("Frame"); - Private.frames["Mount Use Handler"] = mountedFrame; - mountedFrame:RegisterEvent("COMPANION_UPDATE"); - mountedFrame:SetScript("OnEvent", function() - elapsed = 0; - mountedFrame:SetScript("OnUpdate", checkForMounted); + if not (mountedFrame) then + mountedFrame = CreateFrame("Frame") + Private.frames["Mount Use Handler"] = mountedFrame + mountedFrame:RegisterEvent("COMPANION_UPDATE") + mountedFrame:SetScript("OnEvent", function(_, _, arg) + if arg == "MOUNT" then + elapsed = 0 + mountedFrame:SetScript("OnUpdate", checkForMounted) + end end) end end diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 0c13a27..717e75c 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -972,6 +972,15 @@ Private.load_prototype = { optional = true, events = {"VEHICLE_UPDATE", "UNIT_ENTERED_VEHICLE", "UNIT_EXITED_VEHICLE"} }, + { + name = "mounted", + display = L["Mounted"], + type = "tristate", + init = "arg", + width = WeakAuras.normalWidth, + optional = true, + events = {"MOUNTED_UPDATE"} + }, { name ="playerTitle", display = L["Player"], @@ -7429,9 +7438,6 @@ Private.event_prototypes = { if (trigger.use_ismoving ~= nil) then WeakAuras.WatchPlayerMoveSpeed(); end - if (trigger.use_mounted ~= nil) then - WeakAuras.WatchForMounts(); - end if (trigger.use_HasPet ~= nil) then AddWatchedUnits("pet") end diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 3d88adb..a09d038 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -6,20 +6,29 @@ local internalVersion = 83 local insert = table.insert -- WoW APIs -local IsAddOnLoaded, InCombatLockdown = IsAddOnLoaded, InCombatLockdown -local LoadAddOn, UnitName, GetRealmName, UnitFactionGroup, IsInRaid - = LoadAddOn, UnitName, GetRealmName, UnitFactionGroup, IsInRaid -local UnitClass, UnitExists, UnitGUID, UnitAffectingCombat, GetInstanceInfo, IsInInstance - = UnitClass, UnitExists, UnitGUID, UnitAffectingCombat, GetInstanceInfo, IsInInstance -local UnitIsUnit, GetRaidRosterInfo, UnitInVehicle, UnitHasVehicleUI, GetSpellInfo - = UnitIsUnit, GetRaidRosterInfo, UnitInVehicle, UnitHasVehicleUI, GetSpellInfo -local SendChatMessage, UnitInBattleground, UnitInRaid, UnitInParty, GetTime - = SendChatMessage, UnitInBattleground, UnitInRaid, UnitInParty, GetTime -local CreateFrame, IsShiftKeyDown, GetScreenWidth, GetScreenHeight, GetCursorPosition, UpdateAddOnCPUUsage, GetFrameCPUUsage, debugprofilestop - = CreateFrame, IsShiftKeyDown, GetScreenWidth, GetScreenHeight, GetCursorPosition, UpdateAddOnCPUUsage, GetFrameCPUUsage, debugprofilestop -local debugstack = debugstack -local GetNumTalentTabs, GetNumTalents = GetNumTalentTabs, GetNumTalents -local MAX_NUM_TALENTS = MAX_NUM_TALENTS or 40 +local IsAddOnLoaded, LoadAddOn + = IsAddOnLoaded, LoadAddOn +local UnitName, GetRealmName, UnitRace, UnitFactionGroup, UnitClass + = UnitName, GetRealmName, UnitRace, UnitFactionGroup, UnitClass +local IsInRaid, UnitIsPartyLeader, UnitIsRaidOfficer, GetRaidRosterInfo, UnitInRaid, UnitInParty + = IsInRaid, UnitIsPartyLeader, UnitIsRaidOfficer, GetRaidRosterInfo, UnitInRaid, UnitInParty +local InCombatLockdown, UnitAffectingCombat, GetInstanceInfo, IsInInstance + = InCombatLockdown, UnitAffectingCombat, GetInstanceInfo, IsInInstance +local GetCurrentMapAreaID, GetRealZoneText, GetSubZoneText + = GetCurrentMapAreaID, GetRealZoneText, GetSubZoneText +local UnitIsPVPFreeForAll, UnitIsPVP, UnitOnTaxi, IsMounted + = UnitIsPVPFreeForAll, UnitIsPVP, UnitOnTaxi, IsMounted +local UnitInVehicle, UnitHasVehicleUI, UnitIsUnit, UnitIsDeadOrGhost + = UnitInVehicle, UnitHasVehicleUI, UnitIsUnit, UnitIsDeadOrGhost +local SendChatMessage, UnitInBattleground + = SendChatMessage, UnitInBattleground +local GetTime, UpdateAddOnCPUUsage, GetFrameCPUUsage, debugprofilestop + = GetTime, UpdateAddOnCPUUsage, GetFrameCPUUsage, debugprofilestop +local GetNumTalentTabs, GetNumTalents, MAX_NUM_TALENTS + = GetNumTalentTabs, GetNumTalents, MAX_NUM_TALENTS or 40 +local CreateFrame, IsShiftKeyDown, GetScreenWidth, GetScreenHeight, GetCursorPosition + = CreateFrame, IsShiftKeyDown, GetScreenWidth, GetScreenHeight, GetCursorPosition +local debugstack, GetSpellInfo = debugstack, GetSpellInfo local ADDON_NAME = "WeakAuras" local WeakAuras = WeakAuras @@ -1422,6 +1431,7 @@ local function scanForLoadsImpl(toCheck, event, arg1, ...) local pvp = UnitIsPVPFreeForAll("player") or UnitIsPVP("player") local vehicle = UnitInVehicle("player") or UnitOnTaxi("player") or false local vehicleUi = UnitHasVehicleUI("player") or false + local mounted = IsMounted() or false local raidMemberType = 0 @@ -1447,8 +1457,8 @@ local function scanForLoadsImpl(toCheck, event, arg1, ...) if (data and not data.controlledChildren) then local loadFunc = loadFuncs[id]; local loadOpt = loadFuncsForOptions[id]; - shouldBeLoaded = loadFunc and loadFunc("ScanForLoads_Auras", inCombat, alive, pvp, vehicle, vehicleUi, player, realm, class, race, faction, playerLevel, role, role, raidRole, group, groupSize, raidMemberType, zone, zoneId, subzone, size, difficulty); - couldBeLoaded = loadOpt and loadOpt("ScanForLoads_Auras", inCombat, alive, pvp, vehicle, vehicleUi, player, realm, class, race, faction, playerLevel, role, role, raidRole, group, groupSize, raidMemberType, zone, zoneId, subzone, size, difficulty); + shouldBeLoaded = loadFunc and loadFunc("ScanForLoads_Auras", inCombat, alive, pvp, vehicle, vehicleUi, mounted, player, realm, class, race, faction, playerLevel, role, role, raidRole, group, groupSize, raidMemberType, zone, zoneId, subzone, size, difficulty); + couldBeLoaded = loadOpt and loadOpt("ScanForLoads_Auras", inCombat, alive, pvp, vehicle, vehicleUi, mounted, player, realm, class, race, faction, playerLevel, role, role, raidRole, group, groupSize, raidMemberType, zone, zoneId, subzone, size, difficulty); if(shouldBeLoaded and not loaded[id]) then changed = changed + 1;