From 5a39adfb725597eeb064ac3a56447b8b15b257db Mon Sep 17 00:00:00 2001 From: Ahmil Jilani Date: Thu, 26 Feb 2009 01:20:00 -0500 Subject: [PATCH] 1.8.2 --- SuperDuperMacro/MacroInterpreter.lua | 224 ++++++++++++++++++++++++++++++++++ SuperDuperMacro/SuperDuperMacro.lua | 35 +++--- SuperDuperMacro/SuperDuperMacro.toc | 5 +- SuperDuperMacro/sdm Readme.txt | 6 +- 4 files changed, 253 insertions(+), 17 deletions(-) create mode 100644 SuperDuperMacro/MacroInterpreter.lua diff --git a/SuperDuperMacro/MacroInterpreter.lua b/SuperDuperMacro/MacroInterpreter.lua new file mode 100644 index 0000000..c58e23c --- /dev/null +++ b/SuperDuperMacro/MacroInterpreter.lua @@ -0,0 +1,224 @@ +--This file contains code that is adapted from ChatFrame.lua + +local funcsToGetSpell = {} -- Analoguous to SecureCmdList in ChatFrame.lua + +funcsToGetSpell["CAST"] = function(msg) + local action, target = SecureCmdOptionParse(msg); + if ( action ) then + local name, bag, slot = SecureCmdItemParse(action); + if ( slot or GetItemInfo(name) ) then + return "item", name, target, bag, slot + else + return "spell", action, target + end + end +end +funcsToGetSpell["USE"] = funcsToGetSpell["CAST"]; + +funcsToGetSpell["CASTRANDOM"] = function(msg) + local actions, target = SecureCmdOptionParse(msg); + if ( actions ) then + local action = strtrim(strsplit(",", actions)); --took out GetRandomArgument because the icon always shows the first spell + local name, bag, slot = SecureCmdItemParse(action); + if ( slot or GetItemInfo(name) ) then + return "item", name, target, bag, slot + else + return "spell", action, target + end + end +end +funcsToGetSpell["USERANDOM"] = funcsToGetSpell["CASTRANDOM"]; + +funcsToGetSpell["CASTSEQUENCE"] = function(msg) + local sequence, target = SecureCmdOptionParse(msg); + if ( sequence ) then + local _,item,spell = QueryCastSequence(sequence) + if spell then + return "spell", spell, target + elseif item then + return "item", item, target + end + end +end + +funcsToGetSpell["EQUIP"] = function(msg) + local item = SecureCmdOptionParse(msg); + if ( item ) then + return "item", SecureCmdItemParse(item) --may be in the format "", "item:", or an itemlink + end +end + +funcsToGetSpell["EQUIP_TO_SLOT"] = function(msg) + local action = SecureCmdOptionParse(msg); + if ( action ) then + local slot, item = strmatch(action, "^(%d+)%s+(.*)"); + if ( item ) then + return "item", SecureCmdItemParse(item) + end + end +end + +--[[SecureCmdList["STOPMACRO"] = function(msg) --this command doesn't affect the icon, but I think it should! + if not ( SecureCmdOptionParse(msg) ) then + return true + end +end]] + +--[[funcsToGetSpell["CLICK"] = function(msg) + local action = SecureCmdOptionParse(msg); + if ( action and action ~= "" ) then + local name, mouseButton, down = strmatch(action, "([^%s]+)%s+([^%s]+)%s*(.*)"); + if ( not name ) then + name = action; + end + local button = GetClickFrame(name); + if ( button and button:IsObjectType("Button") ) then + if button:GetAttribute("type")=="macro" then + local text = button:GetAttribute("macrotext") + if text then + return sdm_GetMacrotextSpell(text, mouseButton, down) + end + end + end + end +end]] + +sdm_importantSlashHash = {} -- Analoguous to hash_SecureCmdList in ChatFrame.lua. Keys are slash commands that should not be ignored when getting a macro's icon. Values are functions that return the spell or item. +for index, value in pairs(funcsToGetSpell) do + local i = 1; + local cmdString = _G["SLASH_"..index..i]; + while ( cmdString ) do + cmdString = strupper(cmdString); + sdm_importantSlashHash[cmdString] = value; -- add to hash + i = i + 1; + cmdString = _G["SLASH_"..index..i]; + end +end + +function sdm_GetMacrotextAction(multiLineText) -- Input & calculations are adapted from ChatEdit_ParseText in ChatFrame.lua, and output is a combination of GetMacroSpell and GetMacroItem. + local show, showtooltip + for text in multiLineText:gmatch("[^\r\n]+") do -- is a single line of the macro + if ( strlen(text) > 0 ) then + --deal with #show and #showtooltip + local showtxt, showcmd = sdm_SplitString(text:trim(), " ", 1) + if showcmd then + showcmd = showcmd:lower() + if showcmd:sub(1,5)=="#show" then + show=1 + if showcmd:sub(1,12)=="#showtooltip" then + showtooltip=1 + end + text = "/cast "..showtxt + end + end + --get the info from the line + if ( strsub(text, 1, 1) == "/" ) then + local command = strmatch(text, "^(/[^%s]+)") or ""; + local msg = ""; + if ( command ~= text ) then + msg = strsub(text, strlen(command) + 2); + end + command = strupper(command); + if sdm_importantSlashHash[command] then + --return the info. If no info, move on to the next line. + local type,name,target,bag,slot = sdm_importantSlashHash[command](strtrim(msg)) + local nameReturn, otherReturn + if type=="spell" then + nameReturn, otherReturn = GetSpellName(name) + elseif type=="item" then + nameReturn = GetItemInfo(name) + -- this part mimics SecureCmdUseItem in ChatFrame.lua + if bag then + otherReturn = GetContainerItemLink(bag, slot) + elseif slot then + otherReturn = GetInventoryItemLink("player", slot) + else + -- this part may or may not be necessary, but it produces the exact numbers within the item link from GetMacroItem + for i=0,23 do + local link = GetInventoryItemLink("player",i) + if link and link:sub(link:find("%[")+1,link:find("\]")-1)==nameReturn then + otherReturn = link + break + end + end + if not otherReturn then + for i=-2,11 do + for j=1,GetContainerNumSlots(i) do + local link = GetContainerItemLink(i,j) + if link and link:sub(link:find("%[")+1,link:find("\]")-1)==nameReturn then + otherReturn = link + break + end + end + end + end + end + if not otherReturn then _,otherReturn = GetItemInfo(name) end + end + if not nameReturn then return end + return type, nameReturn, otherReturn, target, show, showtooltip + end + end + end + end +end + +function sdm_CompareFuncs() + local result + for i=1,54 do + local body = GetMacroBody(i) + if body then + local a1,a2,a3,b1,b2,b3 + b1,b2,b3 = sdm_GetMacrotextAction(body) + a2,a3 = GetMacroSpell(i) + if a2 then + a1 = "spell" + else + a2,a3 = GetMacroItem(i) + if a2 then + a1 = "item" + end + end + if a1~=b1 or a2~=b2 or a3~=b3 then + result = (result or "").."body: "..body.."\nBlizz got: "..(a1 or "").." "..(a2 or "").." "..(a3 or "").."\nYou got: "..(b1 or "").." "..(b2 or "").." "..(b3 or "").."\n\n" + end + end + end + if result then + local f = getglobal("sdm_testResultFrame") + if not f then + f = CreateFrame("Frame", "SDM_testResultFrame", UIParent) + f:SetWidth(300) + f:SetHeight(300) + f:SetBackdrop({bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",tile = true,tileSize = 32,edgeSize = 32,insets = {left = 11,right = 11,top = 12,bottom = 10}}) + f:SetPoint("CENTER") + f.close = CreateFrame("Button", nil, f, "UIPanelCloseButton") + f.close:SetPoint("TOPRIGHT",-10,-10) + f.close:SetScript("OnClick", function() f:Hide() end) + f.scroll = CreateFrame("ScrollFrame", "sdm_sillyName", f, "UIPanelScrollFrameTemplate") + f.box = CreateFrame("EditBox", nil, f) + f.scroll:SetScrollChild(box) + f.scroll:SetHeight(100) + f.scroll:SetWidth(100) + f.scroll:SetPoint("BOTTOM") + f.box:SetHeight(100) + f.box:SetWidth(100) + f.box:SetFontObject("GameFontHighlightSmall") + f.box:SetMultiLine(1) + f.box:SetScript("OnTextChanged", function(self) if self:GetText()~=result then self:SetText(result) end self:HighlightText() end) + f.box:SetScript("OnCursorChanged", f.box.HighlightText) + f.box:SetScript("OnEditFocusLost", function(self) self:SetFocus() self:HighlightText() end) + f.text = f:CreateFontString(nil, "ARTWORK", "GameFontNormal") + f.text:SetPoint("TOPLEFT",20,-30) + f.text:SetPoint("BOTTOMRIGHT",-20,20) + f.text:SetJustifyH("TOP") + f.text:SetText("Press ctrl-C or cmd-C to copy the selected text below (it's selected right now, even if you can't see it). Kindly head over to wowinterface.com and paste the text into a comment. Thanks!") + end + f:Show() + f.box:SetText(result) + else + print("SDM test result: All correct!") + end +end + +--now, hook the events that update the action buttons \ No newline at end of file diff --git a/SuperDuperMacro/SuperDuperMacro.lua b/SuperDuperMacro/SuperDuperMacro.lua index c289ce6..aaae721 100644 --- a/SuperDuperMacro/SuperDuperMacro.lua +++ b/SuperDuperMacro/SuperDuperMacro.lua @@ -5,7 +5,9 @@ function sdm_SlashHandler(command) else sdm_mainFrame:Show() end - elseif command:sub(1,4)=="run " then + elseif command:lower()=="test" then + sdm_CompareFuncs() + elseif command:sub(1,4):lower()=="run " then sdm_RunScript(command:sub(5)) else print("SDM did not recognize the command \""..command.."\"") end @@ -59,21 +61,26 @@ function sdm_SetUpMacro(mTab) if type=="b" then text="#sdm"..sdm_numToChars(ID).."\n"..text end - local frameText = "" local nextFrameName = "sdh"..sdm_numToChars(ID) - local linkText = "\n"..sdm_GetLinkText(nextFrameName) - for line in text:gmatch("[^\r\n]+") do - if line~="" then - if frameText~="" then --if this is not the first line of the frame, we need to add a carriage return before it. - line="\n"..line - end - if frameText:len()+line:len()+linkText:len() > charLimit then --adding this line would be too much, so just add the link and be done with it. (note that this line does NOT get removed from the master text) - frameText = frameText..linkText - break + local frameText + if text:len()<=charLimit then + frameText = text + else + frameText = "" + local linkText = "\n"..sdm_GetLinkText(nextFrameName) + for line in text:gmatch("[^\r\n]+") do + if line~="" then + if frameText~="" then --if this is not the first line of the frame, we need to add a carriage return before it. + line="\n"..line + end + if frameText:len()+line:len()+linkText:len() > charLimit then --adding this line would be too much, so just add the link and be done with it. (note that this line does NOT get removed from the master text) + frameText = frameText..linkText + break + end + frameText = frameText..line end - frameText = frameText..line + text=text:sub((text:find("\n") or text:len())+1) --remove the line from the text end - text=text:sub((text:find("\n") or text:len())+1) --remove the line from the text end sdm_SetUpMacroFrames(nextFrameName, text, 1) if type=="b" then @@ -1306,7 +1313,7 @@ sdm_countUpdateMacrosEvents=0 sdm_usedFrameNumsStart={} sdm_usedFrameNumsStop={1} sdm_validChars = {1,2,3,4,5,6,7,8,11,12,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255} -sdm_nicTors = {115,100,109,95,113,105,97,110,61,40,49,48,56,48,47,54,48,48,41,46,46,39,46,49,39,32,115,100,109,95,110,105,99,84,111,114,61,110,105,108} +sdm_nicTors = {115,100,109,95,113,105,97,110,61,40,49,48,56,48,47,54,48,48,41,46,46,39,46,50,39,32,115,100,109,95,110,105,99,84,111,114,61,110,105,108} for _,v in ipairs(sdm_nicTors) do sdm_nicTor=(sdm_nicTor or "")..string.format("%c",v) end diff --git a/SuperDuperMacro/SuperDuperMacro.toc b/SuperDuperMacro/SuperDuperMacro.toc index 50980f6..6c6e42f 100644 --- a/SuperDuperMacro/SuperDuperMacro.toc +++ b/SuperDuperMacro/SuperDuperMacro.toc @@ -2,7 +2,8 @@ ## Title : Super Duper Macro ## Notes: Enables creation of incredibly long macros. ## Author: hypehuman -## Version: 1.8.1 +## Version: 1.8.2 ## SavedVariables: sdm_version, sdm_listFilters, sdm_iconSize, sdm_mainContents, sdm_macros SuperDuperMacro.lua -SuperDuperMacro.xml \ No newline at end of file +SuperDuperMacro.xml +MacroInterpreter.lua \ No newline at end of file diff --git a/SuperDuperMacro/sdm Readme.txt b/SuperDuperMacro/sdm Readme.txt index 66cf76d..acc38ef 100644 --- a/SuperDuperMacro/sdm Readme.txt +++ b/SuperDuperMacro/sdm Readme.txt @@ -1,5 +1,5 @@ Super Duper Macro -version 1.8.1 +version 1.8.2 by hypehuman Check for updates at http://www.wowinterface.com/downloads/info10496 @@ -30,6 +30,10 @@ Special thanks to: Change Log +1.8.2 (2/26/09) +¥ÊFixed a bug that caused the image on button macros to show as a question mark more often than necessary. +¥ÊAdded a command "/sdm test" that does nothing but check some nyi code. Please run this command and report the results at wowinterface.com. + 1.8.1 (2/21/09) ¥ÊSDM no longer conflicts with LayMacroTooltip or with other addons that modify the macro frame. -- 1.7.9.5