From 5ec909cd5674e2ef46d3e8d59d6324818828be58 Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Sun, 30 Aug 2026 11:18:37 +0200 Subject: [PATCH] Make Extras ClassicAPI-first --- mods/bag-item-click.lua | 7 +++--- mods/bag-search.lua | 14 ++++++------ mods/macro-icons.lua | 16 ++++++------- mods/macro-tweaks.lua | 34 ++++++++++------------------ mods/raid-dispel-indicators.lua | 12 ++-------- mods/raid.lua | 21 +++++------------ mods/reduced-actionbar-bags.lua | 10 ++++---- mods/reduced-actionbar-micromenu.lua | 10 ++++---- 8 files changed, 47 insertions(+), 77 deletions(-) diff --git a/mods/bag-item-click.lua b/mods/bag-item-click.lua index f637d1d..76c479d 100644 --- a/mods/bag-item-click.lua +++ b/mods/bag-item-click.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local hooksecurefunc = ShaguTweaks.hooksecurefunc local module = ShaguTweaks:register({ @@ -26,8 +26,7 @@ module.enable = function(self) end local function ShiftDown() - if API.IsShiftKeyDown then return API.IsShiftKeyDown() end - return IsShiftKeyDown() + return API.IsShiftKeyDown() end -- Interception is intentional here: the feature must be able to suppress the @@ -44,7 +43,7 @@ module.enable = function(self) end elseif IsAuctionBrowsing() and not ShiftDown() then -- search item in auction house - local link = GetContainerItemLink(bag, slot) + local link = API.GetContainerItemLink(bag, slot) local name = link and string.sub(link, string.find(link, "%[")+1, string.find(link, "%]")-1) or "" BrowseName:SetText(name) AuctionFrameBrowse_Search() diff --git a/mods/bag-search.lua b/mods/bag-search.lua index 3fd922c..283ce38 100644 --- a/mods/bag-search.lua +++ b/mods/bag-search.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["Bag Search Bar"], @@ -52,13 +52,13 @@ module.enable = function(self) end local function GetContainerItemName(bag, slot) - if API.GetContainerItemID and API.GetItemNameByID then - local itemID = API.GetContainerItemID(bag, slot) - local name = itemID and API.GetItemNameByID(itemID) - if name then return name end - end + local itemID = API.GetContainerItemID(bag, slot) + local name = itemID and API.GetItemNameByID(itemID) + if name then return name end - local link = GetContainerItemLink(bag, slot) + -- The bridge uses C_Container.GetContainerItemInfo().hyperlink first and + -- falls back to Vanilla only when ClassicAPI cannot provide the link. + local link = API.GetContainerItemLink(bag, slot) if not link then return "" end local startPos = string.find(link, "%[") diff --git a/mods/macro-icons.lua b/mods/macro-icons.lua index 3744a09..4eb3ca6 100644 --- a/mods/macro-icons.lua +++ b/mods/macro-icons.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local libspell = ShaguTweaks.libspell local module = ShaguTweaks:register({ @@ -27,12 +27,10 @@ module.enable = function(self) end local function GetMacroData(actionSlot, cache) - if API.GetActionInfo then - local actionType, id = API.GetActionInfo(actionSlot) - if actionType == "macro" and id then - local _, _, body = GetMacroInfo(id) - if body then return id, body end - end + local actionType, id = API.GetActionInfo(actionSlot) + if actionType == "macro" and id then + local _, _, body = GetMacroInfo(id) + if body then return id, body end end local macroName = GetActionText(actionSlot) @@ -83,8 +81,8 @@ module.enable = function(self) -- ClassicAPI already resolves and caches the macro's primary spell. -- This is the correct modern behavior for a bare "#showtooltip" line and -- also covers /castsequence, CastSpellByName and CastSpellNoToggle. - if macroSlot and type(_G.GetMacroSpell) == "function" then - local spell, rank = _G.GetMacroSpell(macroSlot) + if macroSlot then + local spell, rank = API.GetMacroSpell(macroSlot) if spell then return spell, rank ~= "" and rank or nil end diff --git a/mods/macro-tweaks.lua b/mods/macro-tweaks.lua index 8f08eda..fee3257 100644 --- a/mods/macro-tweaks.lua +++ b/mods/macro-tweaks.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["Macro Tweaks"], @@ -57,16 +57,14 @@ module.enable = function(self) end local function GetBagItemName(bag, slot) - if API.GetContainerItemID and API.GetItemNameByID then - local itemID = API.GetContainerItemID(bag, slot) - local name = itemID and API.GetItemNameByID(itemID) - if name then return name end - end + local itemID = API.GetContainerItemID(bag, slot) + local name = itemID and API.GetItemNameByID(itemID) + if name then return name end - local itemLink = GetContainerItemLink(bag, slot) - if not itemLink then return end - local _, _, itemID = string.find(itemLink, "item:(%d+)") - return itemID and GetItemInfo(itemID) or nil + local itemLink = API.GetContainerItemLink(bag, slot) + local linkedID = itemLink and API.GetItemIDFromLink(itemLink) + local itemName = linkedID and API.GetItemInfo(linkedID) + return itemName end local function FindItem(item) @@ -114,27 +112,19 @@ module.enable = function(self) end RegisterSlashAlias("SHAGUTWEAKS_STARTATTACK", "/startattack", function(msg) - if type(_G.StartAttack) == "function" then - _G.StartAttack(TrimUnit(msg)) - end + API.StartAttack(TrimUnit(msg)) end) RegisterSlashAlias("SHAGUTWEAKS_STOPATTACK", "/stopattack", function() - if type(_G.StopAttack) == "function" then - _G.StopAttack() - end + API.StopAttack() end) RegisterSlashAlias("SHAGUTWEAKS_FOCUS", "/focus", function(msg) - if type(_G.FocusUnit) == "function" then - _G.FocusUnit(TrimUnit(msg)) - end + API.FocusUnit(TrimUnit(msg)) end) RegisterSlashAlias("SHAGUTWEAKS_CLEARFOCUS", "/clearfocus", function() - if type(_G.ClearFocus) == "function" then - _G.ClearFocus() - end + API.ClearFocus() end) local function EquipOrUse(msg) diff --git a/mods/raid-dispel-indicators.lua b/mods/raid-dispel-indicators.lua index c86da85..1d96401 100644 --- a/mods/raid-dispel-indicators.lua +++ b/mods/raid-dispel-indicators.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["Show Dispel Indicators"], @@ -71,15 +71,7 @@ module.enable = function(self) for dtype in pairs(debuffs) do frame.affected[dtype] = nil end for i = 1, 16 do - local dtype - if API.aurapositional and API.UnitDebuff then - local _, _, _, debuffType = API.UnitDebuff(frame.unitstr, i) - dtype = debuffType - else - local _, _, debuffType = UnitDebuff(frame.unitstr, i) - dtype = debuffType - end - + local dtype = API.GetDebuffType(frame.unitstr, i) if dtype then frame.affected[dtype] = true end end diff --git a/mods/raid.lua b/mods/raid.lua index 0314f7e..159eb0e 100644 --- a/mods/raid.lua +++ b/mods/raid.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["Enable Raid Frames"], @@ -72,19 +72,10 @@ end local UnitInRange = function(unitstr) if not unitstr then return false end - -- Prefer positional range data whenever the client exposes UnitPosition - -- (SuperWoW or another compatibility layer), then fall back to Vanilla. - if type(UnitPosition) == "function" then - local x1, y1, z1 = UnitPosition("player") - local x2, y2, z2 = UnitPosition(unitstr) - - if x1 and y1 and z1 and x2 and y2 and z2 then - local distance = ((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2)^.5 - if distance < 40 then return true end - end - end - - return CheckInteractDistance(unitstr, 4) and true or false + -- ClassicAPI provides a reach-aware 40-yard range check. Any compatibility + -- fallback is centralized in ShaguTweaks.API rather than duplicated here. + local inRange, checked = API.UnitInRange(unitstr) + return checked and inRange or false end -- Unit Frames @@ -610,7 +601,7 @@ module.enable = function(self) end raid.toggle:SetScript("OnMouseDown", function() - local shift = API.IsShiftKeyDown and API.IsShiftKeyDown() or IsShiftKeyDown() + local shift = API.IsShiftKeyDown() if shift then this.dragging = true this:SetScript("OnUpdate", UpdateToggleDrag) diff --git a/mods/reduced-actionbar-bags.lua b/mods/reduced-actionbar-bags.lua index f022d2b..5d8a5f8 100644 --- a/mods/reduced-actionbar-bags.lua +++ b/mods/reduced-actionbar-bags.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["Show Bags"], @@ -58,8 +58,8 @@ module.enable = function(self) bagframe:RegisterEvent("PLAYER_ENTERING_WORLD") bagframe:SetScript("OnDragStart", function() - local shift = API.IsShiftKeyDown and API.IsShiftKeyDown() or IsShiftKeyDown() - local control = API.IsControlKeyDown and API.IsControlKeyDown() or IsControlKeyDown() + local shift = API.IsShiftKeyDown() + local control = API.IsControlKeyDown() if not shift or not control then return end this:StartMoving() end) @@ -73,8 +73,8 @@ module.enable = function(self) if this.modifierTimer < .05 then return end this.modifierTimer = 0 - local shift = API.IsShiftKeyDown and API.IsShiftKeyDown() or IsShiftKeyDown() - local control = API.IsControlKeyDown and API.IsControlKeyDown() or IsControlKeyDown() + local shift = API.IsShiftKeyDown() + local control = API.IsControlKeyDown() if MouseIsOver(this) and shift and control then if not this.mousedisabled then -- disable mouse events on all frames diff --git a/mods/reduced-actionbar-micromenu.lua b/mods/reduced-actionbar-micromenu.lua index 3d1b4cf..06dc596 100644 --- a/mods/reduced-actionbar-micromenu.lua +++ b/mods/reduced-actionbar-micromenu.lua @@ -1,6 +1,6 @@ local _G = ShaguTweaks.GetGlobalEnv() local T = ShaguTweaks.T -local API = ShaguTweaks.API or {} +local API = ShaguTweaks.API local module = ShaguTweaks:register({ title = T["Show Micro Menu"], @@ -59,8 +59,8 @@ module.enable = function(self) microframe:RegisterEvent("PLAYER_ENTERING_WORLD") microframe:SetScript("OnDragStart", function() - local shift = API.IsShiftKeyDown and API.IsShiftKeyDown() or IsShiftKeyDown() - local control = API.IsControlKeyDown and API.IsControlKeyDown() or IsControlKeyDown() + local shift = API.IsShiftKeyDown() + local control = API.IsControlKeyDown() if not shift or not control then return end this:StartMoving() end) @@ -74,8 +74,8 @@ module.enable = function(self) if this.modifierTimer < .05 then return end this.modifierTimer = 0 - local shift = API.IsShiftKeyDown and API.IsShiftKeyDown() or IsShiftKeyDown() - local control = API.IsControlKeyDown and API.IsControlKeyDown() or IsControlKeyDown() + local shift = API.IsShiftKeyDown() + local control = API.IsControlKeyDown() if MouseIsOver(this) and shift and control then if not this.mousedisabled then -- disable mouse events on all frames