From 3ee68a3e84e6a4edcddf0bf74cdf8f35bdbcd04a Mon Sep 17 00:00:00 2001 From: Jrc13245 Date: Tue, 26 Aug 2025 16:25:56 -0400 Subject: [PATCH] cleveroids syntax now works inside supermacro super tab macros --- Compatibility/SuperMacro.lua | 76 ++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/Compatibility/SuperMacro.lua b/Compatibility/SuperMacro.lua index 14d3db3..89d60af 100644 --- a/Compatibility/SuperMacro.lua +++ b/Compatibility/SuperMacro.lua @@ -1,21 +1,71 @@ +-- CleveRoidMacros/Compatibility/SuperMacro.lua +-- Makes SuperMacro's Super tab play nicely with CleveRoidMacros conditionals. + local _G = _G or getfenv(0) -local CleveRoids = _G.CleveRoids or {} +local CRM = _G.CleveRoids or {} +_G.CleveRoids = CRM -local Extension = CleveRoids.RegisterExtension("Compatibility_SuperMacro") -Extension.RegisterEvent("ADDON_LOADED", "OnLoad") +local function install_supermacro_hook() + if CRM.SM_RunLineHooked then return end + if type(_G.RunLine) ~= "function" then return end -function Extension.RunMacro(name) - CleveRoids.ExecuteMacroByName(name) -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 }, + } -function Extension.OnLoad() - if not SuperMacroFrame then - return + 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 + + 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) + end + end end - Extension.Hook("RunMacro", "RunMacro", true) - Extension.UnregisterEvent("ADDON_LOADED", "Onload") + CRM.SM_RunLineHooked = true end - -_G["CleveRoids"] = CleveRoids \ No newline at end of file +-- Install after either addon is ready (order-agnostic) +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() + end +end)