WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Would like to be able to scan all set attributes for a SecureActionButton (https://www.wowinterface.com/forums/showthread.php?t=57117)

Nightness 04-24-19 10:20 PM

Would like to be able to scan all set attributes for a SecureActionButton
 
I'm trying to make a (pseudo) GetAllSetAttributes function for use on SecureActionButtonTemplate. I'm looking to generate a table of all potential attributes that could be set using the attribute naming scheme for SecureActionButtonTemplate.
So here is an excerpt from a wiki on SecureActionButtonTemplate, as an example.

"type" Any clicks.
"*type1" Any left click.
"type1" Unmodified left click.
"shift-type2" Shift+right click. (But not Alt+Shift+right click)
"shift-type*" Shift+any button click.
"alt-ctrl-shift-type*" Alt+Control+Shift+any button click.

Rules
  • General order {modifiers-attribute-suffix}
  • Order of 'alt-ctrl-shift' is strict for modifiers. Also, for at least the 'spell' attribute, the format "modifiers-attribute-{nuke | heal}", is valid.
  • The 'attribute' part is required, other parts are not.
  • Asterisks can only be at the end (any button), beginning (any prior modifiers), or omitted. Note: I believe ctrl and shift can be straight up omitted, so "alt-attribute" should be valid. Not sure if "alt-*-attribute" is legal (matching both alt-shift and alt-ctrl).

Primary Attributes
Code:

local primaryAttributes = {
        "type", "spell", "item", "action", "macro", "macrotext",
        "checkselfcast", "checkfocuscast", "toy", "flyoutDirection",
        "clickbutton", "unit", "marker", "harmbutton", "helpbutton",
        "attribute-name", "attribute-value", "actionpage",
        "downbutton", "unit-suffix", "toggleForVehicle", "allowVehicleTarget"
}

String parsing isn't my strong suit (I can do it), but if anyone has any ideas or suggestions, or wants a little fun challenge; the help would be appreciated. This is for my addon MagnetButtons, trying to add insertion of custom (not yet supported in the addon) attributes. I will give credit to anyone with viable code to use.

Reference: Format details

Nightness 04-26-19 08:36 PM

I need to learn regex
 
Code:

local primaryAttributes = {
        "type", "spell", "item", "action", "macro", "macrotext", "checkselfcast", "checkfocuscast",
        "toy", "flyoutDirection", "clickbutton", "unit", "marker", "harmbutton", "helpbutton", "attribute-name",
        "attribute-value", "actionpage", "downbutton", "unit-suffix", "toggleForVehicle", "allowVehicleTarget"
}

local function potentialProperties(startingTable, attr, prefix, suffix)
        if (type(attr) ~= "string") then return startingTable end
        if (prefix) then prefix = "*" else prefix = "" end
        if (suffix) then suffix = "*" else suffix = "" end
        table.insert(startingTable, prefix..attr..suffix)
        table.insert(startingTable, prefix.."alt-"..attr..suffix);
        table.insert(startingTable, prefix.."alt-ctrl-"..attr..suffix);
        table.insert(startingTable, prefix.."alt-shift-"..attr..suffix);
        if (prefix ~= "*") then
                table.insert(startingTable, prefix.."alt-ctrl-shift-"..attr..suffix);
        end
        table.insert(startingTable, prefix.."ctrl-"..attr..suffix);
        table.insert(startingTable, prefix.."ctrl-shift-"..attr..suffix);
        table.insert(startingTable, prefix.."shift-"..attr..suffix);
        return startingTable;
end

local function generateAllPossibleAttributes()
        local results = { };
        for attribIndex,attrib in ipairs(primaryAttributes) do
                results = potentialProperties(results, attrib, false, false)
                results = potentialProperties(results, attrib, false, true)
                results = potentialProperties(results, attrib, true, false)
                results = potentialProperties(results, attrib, true, true)
                for idx = 1, 5 do
                        results = potentialProperties(results, attrib..tostring(idx), false, false)
                        results = potentialProperties(results, attrib..tostring(idx), true, false)
                end
        end
        return results;
end



All times are GMT -6. The time now is 03:12 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI