Skip to content

Commit 59b10f8

Browse files
authored
fix override spell and flyout in 11.0 (#58)
* feat: Refactor MySlot.lua to improve spell handling * fix flyout in 11.0 * fix in classic * add addon version * Refactor Myslot.lua to include a link to share user profiles * remove debug info * remove unused code
1 parent 71b1d76 commit 59b10f8

File tree

2 files changed

+133
-31
lines changed

2 files changed

+133
-31
lines changed

Myslot.lua

+132-30
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,14 +25,15 @@ 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
3232
local PickupItem = C_Item and C_Item.PickupItem or _G.PickupItem
3333
local GetSpellInfo = C_Spell and C_Spell.GetSpellName or _G.GetSpellInfo
3434
local GetSpellLink = C_Spell and C_Spell.GetSpellLink or _G.GetSpellLink
3535
local GetSpellBookItemInfo = C_SpellBook and C_SpellBook.GetSpellBookItemType or _G.GetSpellBookItemInfo
36+
local PickupSpellBookItem = C_SpellBook and C_SpellBook.PickupSpellBookItem or _G.PickupSpellBookItem
3637
-- TWW Beta Compat End
3738

3839
-- local MYSLOT_IS_DEBUG = true
@@ -107,6 +108,59 @@ local function TableToString(s)
107108
return table.concat(t)
108109
end
109110

111+
local function CreateSpellOverrideMap()
112+
local spellOverride = {}
113+
114+
if C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines then
115+
-- 11.0 only
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
@@ -372,22 +434,27 @@ function MySlot:Export(opt)
372434
s = "# --------------------" .. MYSLOT_LINE_SEP .. s
373435
s = "# " .. L["Feedback"] .. " [email protected]" .. MYSLOT_LINE_SEP .. s
374436
s = "# " .. MYSLOT_LINE_SEP .. s
375-
s = "# " .. LEVEL .. ":" .. UnitLevel("player") .. MYSLOT_LINE_SEP .. s
437+
s = "# " .. LEVEL .. ": " .. UnitLevel("player") .. MYSLOT_LINE_SEP .. s
376438
if talent then
377-
s = "# " .. TALENTS .. ":" .. talent .. MYSLOT_LINE_SEP .. s
439+
s = "# " .. TALENTS .. ": " .. talent .. MYSLOT_LINE_SEP .. s
378440
end
379441
if GetSpecialization then
380442
s = "# " ..
381443
SPECIALIZATION ..
382-
":" ..
444+
": " ..
383445
(GetSpecialization() and select(2, GetSpecializationInfo(GetSpecialization())) or NONE_CAPS) ..
384446
MYSLOT_LINE_SEP .. s
385447
end
386-
s = "# " .. CLASS .. ":" .. UnitClass("player") .. MYSLOT_LINE_SEP .. s
387-
s = "# " .. PLAYER .. ":" .. UnitName("player") .. MYSLOT_LINE_SEP .. s
388-
s = "# " .. L["Time"] .. ":" .. date() .. MYSLOT_LINE_SEP .. s
389-
s = "# Wow (V" .. GetBuildInfo() .. ")" .. MYSLOT_LINE_SEP .. s
390-
s = "# Myslot (https://myslot.net)" .. MYSLOT_LINE_SEP .. s
448+
s = "# " .. CLASS .. ": " .. UnitClass("player") .. MYSLOT_LINE_SEP .. s
449+
s = "# " .. PLAYER .. ": " .. UnitName("player") .. MYSLOT_LINE_SEP .. s
450+
s = "# " .. L["Time"] .. ": " .. date() .. MYSLOT_LINE_SEP .. s
451+
452+
if GetAddOnMetadata then
453+
s = "# Addon Version: " .. GetAddOnMetadata("Myslot", "Version") .. MYSLOT_LINE_SEP .. s
454+
end
455+
456+
s = "# Wow Version: " .. GetBuildInfo() .. MYSLOT_LINE_SEP .. s
457+
s = "# Myslot (https://myslot.net " .. L["<- share your profile here"] ..")" .. MYSLOT_LINE_SEP .. s
391458

392459
local d = base64.enc(t)
393460
local LINE_LEN = 60
@@ -524,22 +591,25 @@ function MySlot:FindOrCreateMacro(macroInfo)
524591
end
525592
-- }}}
526593

594+
595+
527596
function MySlot:RecoverData(msg, opt)
528597
-- {{{ Cache Spells
529598
--cache spells
530599
local spells = {}
531600

601+
-- TODO clean up this with 11.0
532602
if SPELLS_PER_PAGE then
533603
for i = 1, GetNumSpellTabs() do
534-
local tab, tabTex, offset, numSpells, isGuild, offSpecID = GetSpellTabInfo(i);
604+
local tab, tabTex, offset, numSpells, isGuild, offSpecID = GetSpellTabInfo(i)
535605
offSpecID = (offSpecID ~= 0)
536606
if not offSpecID then
537-
offset = offset + 1;
538-
local tabEnd = offset + numSpells;
607+
offset = offset + 1
608+
local tabEnd = offset + numSpells
539609
for j = offset, tabEnd - 1 do
540610
local spellType, spellId = GetSpellBookItemInfo(j, BOOKTYPE_SPELL)
541611
if spellType then
542-
local slot = j + (SPELLS_PER_PAGE * (SPELLBOOK_PAGENUMBERS[i] - 1));
612+
local slot = j + (SPELLS_PER_PAGE * (SPELLBOOK_PAGENUMBERS[i] - 1))
543613
local spellName = GetSpellInfo(spellId)
544614
spells[MySlot.SLOT_TYPE[string.lower(spellType)] .. "_" .. spellId] = { slot, BOOKTYPE_SPELL, "spell" }
545615
if spellName then -- flyout
@@ -567,6 +637,30 @@ function MySlot:RecoverData(msg, opt)
567637
end
568638
end
569639
end
640+
641+
local spellOverride = CreateSpellOverrideMap()
642+
643+
-- 11.0 only
644+
if C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines then
645+
local spellmap = {
646+
-- [Enum.SpellBookItemType.Spell] = "spell",
647+
[Enum.SpellBookItemType.Flyout] = "flyout",
648+
}
649+
650+
for skillLineIndex = 1, C_SpellBook.GetNumSpellBookSkillLines() do
651+
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(skillLineIndex)
652+
for i = 1, skillLineInfo.numSpellBookItems do
653+
local spellIndex = skillLineInfo.itemIndexOffset + i
654+
local spellTypeEnum, spellId = C_SpellBook.GetSpellBookItemType(spellIndex, Enum.SpellBookSpellBank.Player);
655+
if spellId then
656+
if spellmap[spellTypeEnum] then
657+
local spellType = spellmap[spellTypeEnum]
658+
spells[MySlot.SLOT_TYPE[string.lower(spellType)] .. "_" .. spellId] = { spellIndex, Enum.SpellBookSpellBank.Player, "spell" }
659+
end
660+
end
661+
end
662+
end
663+
end
570664
-- }}}
571665

572666

@@ -655,12 +749,19 @@ function MySlot:RecoverData(msg, opt)
655749
return
656750
end
657751

658-
if curIndex ~= index or curType ~= slotType or slotType == MYSLOT_MACRO then -- macro always test
752+
if curIndex ~= index or curType ~= slotType then
659753
if slotType == MYSLOT_SPELL or slotType == MYSLOT_FLYOUT or slotType == MYSLOT_COMPANION then
660754
if slotType == MYSLOT_SPELL or slotType == MYSLOT_COMPANION then
661755
PickupSpell(index)
662756
end
663757

758+
-- try if override
759+
if not GetCursorInfo() then
760+
if spellOverride[index] then
761+
PickupSpell(spellOverride[index])
762+
end
763+
end
764+
664765
if not GetCursorInfo() then
665766
-- flyout and failover
666767

@@ -671,26 +772,27 @@ function MySlot:RecoverData(msg, opt)
671772
if newId then
672773
if pickType == "spell" then
673774
PickupSpellBookItem(newId, spellType)
775+
-- elseif pickType == "spell" then
776+
-- C_SpellBook.PickupSpellBookItem(newId, spellType);
674777
elseif pickType == "companions" then
675778
PickupCompanion(spellType, newId)
676779
end
677-
else
678-
MySlot:Print(L["Ignore unlearned skill [id=%s], %s"]:format(index,
679-
GetSpellLink(index) or ""))
680780
end
681781
end
682-
elseif slotType == MYSLOT_ITEM then
683-
PickupItem(index)
684-
-- elseif slotType == MYSLOT_MACRO then
685-
-- local macroid = macro[index]
686782

687-
-- if not macroid then
688-
-- MySlot:Print(L["Ignore unknown macro [id=%s]"]:format(index))
689-
-- end
783+
-- this fallback should not happen, only to workaround some old export
784+
if not GetCursorInfo() then
785+
local spellName = GetSpellInfo(index)
786+
if spellName then
787+
PickupSpell(spellName)
788+
end
789+
end
690790

691-
-- if curType ~= MYSLOT_MACRO or curIndex ~= macroid then
692-
-- PickupMacro(macroid)
693-
-- end
791+
if not GetCursorInfo() then
792+
MySlot:Print(L["Ignore unlearned skill [id=%s], %s"]:format(index, GetSpellLink(index) or ""))
793+
end
794+
elseif slotType == MYSLOT_ITEM then
795+
PickupItem(index)
694796
elseif slotType == MYSLOT_SUMMONPET and strindex and strindex ~= curIndex then
695797
C_PetJournal.PickupPet(strindex, false)
696798
if not GetCursorInfo() then
@@ -765,7 +867,7 @@ function MySlot:RecoverData(msg, opt)
765867
if not opt.actionOpt.ignorePetActionBar then
766868
local pettoken = {}
767869
for i = 1, NUM_PET_ACTION_SLOTS, 1 do
768-
local name, _, isToken = GetPetActionInfo(i);
870+
local name, _, isToken = GetPetActionInfo(i)
769871
if isToken then
770872
pettoken[name] = i
771873
end

Myslot.toc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Interface: 110000
2-
## Interface-Classic: 11502
2+
## Interface-Classic: 11503
33
## Interface-Cata: 40400
44
## Interface-Wrath: 30403
55
## X-Curse-Project-ID: 48863

0 commit comments

Comments
 (0)