From 75f7932be1cfb97ab55f921a871b43057b09bc25 Mon Sep 17 00:00:00 2001 From: Infus Date: Sun, 21 Jul 2024 19:41:18 +0200 Subject: [PATCH] Rewrite PVP Talent Load/Trigger to use SpellIds Instead of indexes. This breaks all existing pvp talent trigger/load options, though a lot would break anyway with the class changes of TWW. This ensures that in the future patch changes should be less likely break the load/trigger options. And improves cross-spec setups. Fixes; #4557 --- WeakAuras/Prototypes.lua | 42 ++++++++++++++++++++++++---------------- WeakAuras/Types.lua | 8 -------- WeakAuras/WeakAuras.lua | 11 ++++++----- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index ec8767c8ab..d24c133224 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -801,20 +801,22 @@ if WeakAuras.IsRetail() then end end ----@param index integer +---@param spellId integer ---@return boolean hasTalent ----@return number? talentId -function WeakAuras.CheckPvpTalentByIndex(index) +---@return number? spellid +function WeakAuras.CheckPvpTalentBySpellId(spellId) local checkTalentSlotInfo = C_SpecializationInfo.GetPvpTalentSlotInfo(1) if checkTalentSlotInfo then - local checkTalentId = checkTalentSlotInfo.availableTalentIDs[index] for i = 1, 3 do local talentSlotInfo = C_SpecializationInfo.GetPvpTalentSlotInfo(i) - if talentSlotInfo and (talentSlotInfo.selectedTalentID == checkTalentId) then - return true, checkTalentId + if talentSlotInfo and talentSlotInfo.selectedTalentID then + local selectedSpellId = select(6, GetPvpTalentInfoByID(talentSlotInfo.selectedTalentID)) + if selectedSpellId == spellId then + return true, spellId + end end end - return false, checkTalentId + return false, spellId end return false end @@ -1663,17 +1665,23 @@ Private.load_prototype = { single_spec = GetSpecialization(); end - -- print ("Using talent cache", single_class, single_spec); -- If a single specific class was found, load the specific list for it + if not single_class then + single_class = select(2, UnitClass("player")) + end + if not single_spec then + single_spec = GetSpecialization() + end + if(single_class and Private.pvp_talent_types_specific[single_class] and single_spec and Private.pvp_talent_types_specific[single_class][single_spec]) then return Private.pvp_talent_types_specific[single_class][single_spec]; else - return Private.pvp_talent_types; + return {} end end end, - test = "WeakAuras.CheckPvpTalentByIndex(%d)", + test = "WeakAuras.CheckPvpTalentBySpellId(%d)", enable = WeakAuras.IsRetail(), hidden = not WeakAuras.IsRetail(), events = {"PLAYER_PVP_TALENT_UPDATE"} @@ -7135,9 +7143,9 @@ Private.event_prototypes = { local index = %s local activeName, activeIcon, _ - local active, talentId = WeakAuras.CheckPvpTalentByIndex(index) - if talentId then - _, activeName, activeIcon = GetPvpTalentInfoByID(talentId) + local active, spellId = WeakAuras.CheckPvpTalentBySpellId(index) + if spellId then + activeName, _, activeIcon = Private.ExecEnv.GetSpellInfo(spellId) end ]]):format(index or 0)) if (inverse) then @@ -7158,9 +7166,9 @@ Private.event_prototypes = { table.insert(ret, ([[ if (not active) then local index = %s - active, talentId = WeakAuras.CheckPvpTalentByIndex(index) - if active and talentId then - _, activeName, activeIcon = GetPvpTalentInfoByID(talentId) + active, spellId = WeakAuras.CheckPvpTalentBySpellId(index) + if active and spellId then + activeName, _, activeIcon = Private.ExecEnv.GetSpellInfo(spellId) end end ]]):format(index)) @@ -7185,7 +7193,7 @@ Private.event_prototypes = { if(Private.pvp_talent_types_specific[class] and Private.pvp_talent_types_specific[class][spec]) then return Private.pvp_talent_types_specific[class][spec]; else - return Private.pvp_talent_types; + return {} end end, test = "active", diff --git a/WeakAuras/Types.lua b/WeakAuras/Types.lua index ad3d661536..b085e97f4f 100644 --- a/WeakAuras/Types.lua +++ b/WeakAuras/Types.lua @@ -1832,14 +1832,6 @@ else end end ----@type table -Private.pvp_talent_types = {} -if WeakAuras.IsRetail() then - for i = 1,10 do - tinsert(Private.pvp_talent_types, string.format(L["PvP Talent %i"], i)); - end -end - ---@type table Private.talent_extra_option_types = { [0] = L["Talent Known"], diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 361392cfaf..b24c0b802b 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -1003,19 +1003,20 @@ local function CreatePvPTalentCache() Private.pvp_talent_types_specific[player_class] = Private.pvp_talent_types_specific[player_class] or {}; Private.pvp_talent_types_specific[player_class][spec] = Private.pvp_talent_types_specific[player_class][spec] or {}; + --- @type fun(talentId: number): number, string local function formatTalent(talentId) - local _, name, icon = GetPvpTalentInfoByID(talentId); - return "|T"..icon..":0|t "..name + local _, name, icon, _, _, spellId = GetPvpTalentInfoByID(talentId); + return spellId, "|T"..icon..":0|t "..name end local slotInfo = C_SpecializationInfo.GetPvpTalentSlotInfo(1); if (slotInfo) then - Private.pvp_talent_types_specific[player_class][spec] = {}; local pvpSpecTalents = slotInfo.availableTalentIDs; - for i, talentId in ipairs(pvpSpecTalents) do - Private.pvp_talent_types_specific[player_class][spec][i] = formatTalent(talentId); + for _, talentId in ipairs(pvpSpecTalents) do + local index, displayText = formatTalent(talentId) + Private.pvp_talent_types_specific[player_class][spec][index] = displayText end end end