Skip to content

Commit ef08d1b

Browse files
committed
feat: Refactor MySlot.lua to improve spell handling
1 parent 71b1d76 commit ef08d1b

File tree

1 file changed

+86
-8
lines changed

1 file changed

+86
-8
lines changed

Myslot.lua

+86-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local MYSLOT_VER = 42
1616
-- TWW Beta Compat code (fix and cleanup below later)
1717
local GetNumSpellTabs = C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines or _G.GetNumSpellTabs
1818
local GetSpellTabInfo = (C_SpellBook and C_SpellBook.GetSpellBookSkillLineInfo) and function(index)
19-
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(index);
19+
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(index)
2020
if skillLineInfo then
2121
return skillLineInfo.name,
2222
skillLineInfo.iconID,
@@ -25,7 +25,7 @@ local GetSpellTabInfo = (C_SpellBook and C_SpellBook.GetSpellBookSkillLineInfo)
2525
skillLineInfo.isGuild,
2626
skillLineInfo.offSpecID,
2727
skillLineInfo.shouldHide,
28-
skillLineInfo.specID;
28+
skillLineInfo.specID
2929
end
3030
end or _G.GetSpellTabInfo
3131
local PickupSpell = C_Spell and C_Spell.PickupSpell or _G.PickupSpell
@@ -107,6 +107,60 @@ local function TableToString(s)
107107
return table.concat(t)
108108
end
109109

110+
local function CreateSpellOverrideMap()
111+
local spellOverride = {}
112+
113+
if C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines then
114+
-- 11.0
115+
116+
for skillLineIndex = 1, C_SpellBook.GetNumSpellBookSkillLines() do
117+
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(skillLineIndex)
118+
for i = 1, skillLineInfo.numSpellBookItems do
119+
local spellIndex = skillLineInfo.itemIndexOffset + i
120+
local _, spellId = C_SpellBook.GetSpellBookItemType(spellIndex, Enum.SpellBookSpellBank.Player)
121+
if spellId then
122+
local newid = C_Spell.GetOverrideSpell(spellId)
123+
if newid ~= spellId then
124+
spellOverride[newid] = spellId
125+
end
126+
end
127+
end
128+
end
129+
130+
local isInspect = false
131+
for specIndex = 1, GetNumSpecGroups(isInspect) do
132+
for tier = 1, MAX_TALENT_TIERS do
133+
for column = 1, NUM_TALENT_COLUMNS do
134+
local spellId = select(6, GetTalentInfo(tier, column, specIndex))
135+
if spellId then
136+
local newid = C_Spell.GetOverrideSpell(spellId)
137+
if newid ~= spellId then
138+
spellOverride[newid] = spellId
139+
end
140+
end
141+
end
142+
end
143+
end
144+
145+
for pvpTalentSlot = 1, 3 do
146+
local slotInfo = C_SpecializationInfo.GetPvpTalentSlotInfo(pvpTalentSlot)
147+
if slotInfo ~= nil then
148+
for i, pvpTalentID in ipairs(slotInfo.availableTalentIDs) do
149+
local spellId = select(6, GetPvpTalentInfoByID(pvpTalentID))
150+
if spellId then
151+
local newid = C_Spell.GetOverrideSpell(spellId)
152+
if newid ~= spellId then
153+
spellOverride[newid] = spellId
154+
end
155+
end
156+
end
157+
end
158+
end
159+
end
160+
161+
return spellOverride
162+
end
163+
110164
function MySlot:Print(msg)
111165
DEFAULT_CHAT_FRAME:AddMessage("|CFFFF0000<|r|CFFFFD100Myslot|r|CFFFF0000>|r" .. (msg or "nil"))
112166
end
@@ -121,7 +175,7 @@ function MySlot:GetMacroInfo(macroId)
121175
return nil
122176
end
123177

124-
iconTexture = gsub(strupper(iconTexture or "INV_Misc_QuestionMark"), "INTERFACE\\ICONS\\", "");
178+
iconTexture = gsub(strupper(iconTexture or "INV_Misc_QuestionMark"), "INTERFACE\\ICONS\\", "")
125179

126180
local msg = _MySlot.Macro()
127181
msg.id = macroId
@@ -322,10 +376,18 @@ function MySlot:Export(opt)
322376
end
323377

324378
msg.slot = {}
379+
-- TODO move to GetActionInfo
380+
local spellOverride = CreateSpellOverrideMap()
381+
325382
for i = 1, MYSLOT_MAX_ACTIONBAR do
326383
if not opt.ignoreActionBars[math.ceil(i / 12)] then
327384
local m = self:GetActionInfo(i)
328385
if m then
386+
if m.type == 'SPELL' then
387+
if spellOverride[m.index] then
388+
m.index = spellOverride[m.index]
389+
end
390+
end
329391
msg.slot[#msg.slot + 1] = m
330392
end
331393
end
@@ -524,22 +586,25 @@ function MySlot:FindOrCreateMacro(macroInfo)
524586
end
525587
-- }}}
526588

589+
590+
527591
function MySlot:RecoverData(msg, opt)
528592
-- {{{ Cache Spells
529593
--cache spells
530594
local spells = {}
531595

596+
-- TODO clean up this with 11.0
532597
if SPELLS_PER_PAGE then
533598
for i = 1, GetNumSpellTabs() do
534-
local tab, tabTex, offset, numSpells, isGuild, offSpecID = GetSpellTabInfo(i);
599+
local tab, tabTex, offset, numSpells, isGuild, offSpecID = GetSpellTabInfo(i)
535600
offSpecID = (offSpecID ~= 0)
536601
if not offSpecID then
537-
offset = offset + 1;
538-
local tabEnd = offset + numSpells;
602+
offset = offset + 1
603+
local tabEnd = offset + numSpells
539604
for j = offset, tabEnd - 1 do
540605
local spellType, spellId = GetSpellBookItemInfo(j, BOOKTYPE_SPELL)
541606
if spellType then
542-
local slot = j + (SPELLS_PER_PAGE * (SPELLBOOK_PAGENUMBERS[i] - 1));
607+
local slot = j + (SPELLS_PER_PAGE * (SPELLBOOK_PAGENUMBERS[i] - 1))
543608
local spellName = GetSpellInfo(spellId)
544609
spells[MySlot.SLOT_TYPE[string.lower(spellType)] .. "_" .. spellId] = { slot, BOOKTYPE_SPELL, "spell" }
545610
if spellName then -- flyout
@@ -567,6 +632,8 @@ function MySlot:RecoverData(msg, opt)
567632
end
568633
end
569634
end
635+
636+
local spellOverride = CreateSpellOverrideMap()
570637
-- }}}
571638

572639

@@ -661,6 +728,17 @@ function MySlot:RecoverData(msg, opt)
661728
PickupSpell(index)
662729
end
663730

731+
if not GetCursorInfo() then
732+
if spellOverride[index] then
733+
PickupSpell(spellOverride[index])
734+
end
735+
end
736+
737+
if not GetCursorInfo() then
738+
local spellName = GetSpellInfo(index)
739+
PickupSpell(spellName)
740+
end
741+
664742
if not GetCursorInfo() then
665743
-- flyout and failover
666744

@@ -765,7 +843,7 @@ function MySlot:RecoverData(msg, opt)
765843
if not opt.actionOpt.ignorePetActionBar then
766844
local pettoken = {}
767845
for i = 1, NUM_PET_ACTION_SLOTS, 1 do
768-
local name, _, isToken = GetPetActionInfo(i);
846+
local name, _, isToken = GetPetActionInfo(i)
769847
if isToken then
770848
pettoken[name] = i
771849
end

0 commit comments

Comments
 (0)