Add minimal modern ClassicAPI macro aliases

This commit is contained in:
Dusk-92
2026-08-30 09:51:11 +02:00
parent 1328a7e082
commit d52c455139
3 changed files with 60 additions and 24 deletions
+15 -5
View File
@@ -163,11 +163,21 @@ macro slots again for every button.
#### Macro Tweaks — fixed / ClassicAPI-aware
Registers modern-style `/startattack` and `/stopattack` slash commands on
Vanilla and routes them to ClassicAPI's non-toggling `StartAttack()` and
`StopAttack()` functions. This avoids Vanilla treating `/startattack` as an
unknown slash command and, unlike `AttackTarget()`, repeated use cannot toggle
an active auto-attack off.
Registers a deliberately small set of modern-style slash commands backed by
ClassicAPI:
- `/startattack [unit]` → `StartAttack(unit)`
- `/stopattack` → `StopAttack()`
- `/focus [unit]` → `FocusUnit(unit)` (defaults to current target)
- `/clearfocus` → `ClearFocus()`
Each alias is only registered when another addon has not already claimed the
same command. This keeps Macro Tweaks a compatibility/convenience layer rather
than duplicating ClassicAPI itself.
No `/castnotoggle` alias is added: ClassicAPI already recognizes
`CastSpellNoToggle("Spell")` directly inside macro bodies and tags the action
slot correctly, so an extra slash command would be redundant.
Container item lookup now prefers ClassicAPI item IDs/names.
+1
View File
@@ -56,6 +56,7 @@ versions already exist in ShaguTweaks-ClassicAPI:
### Macro
- Macro Icons
- Macro Tweaks
- modern ClassicAPI aliases: `/startattack`, `/stopattack`, `/focus`, `/clearfocus`
### Raid
- Enable Raid Frames
+44 -19
View File
@@ -4,7 +4,7 @@ local API = ShaguTweaks.API or {}
local module = ShaguTweaks:register({
title = T["Macro Tweaks"],
description = T["Add /equip, /use, /startattack and /stopattack to macros, remove #showtooltip from chat and hide macro commands from history."],
description = T["Add /equip, /use and modern ClassicAPI macro commands, remove #showtooltip from chat and hide macro commands from history."],
expansions = { ["vanilla"] = true, ["tbc"] = false },
maintainer = "@shagu (GitHub)",
category = T["Macro"],
@@ -32,6 +32,8 @@ module.enable = function(self)
if string.find(text, "^/cast%s*") then return end
if string.find(text, "^/startattack%s*") then return end
if string.find(text, "^/stopattack%s*") then return end
if string.find(text, "^/focus%s*") then return end
if string.find(text, "^/clearfocus%s*") then return end
end
ChatFrameEditBox._AddHistoryLine(self, text)
end
@@ -69,26 +71,49 @@ module.enable = function(self)
end
end
-- ClassicAPI exposes the modern non-toggling StartAttack/StopAttack verbs.
-- Register the corresponding slash commands so Vanilla's macro parser can
-- use the familiar modern syntax without falling through to "unknown command".
_G.SLASH_STARTATTACK1 = "/startattack"
_G.SlashCmdList.STARTATTACK = function(msg)
if type(_G.StartAttack) ~= "function" then return end
local unit
if msg then
_, _, unit = string.find(msg, "^%s*(.-)%s*$")
if unit == "" then unit = nil end
end
_G.StartAttack(unit)
-- ClassicAPI exposes several modern macro primitives as Lua functions but
-- Vanilla does not register their familiar slash-command equivalents.
-- Add only the small set that maps cleanly to modern macro syntax, and leave
-- any command already registered by another addon untouched.
local function TrimUnit(msg)
if not msg then return nil end
local _, _, unit = string.find(msg, "^%s*(.-)%s*$")
return unit ~= "" and unit or nil
end
_G.SLASH_STOPATTACK1 = "/stopattack"
_G.SlashCmdList.STOPATTACK = function()
if type(_G.StopAttack) == "function" then
_G.StopAttack()
if not _G.SlashCmdList.STARTATTACK then
_G.SLASH_STARTATTACK1 = "/startattack"
_G.SlashCmdList.STARTATTACK = function(msg)
if type(_G.StartAttack) == "function" then
_G.StartAttack(TrimUnit(msg))
end
end
end
if not _G.SlashCmdList.STOPATTACK then
_G.SLASH_STOPATTACK1 = "/stopattack"
_G.SlashCmdList.STOPATTACK = function()
if type(_G.StopAttack) == "function" then
_G.StopAttack()
end
end
end
if not _G.SlashCmdList.FOCUS then
_G.SLASH_FOCUS1 = "/focus"
_G.SlashCmdList.FOCUS = function(msg)
if type(_G.FocusUnit) == "function" then
_G.FocusUnit(TrimUnit(msg))
end
end
end
if not _G.SlashCmdList.CLEARFOCUS then
_G.SLASH_CLEARFOCUS1 = "/clearfocus"
_G.SlashCmdList.CLEARFOCUS = function()
if type(_G.ClearFocus) == "function" then
_G.ClearFocus()
end
end
end