Skip to content

Commit

Permalink
Rewrite PVP Talent Load/Trigger to use SpellIds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
InfusOnWoW committed Jul 23, 2024
1 parent 001969d commit 75f7932
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
42 changes: 25 additions & 17 deletions WeakAuras/Prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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",
Expand Down
8 changes: 0 additions & 8 deletions WeakAuras/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1832,14 +1832,6 @@ else
end
end

---@type table<number, string>
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<number, string>
Private.talent_extra_option_types = {
[0] = L["Talent Known"],
Expand Down
11 changes: 6 additions & 5 deletions WeakAuras/WeakAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75f7932

Please sign in to comment.