diff --git a/Compatibility/SuperMacro.lua b/Compatibility/SuperMacro.lua index 89d60af..2cd1c01 100644 --- a/Compatibility/SuperMacro.lua +++ b/Compatibility/SuperMacro.lua @@ -1,59 +1,63 @@ -- CleveRoidMacros/Compatibility/SuperMacro.lua --- Makes SuperMacro's Super tab play nicely with CleveRoidMacros conditionals. +-- Make SuperMacro’s RunLine play nicely with CleveRoidMacros (incl. /castsequence) -local _G = _G or getfenv(0) +local _G = _G or getfenv(0) local CRM = _G.CleveRoids or {} _G.CleveRoids = CRM local function install_supermacro_hook() - if CRM.SM_RunLineHooked then return end - if type(_G.RunLine) ~= "function" then return end + if CRM.SM_RunLineHooked then return end + if type(_G.RunLine) ~= "function" then return end - -- Build the map of commands we want CRM to execute for bracketed lines. - local hooks = { - cast = { action = CRM.DoCast }, - target = { action = CRM.DoTarget }, - use = { action = CRM.DoUse }, - castsequence = { action = CRM.DoCastSequence }, - } + -- Commands we only intercept when they use bracket/extended syntax + local bracketHooks = { + cast = CRM.DoCast, + target = CRM.DoTarget, + use = CRM.DoUse, + } - CRM.Hooks = CRM.Hooks or {} - CRM.Hooks.RunLine = CRM.Hooks.RunLine or _G.RunLine + CRM.Hooks = CRM.Hooks or {} + CRM.Hooks.RunLine = CRM.Hooks.RunLine or _G.RunLine - _G.RunLine = function(...) - for i = 1, arg.n do - local text = arg[i] - -- Respect /stopmacro from CRM - if CRM.stopmacro then - CRM.stopmacro = false - return true - end + _G.RunLine = function(...) + for i = 1, arg.n do + local text = arg[i] + if CRM.stopmacro then + CRM.stopmacro = false + return true + end - local handled = false - if type(text) == "string" then - -- Look for "/ [ ... " or "/ !..." - for cmd, def in pairs(hooks) do - local b, e = string.find(text, "^/" .. cmd .. "%s+[!%[]") - if b then - local msg = string.sub(text, e) -- keep the leading [ or ! - -- trim space just in case - msg = string.gsub(msg, "^%s+", "") - -- Hand off to CRM's executor (e.g., DoCast), which knows how to evaluate conditionals - pcall(def.action, msg) - handled = true - break - end - end - end - - if not handled then - -- Default behavior (lets SuperMacro process non-conditional lines) - CRM.Hooks.RunLine(text) + local handled = false + if type(text) == "string" then + -- 1) Always handle /castsequence (with or without conditionals) + local b1, e1, rest = string.find(text, "^%s*/castsequence%s*(.*)") + if b1 then + local msg = CRM.Trim(rest or "") + local seq = CRM.GetSequence(msg) + if seq then pcall(CRM.DoCastSequence, seq) end + handled = true + else + -- 2) Bracketed/advanced forms for /cast, /target, /use + for cmd, action in bracketHooks do + local b2, e2 = string.find(text, "^%s*/" .. cmd .. "%s+[!%[]") + if b2 then + local msg = string.sub(text, e2) + msg = string.gsub(msg, "^%s+", "") + pcall(action, msg) + handled = true + break end + end end - end + end - CRM.SM_RunLineHooked = true + if not handled then + CRM.Hooks.RunLine(text) -- fall back to SuperMacro’s original logic + end + end + end + + CRM.SM_RunLineHooked = true end -- Install after either addon is ready (order-agnostic) @@ -61,11 +65,11 @@ local f = CreateFrame("Frame") f:RegisterEvent("ADDON_LOADED") f:RegisterEvent("PLAYER_LOGIN") f:SetScript("OnEvent", function(_, event, addon) - if event == "ADDON_LOADED" then - if addon == "SuperMacro" or addon == "CleveRoidMacros" then - install_supermacro_hook() - end - else -- PLAYER_LOGIN as a final safety net - install_supermacro_hook() + if event == "ADDON_LOADED" then + if addon == "SuperMacro" or addon == "CleveRoidMacros" then + install_supermacro_hook() end + else + install_supermacro_hook() + end end)