Use ClassicAPI exclusively for no-toggle detection

This commit is contained in:
Dusk-92
2026-09-04 18:46:33 +02:00
parent 06fc84d4fe
commit e852c6c7d8
+12 -33
View File
@@ -12,6 +12,10 @@ local module = ShaguTweaks:register({
}) })
module.enable = function(self) module.enable = function(self)
-- This fork requires ClassicAPI. Do not retain the old tooltip/action-name
-- scanners when the engine can identify auto-attack actions directly.
if not API or not API.autoattack or not API.autoattackbook or not API.actioninfo then return end
local attacking, shooting local attacking, shooting
local attackNames = { local attackNames = {
@@ -22,13 +26,13 @@ module.enable = function(self)
} }
local function AddAttackName(spellID, attackType) local function AddAttackName(spellID, attackType)
if not API or not API.GetSpellInfo then return end
local name = API.GetSpellInfo(spellID) local name = API.GetSpellInfo(spellID)
if name then attackNames[strlower(name)] = attackType end if name then attackNames[strlower(name)] = attackType end
end end
-- Add the current client's localized spell names while retaining the -- CastSpellByName still receives text rather than a spellbook/action ID.
-- original English aliases for the legacy fallback. -- Resolve the localized names once through ClassicAPI while retaining the
-- common English aliases used by macros and third-party addons.
AddAttackName(6603, "melee") AddAttackName(6603, "melee")
AddAttackName(75, "ranged") AddAttackName(75, "ranged")
AddAttackName(5019, "ranged") AddAttackName(5019, "ranged")
@@ -55,18 +59,14 @@ module.enable = function(self)
end end
local function activeSpell(spellID) local function activeSpell(spellID)
if not API or not API.autoattack or not spellID then return false end if not spellID then return false end
return (API.IsAutoAttackSpell(spellID) and attacking) or return (API.IsAutoAttackSpell(spellID) and attacking) or
(API.IsRangedAutoAttackSpell(spellID) and shooting) (API.IsRangedAutoAttackSpell(spellID) and shooting)
end end
local function activeSpellBook(index, booktype) local function activeSpellBook(index, booktype)
if API and API.autoattackbook then return (API.IsAutoAttackSpellBookItem(index, booktype) and attacking) or
return (API.IsAutoAttackSpellBookItem(index, booktype) and attacking) or (API.IsRangedAutoAttackSpellBookItem(index, booktype) and shooting)
(API.IsRangedAutoAttackSpellBookItem(index, booktype) and shooting)
end
return activeName(GetSpellName(index, booktype))
end end
local origCastSpell = CastSpell local origCastSpell = CastSpell
@@ -82,31 +82,10 @@ module.enable = function(self)
return origCastSpellByName(text, onself) return origCastSpellByName(text, onself)
end end
local tt
local function GetLegacyTooltip()
if tt then return tt end
tt = CreateFrame("GameTooltip", "ShaguTweaksNoToggleTT", nil, "GameTooltipTemplate")
tt:SetOwner(UIParent, "ANCHOR_NONE")
return tt
end
local origUseAction = UseAction local origUseAction = UseAction
function _G.UseAction(slot, clicked, onself) function _G.UseAction(slot, clicked, onself)
if API and API.actioninfo and API.autoattack then local actionType, spellID = API.GetActionInfo(slot)
local actionType, spellID = API.GetActionInfo(slot) if actionType == "spell" and activeSpell(spellID) then return end
if actionType == "spell" and activeSpell(spellID) then return end
if actionType then return origUseAction(slot, clicked, onself) end
end
-- Legacy clients have no action descriptor API. Keep the tooltip scan as
-- a fallback only, instead of paying for it on every spell/item action.
if HasAction(slot) and not GetActionText(slot) then
local tt = GetLegacyTooltip()
tt:SetOwner(UIParent, "ANCHOR_NONE")
tt:SetAction(slot)
local label = _G["ShaguTweaksNoToggleTTTextLeft1"]
if label and activeName(label:GetText()) then return end
end
return origUseAction(slot, clicked, onself) return origUseAction(slot, clicked, onself)
end end
end end