From e7c46c8d5f826ba6ed17f758158ee26e538eb5d2 Mon Sep 17 00:00:00 2001 From: Bunny67 Date: Sun, 27 Dec 2020 22:24:13 +0300 Subject: [PATCH] add map area id (zoneId) support for load auras --- WeakAuras/Prototypes.lua | 31 +++++++++++++++++++++++++++++++ WeakAuras/WeakAuras.lua | 5 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 1e03470..6048e0f 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -545,6 +545,26 @@ function WeakAuras.CheckTalentByIndex(index) return rank and rank > 0; end +function WeakAuras.CheckNumericIds(loadids, currentId) + if (not loadids or not currentId) then + return false; + end + + local searchFrom = 0; + local startI, endI = string.find(loadids, currentId, searchFrom); + while (startI) do + searchFrom = endI + 1; -- start next search from end + if (startI == 1 or tonumber(string.sub(loadids, startI - 1, startI - 1)) == nil) then + -- Either right at start, or character before is not a number + if (endI == string.len(loadids) or tonumber(string.sub(loadids, endI + 1, endI + 1)) == nil) then + return true; + end + end + startI, endI = string.find(loadids, currentId, searchFrom); + end + return false; +end + function WeakAuras.CheckString(ids, currentId) if (not ids or not currentId) then return false; @@ -858,6 +878,17 @@ Private.load_prototype = { events = {"ZONE_CHANGED", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED_NEW_AREA", "VEHICLE_UPDATE"}, desc = L["Supports multiple entries, separated by commas"] }, + { + name = "zoneId", + display = L["Zone ID(s)"], + type = "string", + init = "arg", + test = "WeakAuras.CheckNumericIds(%q, zoneId)", + events = {"ZONE_CHANGED", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED_NEW_AREA", "VEHICLE_UPDATE"}, + desc = function() + return ("\n|cffffd200%s|r%s: %d\n\n%s"):format(L["Current Zone\n"], GetRealZoneText(), GetCurrentMapAreaID(), L["Supports multiple entries, separated by commas"]) + end + }, { name = "size", display = L["Instance Type"], diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 2c12f93..8ebfd47 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -1179,6 +1179,7 @@ local function scanForLoadsImpl(toCheck, event, arg1, ...) local player, realm, zone = UnitName("player"), GetRealmName(), GetRealZoneText(); local faction = UnitFactionGroup("player") + local zoneId = GetCurrentMapAreaID() local _, class = UnitClass("player"); @@ -1199,8 +1200,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, vehicle, vehicleUi, group, player, realm, class, faction, playerLevel, zone, size, difficulty); - couldBeLoaded = loadOpt and loadOpt("ScanForLoads_Auras", inCombat, vehicle, vehicleUi, group, player, realm, class, faction, playerLevel, zone, size, difficulty); + shouldBeLoaded = loadFunc and loadFunc("ScanForLoads_Auras", inCombat, vehicle, vehicleUi, group, player, realm, class, faction, playerLevel, zone, zoneId, size, difficulty); + couldBeLoaded = loadOpt and loadOpt("ScanForLoads_Auras", inCombat, vehicle, vehicleUi, group, player, realm, class, faction, playerLevel, zone, zoneId, size, difficulty); if(shouldBeLoaded and not loaded[id]) then changed = changed + 1;