From 7f6a5b2bf253ea3638d2929e244bd4a76d22abc0 Mon Sep 17 00:00:00 2001 From: d87 Date: Mon, 15 Jul 2024 12:39:19 +0700 Subject: [PATCH] TWW API Support --- .luacheckrc | 5 + Aptechka-Mainline.toc | 2 +- Aptechka.lua | 108 +++++++++++++------- Aptechka.toc | 2 +- Options/DebuffHighlight.lua | 5 +- Options/LoadHooks.lua | 2 +- Options/SpellList.lua | 13 +-- Options/loader/AptechkaOptions-Mainline.toc | 2 +- Options/loader/AptechkaOptions.toc | 2 +- helpers.lua | 38 +++++-- launcher.lua | 4 +- 11 files changed, 122 insertions(+), 61 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index c02a02f..34b7f3a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -245,6 +245,11 @@ globals = { "GetActiveTalentGroup", "GetTalentGroupRole", + "C_Spell", + "C_UnitAuras", + "C_AddOns", + "Settings", + -- Disarm Blizz raid "PartyFrame", "UnregisterUnitWatch", diff --git a/Aptechka-Mainline.toc b/Aptechka-Mainline.toc index 40eccf2..ff27845 100644 --- a/Aptechka-Mainline.toc +++ b/Aptechka-Mainline.toc @@ -1,4 +1,4 @@ -## Interface: 100200 +## Interface: 110000 ## Title: Aptechka ## Notes: Raid Frames ## Version: @project-version@ diff --git a/Aptechka.lua b/Aptechka.lua index 403981a..611af16 100644 --- a/Aptechka.lua +++ b/Aptechka.lua @@ -22,6 +22,8 @@ local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs local UnitThreatSituation = UnitThreatSituation local UnitGroupRolesAssigned = UnitGroupRolesAssigned local UnitPhaseReason = UnitPhaseReason +local GetSpellName = helpers.GetSpellName +local GetSpellTexture = helpers.GetSpellTexture local GetSpecialization = GetSpecialization local GetSpecializationRole = GetSpecializationRole local GetActiveTalentGroup = GetActiveTalentGroup @@ -802,7 +804,7 @@ function Aptechka:GenerateMergedConfig() for additionalSpellID, enabled in pairs(opts.clones) do -- if clone spell ID is at the same time a root ID of another spell if config[category][additionalSpellID] then - local spellName = GetSpellInfo(additionalSpellID) + local spellName = GetSpellName(additionalSpellID) if spellName then print(string.format("[Aptechka] Conflicting spell IDs: %d (%s) already exists as root ID", additionalSpellID, spellName)) end @@ -3201,20 +3203,7 @@ end --------------------------- -- Ordered --------------------------- -local UnitAuraUniversal -- If available it's using slots API, otherwise just normal UnitAura -if apiLevel <= 4 then - UnitAuraUniversal = UnitAura - ForEachAura = function(frame, unit, filter, batchSize, func) - for i=1,100 do - local name, icon, count, debuffType, duration, expirationTime, caster, isStealable, nameplateShowSelf, spellID, canApplyAura, isBossAura = UnitAura(unit, i, filter) - if not name then break end - func(frame, unit, i, nil, filter, name, icon, count, debuffType, duration, expirationTime, caster, isStealable, nameplateShowSelf, spellID, canApplyAura, isBossAura) - end - end -else - UnitAuraUniversal = UnitAuraBySlot - -- ForEachAura = helpers.ForEachAura -- This one is using Slots API -end +local UnitAuraUniversal = C_UnitAuras.UnitAuraBySlot local BITMASK_DISEASE = helpers.BITMASK_DISEASE local BITMASK_POISON = helpers.BITMASK_POISON @@ -3503,17 +3492,35 @@ function Aptechka.DispelTypePostUpdate(frame, unit) end function Aptechka.DummyFunction() end -local handleBuffs = function(frame, unit, index, slot, filter, ...) - IndicatorAurasProc(frame, unit, index, slot, filter, ...) - BuffProc(frame, unit, index, slot, filter, ...) + +local function UnpackAuraData(auraData) + return + auraData.name, + auraData.icon, + auraData.charges, + auraData.dispelName, + auraData.duration, + auraData.expirationTime, + auraData.sourceUnit, + nil, + nil, + auraData.spellId +end + +local handleBuffs = function(frame, unit, index, slot, filter, auraData) + local name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID = UnpackAuraData(auraData) + + IndicatorAurasProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) + BuffProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) end -local handleDebuffs = function(frame, unit, index, slot, filter, ...) - IndicatorAurasProc(frame, unit, index, slot, filter, ...) - DebuffProc(frame, unit, index, slot, filter, ...) - HighlightProc(frame, unit, index, slot, filter, ...) - DispelTypeProc(frame, unit, index, slot, filter, ...) - EffectListProc(frame, unit, index, slot, filter, ...) +local handleDebuffs = function(frame, unit, index, slot, filter, auraData) + local name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID = UnpackAuraData(auraData) + IndicatorAurasProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) + DebuffProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) + HighlightProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) + DispelTypeProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) + EffectListProc(frame, unit, index, slot, filter, name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellID) end function Aptechka.FrameScanAuras(frame, unit) @@ -3652,7 +3659,7 @@ function Aptechka.TestDebuffSlotsForUnit(frame, unit) local randomIDs = { 5211, 19577, 172, 408, 15286, 853, 980, 589, 118, 605 } for i=1,6 do local spellID = randomIDs[math.random(#randomIDs)] - local name, _, icon = GetSpellInfo(spellID) + local name, _, icon = GetSpellName(spellID) local duration = math.random(20)+5 local hasCount = math.random(3) == 1 local count = hasCount and math.random(18) or 0 @@ -3695,7 +3702,7 @@ function Aptechka.TestCastBar(frame, unit) local spellID = 172 local srcGUID = UnitGUID("player") local castType = "CAST" - local name, _, icon = GetSpellInfo(spellID) + local name, _, icon = GetSpellName(spellID) local dstGUID = srcGUID local totalCasts = math.random(5) local duration = math.random(20)+5 @@ -3784,8 +3791,8 @@ function Aptechka:RemoveWidget(wname) end function Aptechka:OpenGUI() - if not IsAddOnLoaded("AptechkaOptions") then - LoadAddOn("AptechkaOptions") + if not C_AddOns.IsAddOnLoaded("AptechkaOptions") then + C_AddOns.LoadAddOn("AptechkaOptions") end AptechkaOptions.Open() -- InterfaceOptionsFrame_OpenToCategory("Aptechka") @@ -3828,7 +3835,7 @@ function Aptechka:ListSpellsForWidget(widgetName) local name local icon if type(spellID) == "number" then - name = GetSpellInfo(spellID) or "" + name = GetSpellName(spellID) or "" icon = GetSpellTexture(spellID) else name = spellID @@ -4187,7 +4194,7 @@ Aptechka.Commands = { local spellID = tonumber(args) if spellID then Aptechka.db.global.customBlacklist[spellID] = true - local spellName = GetSpellInfo(spellID) or "" + local spellName = GetSpellName(spellID) or "" print(string.format("%s (%d) added to debuff blacklist", spellName, spellID)) end elseif cmd == "del" then @@ -4196,18 +4203,18 @@ Aptechka.Commands = { local val = nil if defaultBlacklist[spellID] then val = false end -- if nil it'll fallback on __index Aptechka.db.global.customBlacklist[spellID] = val - local spellName = GetSpellInfo(spellID) or "" + local spellName = GetSpellName(spellID) or "" print(string.format("%s (%d) removed from debuff blacklist", spellName, spellID)) end else print("Default blacklist:") for spellID in pairs(defaultBlacklist) do - local spellName = GetSpellInfo(spellID) or "" + local spellName = GetSpellName(spellID) or "" print(string.format(" %s (%d)", spellName, spellID)) end print("Custom blacklist:") for spellID in pairs(Aptechka.db.global.customBlacklist) do - local spellName = GetSpellInfo(spellID) or "" + local spellName = GetSpellName(spellID) or "" print(string.format(" %s (%d)", spellName, spellID)) end end @@ -4444,10 +4451,41 @@ end Aptechka.UNIT_SPELLCAST_INTERRUPTED = Aptechka.UNIT_SPELLCAST_FAILED + +function Aptechka.InterfaceOptions_AddCategory(frame, addOn, position) + -- cancel is no longer a default option. May add menu extension for this. + frame.OnCommit = frame.okay; + frame.OnDefault = frame.default; + frame.OnRefresh = frame.refresh; + + if frame.parent then + local category = Settings.GetCategory(frame.parent); + local subcategory, layout = Settings.RegisterCanvasLayoutSubcategory(category, frame, frame.name, frame.name); + subcategory.ID = frame.name; + return subcategory, category; + else + local category, layout = Settings.RegisterCanvasLayoutCategory(frame, frame.name, frame.name); + category.ID = frame.name; + Settings.RegisterAddOnCategory(category); + return category; + end +end + +-- Deprecated. Use Settings.OpenToCategory(). +function Aptechka.InterfaceOptionsFrame_OpenToCategory(categoryIDOrFrame) + if type(categoryIDOrFrame) == "table" then + local categoryID = categoryIDOrFrame.name; + return Settings.OpenToCategory(categoryID); + else + return Settings.OpenToCategory(categoryIDOrFrame); + end +end + + function Aptechka:CreateBlizzOptionsPanel() local f = CreateFrame('Frame', "AptechkaBlizzOptionsPanel", InterfaceOptionsFrame) f.name = "Aptechka" - InterfaceOptions_AddCategory(f); + Aptechka.InterfaceOptions_AddCategory(f); local content = CreateFrame("Frame", "$parentContent", f) content:SetPoint("TOPLEFT", 10, -10) @@ -4542,7 +4580,7 @@ do local tooltip = self.tooltipPool:Acquire() tooltip:SetOwner(frame, "ANCHOR_NONE") - local name,_, texture = GetSpellInfo(spellID) + local name, _, texture = GetSpellName(spellID) tooltip.iconTexture:SetTexture(texture) tooltip:SetUnitAura(icon.unit, icon.index, icon.filter) diff --git a/Aptechka.toc b/Aptechka.toc index 9e4eb91..25b7cd4 100644 --- a/Aptechka.toc +++ b/Aptechka.toc @@ -1,4 +1,4 @@ -## Interface: 100200 +## Interface: 110000 ## Title: Aptechka ## Notes: Raid Frames ## Version: @project-version@ diff --git a/Options/DebuffHighlight.lua b/Options/DebuffHighlight.lua index e0298b5..50018f7 100644 --- a/Options/DebuffHighlight.lua +++ b/Options/DebuffHighlight.lua @@ -4,6 +4,7 @@ local L = Aptechka.L local defaultDebuffHighlights = AptechkaDefaultConfig.defaultDebuffHighlights +local GetSpellName = Aptechka.util.GetSpellName local function IsSpellInList(list, id) for cat, spells in pairs(list) do for spellId, opts in pairs(spells) do @@ -233,7 +234,7 @@ function AptechkaHybridScrollMixin:RefreshLayout() button.categoryMiddle:Hide(); local spellId, prio, commentText = unpack(item) - local spellName, _, tex = GetSpellInfo(spellId) + local spellName, _, tex = GetSpellName(spellId) button.spellId = spellId icon:SetPoint("LEFT", 15, 0) icon:SetTexture(tex); @@ -279,7 +280,7 @@ function ns.CreateSpellDataPanel() spellID:SetRelativeWidth(0.13) spellID:SetCallback("OnTextChanged", function(self, event, value) local v = tonumber(value) - if v and v > 0 and GetSpellInfo(v) then + if v and v > 0 and GetSpellName(v) then self.parent.opts["spellID"] = v self.editbox:SetTextColor(1,1,1) self.parent.controls.save:SetDisabled(false) diff --git a/Options/LoadHooks.lua b/Options/LoadHooks.lua index 93404ac..94a4890 100644 --- a/Options/LoadHooks.lua +++ b/Options/LoadHooks.lua @@ -110,7 +110,7 @@ function f.Open() WIDGETCONFIG = widgetsFrame, } - + treegroup.text = "123" treegroup:SetCallback("OnGroupSelected", function(self, event, group) if self.customPanel then diff --git a/Options/SpellList.lua b/Options/SpellList.lua index e1d4ecf..35d7590 100644 --- a/Options/SpellList.lua +++ b/Options/SpellList.lua @@ -5,7 +5,8 @@ local L = Aptechka.L local LSM = LibStub("LibSharedMedia-3.0") local newFeatureIcon = "|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:0:-1|t" - +local GetSpellName = Aptechka.util.GetSpellName +local GetSpellTexture = Aptechka.util.GetSpellTexture local AceGUI = LibStub("AceGUI-3.0") local rootFrame local FORM_CACHE = {} @@ -68,7 +69,7 @@ function ns.GenerateCategoryTree(self, settingsClass, category) if isTemplate or defaultSpellList[spellID] or customSpellList[spellID] then local name if type(spellID) == "number" then - name = (GetSpellInfo(spellID) or "") or opts.name + name = (GetSpellName(spellID) or "") or opts.name else name = spellID end @@ -220,18 +221,18 @@ local function form_save(form) --invalid spell id string return end - if not GetSpellInfo(spellID) then + if not GetSpellName(spellID) then return -- spell doesn't exist end -- if not opts.name then - -- opts.name = GetSpellInfo(spellID) + -- opts.name = GetSpellName(spellID) -- end opts.spellID = nil end if not opts.name then - opts.name = GetSpellInfo(spellID) + opts.name = GetSpellName(spellID) if category == "traces" then opts.name = opts.name.."Trace" end @@ -449,7 +450,7 @@ local function form_spellID(form) spellID:SetRelativeWidth(0.2) spellID:SetCallback("OnTextChanged", function(self, event, value) local v = tonumber(value) - if v and v > 0 and GetSpellInfo(v) then + if v and v > 0 and GetSpellName(v) then self.parent.opts["spellID"] = v self.editbox:SetTextColor(1,1,1) else diff --git a/Options/loader/AptechkaOptions-Mainline.toc b/Options/loader/AptechkaOptions-Mainline.toc index c86ad9a..dc446de 100644 --- a/Options/loader/AptechkaOptions-Mainline.toc +++ b/Options/loader/AptechkaOptions-Mainline.toc @@ -1,4 +1,4 @@ -## Interface: 100200 +## Interface: 110000 ## Title: AptechkaOptions ## Notes: Options module for Aptechka ## Author: d87 diff --git a/Options/loader/AptechkaOptions.toc b/Options/loader/AptechkaOptions.toc index c86ad9a..dc446de 100644 --- a/Options/loader/AptechkaOptions.toc +++ b/Options/loader/AptechkaOptions.toc @@ -1,4 +1,4 @@ -## Interface: 100200 +## Interface: 110000 ## Title: AptechkaOptions ## Notes: Options module for Aptechka ## Author: d87 diff --git a/helpers.lua b/helpers.lua index 7a66d57..8503b7f 100644 --- a/helpers.lua +++ b/helpers.lua @@ -9,6 +9,7 @@ local _, playerClass = UnitClass("player") config["GLOBAL"] = { auras = {}, traces = {}, } config[playerClass] = { auras = {}, traces = {}, } + local isClassic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC local APILevel = math.floor(select(4,GetBuildInfo())/10000) @@ -33,10 +34,25 @@ helpers.FRAMELEVEL = { FLASH = 19, } +if C_Spell.GetSpellInfo then + local C_Spell_GetSpellInfo = C_Spell.GetSpellInfo + helpers.GetSpellName = function(spellId) + local info = C_Spell_GetSpellInfo(spellId) + if info then + return info.name, info.iconID + end + end + helpers.GetSpellTexture = C_Spell.GetSpellTexture +else + helpers.GetSpellName = _G.GetSpellInfo + helpers.GetSpellTexture = _G.GetSpellTexture +end +local GetSpellName = helpers.GetSpellName + if APILevel == 1 then helpers.spellNameToID = {} helpers.AddSpellNameRecognition = function(lastRankID) - helpers.spellNameToID[GetSpellInfo(lastRankID)] = lastRankID + helpers.spellNameToID[GetSpellName(lastRankID)] = lastRankID end end @@ -154,7 +170,7 @@ function helpers.UnwrapConfigTemplates(configCategory) end function helpers.AddLoadableAura(data, todefault) - if data.id then data.name = GetSpellInfo(data.id) end + if data.id then data.name = GetSpellName(data.id) end if data.name == nil then print (data.id.." spell id missing") return end if data.prototype then @@ -182,7 +198,7 @@ local function PrepareAuraOpts(data) data.clones = t end - if data.id and not data.name then data.name = GetSpellInfo(data.id) end + if data.id and not data.name then data.name = GetSpellName(data.id) end if data.name == nil then -- print(string.format("[Aptechka] %d spell id missing", data.id)) return @@ -235,7 +251,7 @@ function helpers.AddTrace(data) data.clones = t end - if data.id then data.name = GetSpellInfo(data.id) or data.name end + if data.id then data.name = GetSpellName(data.id) or data.name end if not config.traces then config.traces = {} end if not data.name then -- print(string.format("[Aptechka] %d spell id missing", data.id)) @@ -279,7 +295,7 @@ end helpers.ClickMacro = function(macro) if AptechkaUserConfig then config = AptechkaUserConfig else config = AptechkaDefaultConfig end if not config.enableClickCasting then return end - config.ClickCastingMacro = macro:gsub("spell:(%d+)",GetSpellInfo):gsub("([ \t]+)/",'/') + config.ClickCastingMacro = macro:gsub("spell:(%d+)",GetSpellName):gsub("([ \t]+)/",'/') end helpers.BindTarget = function(str) @@ -592,15 +608,15 @@ function helpers.GetHorizontalAlignmentFromPoint(p1) end -local UnitAuraSlots = UnitAuraSlots -local UnitAuraBySlot = UnitAuraBySlot +local GetAuraSlots = C_UnitAuras.GetAuraSlots +local GetAuraDataBySlot = C_UnitAuras.GetAuraDataBySlot local function ForEachAuraHelper(frame, unit, index, filter, func, continuationToken, ...) - -- continuationToken is the first return value of UnitAuraSlots() + -- continuationToken is the first return value of GetAuraSlots() local n = select('#', ...); for i=1, n do local slot = select(i, ...); - local result = func(frame, unit, index, slot, filter, UnitAuraBySlot(unit, slot)) + local result = func(frame, unit, index, slot, filter, GetAuraDataBySlot(unit, slot)) if result == -1 then -- if func returns -1 then no further slots are needed, so don't return continuationToken @@ -620,7 +636,7 @@ function helpers.ForEachAura(frame, unit, filter, maxCount, func) local index = 1 repeat -- continuationToken is the first return value of UnitAuraSltos - continuationToken, index = ForEachAuraHelper(frame, unit, index, filter, func, UnitAuraSlots(unit, filter, maxCount, continuationToken)); + continuationToken, index = ForEachAuraHelper(frame, unit, index, filter, func, GetAuraSlots(unit, filter, maxCount, continuationToken)); until continuationToken == nil; return index @@ -629,7 +645,7 @@ end do local IsSpellInRange = _G.IsSpellInRange function helpers.RangeCheckBySpell(spellID) - local spellName = GetSpellInfo(spellID) + local spellName = GetSpellName(spellID) return function(unit) return (IsSpellInRange(spellName,unit) == 1) end diff --git a/launcher.lua b/launcher.lua index eec1a62..c49a17e 100644 --- a/launcher.lua +++ b/launcher.lua @@ -34,7 +34,7 @@ function Aptechka:CreteMinimapIcon() end - LoadAddOn('AptechkaOptions') + C_AddOns.LoadAddOn('AptechkaOptions') Aptechka:OpenGUI() --[[ InterfaceOptionsFrame_OpenToCategory("Aptechka") @@ -57,7 +57,7 @@ function Aptechka:CreteMinimapIcon() OnTooltipShow = function(tooltip) if not tooltip or not tooltip.AddLine then return end - GameTooltip_SetTitle(tooltip, string.format("%s %s",addonName, GetAddOnMetadata(addonName, "version"))) + GameTooltip_SetTitle(tooltip, string.format("%s %s",addonName, C_AddOns.GetAddOnMetadata(addonName, "version"))) GameTooltip_AddInstructionLine(tooltip, string.format("LeftClick - %s", L"Profile Settings")) GameTooltip_AddInstructionLine(tooltip, string.format("|cffc9e06cCtrl-LeftClick - %s|r", L"Unlock")) --[[