Code format

This commit is contained in:
2025-05-06 22:00:50 +02:00
parent 4c3913ca3f
commit f1b1a384d4
7 changed files with 440 additions and 474 deletions

View File

@@ -1 +1,5 @@
C:/Users/Administrator/Seafile/Games-WoW/Ruski/Interface/AddOns/ActionBarSaverReloaded/Meta/.luacheckrc globals = { "CykaPersistentData", "CreateFrame", "GetItemInfo" }
unused_args = false
max_line_length = 150
exclude_files = { "Meta/" }
global = false

View File

@@ -1 +1,11 @@
C:/Users/Administrator/Seafile/Games-WoW/Ruski/Interface/AddOns/ActionBarSaverReloaded/Meta/.luarc.json {
"workspace": {
"library": [
"./Meta"
]
},
"diagnostics.disable": [
"unused-local",
"unused-vararg"
]
}

View File

@@ -1,268 +1,276 @@
local ADDON_LOADED, shared = ... local ADDON_LOADED, shared = ...
local typeMap = { local typeMap = {
spell = "S", spell = "S",
item = "I", item = "I",
macro = "M", macro = "M",
companion = "C", companion = "C",
equipmentset = "E", equipmentset = "E",
summonmount = "U" summonmount = "U",
} }
local inverseTypeMap = { local inverseTypeMap = {
S = "spell", S = "spell",
I = "item", I = "item",
M = "macro", M = "macro",
C = "companion", C = "companion",
E = "equipmentset", E = "equipmentset",
U = "summonmount" U = "summonmount",
} }
local function PickupEquipmentSet(setName) local function PickupEquipmentSet(setName)
local setIndex = 0 local setIndex = 0
for i = 1, C_EquipmentSet.GetNumEquipmentSets() do for i = 1, C_EquipmentSet.GetNumEquipmentSets() do
local sn = C_EquipmentSet.GetEquipmentSetInfo(i) local sn = C_EquipmentSet.GetEquipmentSetInfo(i)
if sn == setName then if sn == setName then setIndex = i end
setIndex = i end
end
end
C_EquipmentSet.PickupEquipmentSet(setIndex) C_EquipmentSet.PickupEquipmentSet(setIndex)
end end
local pickupActionButton = { local pickupActionButton = {
item = PickupItem, item = PickupItem,
spell = PickupSpell, spell = PickupSpell,
macro = PickupMacro, macro = PickupMacro,
companion = PickupSpell, companion = PickupSpell,
equipmentset = PickupEquipmentSet, equipmentset = PickupEquipmentSet,
summonmount = C_MountJournal.Pickup summonmount = C_MountJournal.Pickup,
} }
local function RestoreActionButton(self, index, actionButton) local function RestoreActionButton(self, index, actionButton)
if GetActionInfo(index) then if GetActionInfo(index) then
PickupAction(index) PickupAction(index)
ClearCursor() ClearCursor()
end end
if not actionButton then if not actionButton then return true, nil end
return true, nil
end
local aliases = ActionBarSaverReloaded.spellAliases[actionButton.id] or {} local aliases = ActionBarSaverReloaded.spellAliases[actionButton.id] or {}
table.insert(aliases, actionButton.id) table.insert(aliases, actionButton.id)
for _, id in ipairs(aliases) do for _, id in ipairs(aliases) do
pickupActionButton[actionButton.type](id) pickupActionButton[actionButton.type](id)
if GetCursorInfo() == actionButton.type then if GetCursorInfo() == actionButton.type then
PlaceAction(index) PlaceAction(index)
return true, id return true, id
end end
ClearCursor() ClearCursor()
end end
return false return false
end end
local function IsMacro(actionButton) local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end
return actionButton and actionButton.type == "macro"
end
local function GetMacroDuplicates() local function GetMacroDuplicates()
local t = {} local t = {}
local duplicates = {} local duplicates = {}
for i = 1, MAX_MACROS do for i = 1, MAX_MACROS do
local macroName = GetMacroInfo(i) local macroName = GetMacroInfo(i)
if macroName then if macroName then
if not t[macroName] then if not t[macroName] then
t[macroName] = 1 t[macroName] = 1
else else
t[macroName] = t[macroName] + 1 t[macroName] = t[macroName] + 1
duplicates[macroName] = t[macroName] duplicates[macroName] = t[macroName]
end end
end end
end end
return duplicates return duplicates
end end
local function AddWarning(warnings, macroName, usages) local function AddWarning(warnings, macroName, usages)
table.insert(warnings, string.format("Warning: Found %d macros named '%s'. Consider renaming them to avoid issues", table.insert(
usages, macroName)) warnings,
string.format("Warning: Found %d macros named '%s'. Consider renaming them to avoid issues", usages, macroName)
)
end end
function SaveSet(setName) function SaveSet(setName)
if not setName or setName == "" then if not setName or setName == "" then
print("Set name cannot be empty") print("Set name cannot be empty")
return return
end end
local duplicates = GetMacroDuplicates() local duplicates = GetMacroDuplicates()
local set = {} local set = {}
local warnings = {} local warnings = {}
for i = 1, MAX_ACTION_BUTTONS do for i = 1, MAX_ACTION_BUTTONS do
local type, id = GetActionInfo(i) local type, id = GetActionInfo(i)
if type == "macro" then if type == "macro" then
-- use macro name as the ID -- use macro name as the ID
id = GetMacroInfo(id) id = GetMacroInfo(id)
if duplicates[id] then if duplicates[id] then AddWarning(warnings, id, duplicates[id]) end
AddWarning(warnings, id, duplicates[id]) end
end
end
if type and id then if type and id then set[i] = type and {
set[i] = type and { type = type,
type = type, id = id,
id = id } end
} end
end
end
ActionBarSaverReloaded.sets[setName] = set ActionBarSaverReloaded.sets[setName] = set
print(string.format("Saved set '%s'!", setName)) print(string.format("Saved set '%s'!", setName))
for _, warning in ipairs(warnings) do for _, warning in ipairs(warnings) do
print(warning) print(warning)
end end
end end
function RestoreSet(setName) function RestoreSet(setName)
if not setName or setName == "" then if not setName or setName == "" then
print("Set name cannot be empty") print("Set name cannot be empty")
return return
end end
local set = ActionBarSaverReloaded.sets[setName] local set = ActionBarSaverReloaded.sets[setName]
if not set then if not set then
print(string.format("No set with the name '%s' exists", setName)) print(string.format("No set with the name '%s' exists", setName))
return return
end end
if InCombatLockdown() then if InCombatLockdown() then
print("Cannot restore sets while in combat") print("Cannot restore sets while in combat")
return return
end end
local duplicates = GetMacroDuplicates() local duplicates = GetMacroDuplicates()
local messages = {} local messages = {}
-- Start with an empty cursor -- Start with an empty cursor
ClearCursor() ClearCursor()
for i = 1, MAX_ACTION_BUTTONS do for i = 1, MAX_ACTION_BUTTONS do
local actionButton = set[i] local actionButton = set[i]
if IsMacro(actionButton) and duplicates[actionButton.id] then if IsMacro(actionButton) and duplicates[actionButton.id] then
AddWarning(messages, actionButton.id, duplicates[actionButton.id]) AddWarning(messages, actionButton.id, duplicates[actionButton.id])
end end
local succeeded, restoredID = RestoreActionButton(self, i, actionButton) local succeeded, restoredID = RestoreActionButton(self, i, actionButton)
if not succeeded then if not succeeded then
table.insert(messages, string.format("Error: Unable to restore %s with id [%s] to slot %d", table.insert(
actionButton.type, actionButton.id or "", i)) messages,
elseif actionButton and restoredID ~= actionButton.id then string.format(
table.insert(messages, "Error: Unable to restore %s with id [%s] to slot %d",
string.format("Info: Restored spell %d (%s) in place of spell %d", restoredID, GetSpellInfo(restoredID), actionButton.type,
actionButton.id)) actionButton.id or "",
end i
end )
)
elseif actionButton and restoredID ~= actionButton.id then
table.insert(
messages,
string.format(
"Info: Restored spell %d (%s) in place of spell %d",
restoredID,
GetSpellInfo(restoredID),
actionButton.id
)
)
end
end
print(string.format("Restored set '%s'", setName)) print(string.format("Restored set '%s'", setName))
for _, warning in ipairs(messages) do for _, warning in ipairs(messages) do
print(warning) print(warning)
end end
end end
function DeleteSet(setName) function DeleteSet(setName)
if not setName or setName == "" then if not setName or setName == "" then
print("Set name cannot be empty") print("Set name cannot be empty")
return return
end end
if not ActionBarSaverReloaded.sets[setName] then if not ActionBarSaverReloaded.sets[setName] then
print(string.format("No set with the name '%s' exists", setName)) print(string.format("No set with the name '%s' exists", setName))
return return
end end
ActionBarSaverReloaded.sets[setName] = nil ActionBarSaverReloaded.sets[setName] = nil
print(string.format("Deleted set '%s'", setName)) print(string.format("Deleted set '%s'", setName))
end end
function ListSets() function ListSets()
local sets = {} local sets = {}
for setName, foo in pairs(ActionBarSaverReloaded.sets) do for setName, foo in pairs(ActionBarSaverReloaded.sets) do
sets[#sets + 1] = setName sets[#sets + 1] = setName
end end
table.sort(sets) table.sort(sets)
local setsStr = table.concat(sets, ", ") local setsStr = table.concat(sets, ", ")
print(not (not setsStr or setsStr == "") and setsStr or "No sets found") print(not (not setsStr or setsStr == "") and setsStr or "No sets found")
end end
function AliasSpell(args) function AliasSpell(args)
if not args or args == "" then if not args or args == "" then
print("Must provide args in the format 'spellID aliasID'") print("Must provide args in the format 'spellID aliasID'")
return return
end end
local spellID, aliasID = string.match(args, "(%d+)%s+(%d+)") local spellID, aliasID = string.match(args, "(%d+)%s+(%d+)")
spellID = tonumber(spellID) spellID = tonumber(spellID)
aliasID = tonumber(aliasID) aliasID = tonumber(aliasID)
if not (spellID and aliasID) then if not (spellID and aliasID) then
print(string.format("Could not parse spellID and aliasID from '%s'", args)) print(string.format("Could not parse spellID and aliasID from '%s'", args))
return return
end end
local aliases = ActionBarSaverReloaded.spellAliases[spellID] or {} local aliases = ActionBarSaverReloaded.spellAliases[spellID] or {}
for _, id in ipairs(aliases) do for _, id in ipairs(aliases) do
if id == aliasID then if id == aliasID then
print(string.format("Spell %d is already aliased by %d", spellID, aliasID)) print(string.format("Spell %d is already aliased by %d", spellID, aliasID))
return return
end end
end end
table.insert(ActionBarSaverReloaded.spellAliases[spellID], aliasID) table.insert(ActionBarSaverReloaded.spellAliases[spellID], aliasID)
print(string.format("Added %d as an alias for %d", aliasID, spellID)) print(string.format("Added %d as an alias for %d", aliasID, spellID))
end end
function DeleteSpellAliases(spellID) function DeleteSpellAliases(spellID)
if not spellID or spellID == "" then if not spellID or spellID == "" then
print("Must provide a valid spellID") print("Must provide a valid spellID")
return return
end end
spellID = tonumber(spellID) spellID = tonumber(spellID)
if not ActionBarSaverReloaded.spellAliases[spellID] then if not ActionBarSaverReloaded.spellAliases[spellID] then
print(string.format("No aliases to remove for spell with ID %d", spellID)) print(string.format("No aliases to remove for spell with ID %d", spellID))
return return
end end
ActionBarSaverReloaded.spellAliases[spellID] = nil ActionBarSaverReloaded.spellAliases[spellID] = nil
print(string.format("Removed all aliases for spell with ID %d", spellID)) print(string.format("Removed all aliases for spell with ID %d", spellID))
end end
function ListAliases() function ListAliases()
local aliases = ActionBarSaverReloaded.spellAliases local aliases = ActionBarSaverReloaded.spellAliases
if Dict.isEmpty(aliases) then if Dict.isEmpty(aliases) then
print("No aliases found") print("No aliases found")
return return
end end
Dict.iter(ActionBarSaverReloaded.spellAliases, function(spellID, aliases) Dict.iter(
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(aliases, ", "))) ActionBarSaverReloaded.spellAliases,
end) function(spellID, aliases)
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(aliases, ", ")))
end
)
end end
---@param text string ---@param text string
@@ -270,30 +278,26 @@ end
---@param deliminer string ---@param deliminer string
---@return string[] ---@return string[]
local function Partition(text, size, deliminer) local function Partition(text, size, deliminer)
local words = {} local words = {}
for word in text:gmatch("[^" .. deliminer .. "]+") do for word in text:gmatch("[^" .. deliminer .. "]+") do
words[#words + 1] = word words[#words + 1] = word
end end
local ret = {} local ret = {}
local currentChunk = "" local currentChunk = ""
for _, word in ipairs(words) do for _, word in ipairs(words) do
if #currentChunk + #word + 1 <= size then if #currentChunk + #word + 1 <= size then
currentChunk = currentChunk .. deliminer .. word currentChunk = currentChunk .. deliminer .. word
else else
if #currentChunk > 0 then if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
ret[#ret + 1] = currentChunk currentChunk = word
end end
currentChunk = word end
end
end
if #currentChunk > 0 then if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
ret[#ret + 1] = currentChunk
end
return ret return ret
end end
local importingSet = nil local importingSet = nil
@@ -305,17 +309,17 @@ importExportFrame:EnableMouse(true)
importExportFrame:SetMovable(true) importExportFrame:SetMovable(true)
importExportFrame:SetResizable(false) importExportFrame:SetResizable(false)
importExportFrame:SetBackdrop({ importExportFrame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background", bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tile = true,
tileSize = 4, tileSize = 4,
edgeSize = 4, edgeSize = 4,
insets = { insets = {
left = 4, left = 4,
right = 4, right = 4,
top = 4, top = 4,
bottom = 4 bottom = 4,
} },
}) })
importExportFrame:SetBackdropColor(0, 0, 0, 0.8) importExportFrame:SetBackdropColor(0, 0, 0, 0.8)
importExportFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1) importExportFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
@@ -323,15 +327,9 @@ importExportFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
importExportFrame:SetMovable(true) importExportFrame:SetMovable(true)
importExportFrame:EnableMouse(true) importExportFrame:EnableMouse(true)
importExportFrame:RegisterForDrag("LeftButton") importExportFrame:RegisterForDrag("LeftButton")
importExportFrame:SetScript("OnDragStart", function(self) importExportFrame:SetScript("OnDragStart", function(self) self:StartMoving() end)
self:StartMoving() importExportFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
end) importExportFrame:SetScript("OnShow", function(self) self:SetScale(1) end)
importExportFrame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)
importExportFrame:SetScript("OnShow", function(self)
self:SetScale(1)
end)
importExportFrame:Hide() importExportFrame:Hide()
local importExportFrameTextBox = CreateFrame("EditBox", "ABSImportExportFrameTextBox", importExportFrame) local importExportFrameTextBox = CreateFrame("EditBox", "ABSImportExportFrameTextBox", importExportFrame)
@@ -344,207 +342,179 @@ importExportFrameTextBox:SetMultiLine(true)
importExportFrameTextBox:SetAutoFocus(true) importExportFrameTextBox:SetAutoFocus(true)
importExportFrameTextBox:SetMaxLetters(1000000) importExportFrameTextBox:SetMaxLetters(1000000)
importExportFrameTextBox:SetScript("OnEscapePressed", function(self) importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
importExportFrame:Hide() importExportFrame:Hide()
if importingSet then if importingSet then
local lines = {strsplit("\n", self:GetText())} local lines = { strsplit("\n", self:GetText()) }
for _, line in ipairs(lines) do for _, line in ipairs(lines) do
line = strtrim(line) line = strtrim(line)
if line ~= "" then if line ~= "" then ImportSet(importingSet, line) end
ImportSet(importingSet, line) end
end importingSet = nil
end end
importingSet = nil
end
end) end)
function ExportSet(setName) function ExportSet(setName)
local set = ActionBarSaverReloaded.sets[setName] local set = ActionBarSaverReloaded.sets[setName]
if not set then if not set then
print(string.format("No set with the name '%s' exists", setName)) print(string.format("No set with the name '%s' exists", setName))
return return
end end
local macros = {} local macros = {}
local stringified = {} local stringified = {}
for slot, action in pairs(set) do for slot, action in pairs(set) do
local typeChar = typeMap[action.type] local typeChar = typeMap[action.type]
if not typeChar then if not typeChar then
print(string.format("Unknown action type '%s' in set '%s'", action.type, setName)) print(string.format("Unknown action type '%s' in set '%s'", action.type, setName))
return return
end end
stringified[#stringified + 1] = string.format("%s\\%s\\%s", tostring(slot), tostring(action.id), stringified[#stringified + 1] =
tostring(typeChar)) string.format("%s\\%s\\%s", tostring(slot), tostring(action.id), tostring(typeChar))
if typeChar == "M" then if typeChar == "M" then
local _, _, macro = GetMacroInfo(action.id) local _, _, macro = GetMacroInfo(action.id)
if macro then if macro then macros[action.id] = macro end
macros[action.id] = macro end
end end
end
end
local export = {} local export = {}
for name, macro in pairs(macros) do for name, macro in pairs(macros) do
local content = B64.Encode(macro) local content = B64.Encode(macro)
export[#export + 1] = string.format("Mž%sž%s", name, content) export[#export + 1] = string.format("Mž%sž%s", name, content)
end end
export[#export + 1] = table.concat(stringified, "ž") export[#export + 1] = table.concat(stringified, "ž")
local str = table.concat(export, "\n") local str = table.concat(export, "\n")
importExportFrame:Show() importExportFrame:Show()
importExportFrameTextBox:SetText(str) importExportFrameTextBox:SetText(str)
importExportFrameTextBox:SetFocus() importExportFrameTextBox:SetFocus()
end end
function ParseAction(action) function ParseAction(action)
if not action or action == "" then if not action or action == "" then return nil end
return nil action = strtrim(action)
end local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)")
action = strtrim(action) if not typeChar then
local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)") print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName)))
if not typeChar then return
print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName))) end
return local type = inverseTypeMap[typeChar]
end if not type then
local type = inverseTypeMap[typeChar] print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName)))
if not type then return
print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName))) end
return
end
slot = tonumber(slot) slot = tonumber(slot)
if not slot then if not slot then
print(string.format("Unknown slot '%s' in set '%s'", tostring(slot), tostring(setName))) print(string.format("Unknown slot '%s' in set '%s'", tostring(slot), tostring(setName)))
return return
end end
if not id then if not id then
print(string.format("Unknown id '%s' in set '%s'", tostring(id), tostring(setName))) print(string.format("Unknown id '%s' in set '%s'", tostring(id), tostring(setName)))
return return
end end
return { return {
slot = slot, slot = slot,
id = id, id = id,
type = type type = type,
} }
end end
function ImportMacro(importString) function ImportMacro(importString)
if not importString or importString == "" then if not importString or importString == "" then
print("Must provide a valid macro string") print("Must provide a valid macro string")
return return
end end
importString = strtrim(importString) importString = strtrim(importString)
local name, content = string.match(importString, "^Mž([^ž]+)ž([^ž]+)") local name, content = string.match(importString, "^Mž([^ž]+)ž([^ž]+)")
if not name or not content then if not name or not content then
print("Error: Invalid macro part format") print("Error: Invalid macro part format")
return return
end end
content = strtrim(content) content = strtrim(content)
name = strtrim(name) name = strtrim(name)
local reconstructed = B64.Decode(content) local reconstructed = B64.Decode(content)
local macroIdx = GetMacroIndexByName(name) local macroIdx = GetMacroIndexByName(name)
if macroIdx == 0 then if macroIdx == 0 then
macroIdx = CreateMacro(name, "Inv_misc_questionmark", "") macroIdx = CreateMacro(name, "Inv_misc_questionmark", "")
macroIdx = GetMacroIndexByName(name) macroIdx = GetMacroIndexByName(name)
end end
EditMacro(macroIdx, name, nil, reconstructed) EditMacro(macroIdx, name, nil, reconstructed)
print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed)) print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed))
return return
end end
function ImportSet(setName, str) function ImportSet(setName, str)
if not setName or setName == "" then if not setName or setName == "" then
print("Must provide a valid set name") print("Must provide a valid set name")
return return
end end
if string.find(str, "^Mž") then if string.find(str, "^Mž") then
ImportMacro(str) ImportMacro(str)
return return
end end
local set = ActionBarSaverReloaded.sets[setName] or {} local set = ActionBarSaverReloaded.sets[setName] or {}
-- if set then -- if set then
-- print(string.format("Set '%s' already exists", setName)) -- print(string.format("Set '%s' already exists", setName))
-- return -- return
-- end -- end
str = strtrim(str) str = strtrim(str)
local data = {strsplit("ž", str)} local data = { strsplit("ž", str) }
for _, action in ipairs(data) do for _, action in ipairs(data) do
local paction = ParseAction(action) local paction = ParseAction(action)
if paction then if paction then set[paction.slot] = {
set[paction.slot] = { type = paction.type,
type = paction.type, id = paction.id,
id = paction.id } end
} end
end
end
-- /dump ActionBarSaverReloaded.sets["havoc"] -- /dump ActionBarSaverReloaded.sets["havoc"]
-- /dump ActionBarSaverReloaded.sets["havoc2"] -- /dump ActionBarSaverReloaded.sets["havoc2"]
ActionBarSaverReloaded.sets[setName] = set ActionBarSaverReloaded.sets[setName] = set
print(string.format("Imported set '%s'", setName)) print(string.format("Imported set '%s'", setName))
end end
function ImportSetDialogue(setName) function ImportSetDialogue(setName)
if not setName or setName == "" then if not setName or setName == "" then
print("Must provide a valid set name") print("Must provide a valid set name")
return return
end end
importingSet = setName importingSet = setName
importExportFrameTextBox:SetText("") importExportFrameTextBox:SetText("")
importExportFrame:Show() importExportFrame:Show()
importExportFrameTextBox:SetFocus() importExportFrameTextBox:SetFocus()
end end
function PrintUsage() function PrintUsage()
print("ABS Slash commands") print("ABS Slash commands")
print("/abs save <set> - Saves your current action bar setup under the given <set>") print("/abs save <set> - Saves your current action bar setup under the given <set>")
print("/abs restore <set> - Restores the saved <set>") print("/abs restore <set> - Restores the saved <set>")
print("/abs delete <set> - Deletes the saved <set>") print("/abs delete <set> - Deletes the saved <set>")
print("/abs list - Lists all saved sets") print("/abs list - Lists all saved sets")
print("/abs alias <spellID> <aliasID> - Adds an alias with <aliasID> to <spellID>") print("/abs alias <spellID> <aliasID> - Adds an alias with <aliasID> to <spellID>")
print("/abs unalias <spellID> - Removes all aliases associated with <spellID>") print("/abs unalias <spellID> - Removes all aliases associated with <spellID>")
print("/abs aliases - List all spell aliases") print("/abs aliases - List all spell aliases")
print("/abs export <set> - Brings up a dialog to export the given <set>") print("/abs export <set> - Brings up a dialog to export the given <set>")
print("/abs import <set> - Brings up a dialog to import the given <set>") print("/abs import <set> - Brings up a dialog to import the given <set>")
end end
SlashCmdList["ABS"] = function(argv) SlashCmdList["ABS"] = function(argv)
local args = {strsplit(" ", argv)} local args = { strsplit(" ", argv) }
local cmd = args[1] local cmd = args[1]
if cmd == "save" then if cmd == "save" then SaveSet(args[2]) end
SaveSet(args[2]) if cmd == "restore" then RestoreSet(args[2]) end
end if cmd == "delete" then DeleteSet(args[2]) end
if cmd == "restore" then if cmd == "list" then ListSets() end
RestoreSet(args[2]) if cmd == "alias" then AliasSpell(args[2], args[3]) end
end if cmd == "unalias" then DeleteSpellAliases(args[2]) end
if cmd == "delete" then if cmd == "aliases" then ListAliases() end
DeleteSet(args[2]) if cmd == "export" then ExportSet(args[2]) end
end if cmd == "import" then ImportSetDialogue(args[2]) end
if cmd == "list" then
ListSets()
end
if cmd == "alias" then
AliasSpell(args[2], args[3])
end
if cmd == "unalias" then
DeleteSpellAliases(args[2])
end
if cmd == "aliases" then
ListAliases()
end
if cmd == "export" then
ExportSet(args[2])
end
if cmd == "import" then
ImportSetDialogue(args[2])
end
if cmd == "" or not cmd then if cmd == "" or not cmd then PrintUsage() end
PrintUsage()
end
end end
SLASH_ABS1 = "/abs" SLASH_ABS1 = "/abs"

66
B64.lua
View File

@@ -1,46 +1,42 @@
if not B64 then if not B64 then B64 = {} end
B64 = {}
end
local encode, decode = {}, { local encode, decode = {}, {
[strbyte("=")] = false [strbyte("=")] = false,
} }
for value = 0, 63 do for value = 0, 63 do
local char = strsub('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', value + 1, value + 1) local char = strsub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", value + 1, value + 1)
encode[value] = char encode[value] = char
decode[strbyte(char)] = value decode[strbyte(char)] = value
end end
local t = {} local t = {}
function B64.Encode(str) function B64.Encode(str)
local j = 1 local j = 1
for i = 1, strlen(str), 3 do for i = 1, strlen(str), 3 do
local a, b, c = strbyte(str, i, i + 2) local a, b, c = strbyte(str, i, i + 2)
t[j] = encode[bit.rshift(a, 2)] t[j] = encode[bit.rshift(a, 2)]
t[j + 1] = encode[bit.band(bit.lshift(a, 4) + bit.rshift(b or 0, 4), 0x3F)] t[j + 1] = encode[bit.band(bit.lshift(a, 4) + bit.rshift(b or 0, 4), 0x3F)]
t[j + 2] = b and encode[bit.band(bit.lshift(b, 2) + bit.rshift(c or 0, 6), 0x3F)] or "=" t[j + 2] = b and encode[bit.band(bit.lshift(b, 2) + bit.rshift(c or 0, 6), 0x3F)] or "="
t[j + 3] = c and encode[bit.band(c, 0x3F)] or "=" t[j + 3] = c and encode[bit.band(c, 0x3F)] or "="
j = j + 4 j = j + 4
end end
return table.concat(t, "", 1, j - 1) return table.concat(t, "", 1, j - 1)
end end
function B64.Decode(str) function B64.Decode(str)
local j = 1 local j = 1
if strlen(str) % 4 ~= 0 then if strlen(str) % 4 ~= 0 then str = str .. string.rep("=", 4 - strlen(str) % 4) end
str = str .. string.rep("=", 4 - strlen(str) % 4) assert(strlen(str) % 4 == 0, format("invalid data length: %d", strlen(str)))
end for i = 1, strlen(str), 4 do
assert(strlen(str) % 4 == 0, format("invalid data length: %d", strlen(str))) local ba, bb, bc, bd = strbyte(str, i, i + 3)
for i = 1, strlen(str), 4 do local a, b, c, d = decode[ba], decode[bb], decode[bc], decode[bd]
local ba, bb, bc, bd = strbyte(str, i, i + 3) assert(a ~= nil, format("invalid data at position %d: '%s'", i, ba))
local a, b, c, d = decode[ba], decode[bb], decode[bc], decode[bd] assert(b ~= nil, format("invalid data at position %d: '%s'", i + 1, bb))
assert(a ~= nil, format("invalid data at position %d: '%s'", i, ba)) assert(c ~= nil, format("invalid data at position %d: '%s'", i + 2, bc))
assert(b ~= nil, format("invalid data at position %d: '%s'", i + 1, bb)) assert(d ~= nil, format("invalid data at position %d: '%s'", i + 3, bd))
assert(c ~= nil, format("invalid data at position %d: '%s'", i + 2, bc)) t[j] = strchar(bit.lshift(a, 2) + bit.rshift(b, 4))
assert(d ~= nil, format("invalid data at position %d: '%s'", i + 3, bd)) t[j + 1] = c and strchar(bit.band(bit.lshift(b, 4) + bit.rshift(c, 2), 0xFF)) or ""
t[j] = strchar(bit.lshift(a, 2) + bit.rshift(b, 4)) t[j + 2] = d and strchar(bit.band(bit.lshift(c, 6) + d, 0xFF)) or ""
t[j + 1] = c and strchar(bit.band(bit.lshift(b, 4) + bit.rshift(c, 2), 0xFF)) or "" j = j + 3
t[j + 2] = d and strchar(bit.band(bit.lshift(c, 6) + d, 0xFF)) or "" end
j = j + 3 return table.concat(t, "", 1, j - 1)
end
return table.concat(t, "", 1, j - 1)
end end

View File

@@ -4,9 +4,7 @@ local ADDON_NAME, shared = ...
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED") frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, addon) frame:SetScript("OnEvent", function(self, event, addon)
if addon ~= ADDON_NAME then if addon ~= ADDON_NAME then return end
return
end
KeybindSaverReloaded = KeybindSaverReloaded or {} KeybindSaverReloaded = KeybindSaverReloaded or {}
KeybindSaverReloaded.sets = KeybindSaverReloaded.sets or {} KeybindSaverReloaded.sets = KeybindSaverReloaded.sets or {}
@@ -39,15 +37,9 @@ importExportFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
importExportFrame:SetMovable(true) importExportFrame:SetMovable(true)
importExportFrame:EnableMouse(true) importExportFrame:EnableMouse(true)
importExportFrame:RegisterForDrag("LeftButton") importExportFrame:RegisterForDrag("LeftButton")
importExportFrame:SetScript("OnDragStart", function(self) importExportFrame:SetScript("OnDragStart", function(self) self:StartMoving() end)
self:StartMoving() importExportFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
end) importExportFrame:SetScript("OnShow", function(self) self:SetScale(1) end)
importExportFrame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)
importExportFrame:SetScript("OnShow", function(self)
self:SetScale(1)
end)
importExportFrame:Hide() importExportFrame:Hide()
local importingSet = nil local importingSet = nil
@@ -64,14 +56,11 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
importExportFrame:Hide() importExportFrame:Hide()
if importingSet then if importingSet then
local text = self:GetText() local text = self:GetText()
if text and text ~= "" then if text and text ~= "" then ImportSet(importingSet, text) end
ImportSet(importingSet, text)
end
importingSet = nil importingSet = nil
end end
end) end)
local function SaveSet(setName) local function SaveSet(setName)
if not setName or setName == "" then if not setName or setName == "" then
print("Set name cannot be empty") print("Set name cannot be empty")
@@ -83,12 +72,10 @@ local function SaveSet(setName)
for i = 1, numBindings do for i = 1, numBindings do
local command, category, key1, key2 = GetBinding(i) local command, category, key1, key2 = GetBinding(i)
if key1 or key2 then if key1 or key2 then set[command] = {
set[command] = { key1 = key1,
key1 = key1, key2 = key2,
key2 = key2, } end
}
end
end end
KeybindSaverReloaded.sets[setName] = set KeybindSaverReloaded.sets[setName] = set
@@ -112,12 +99,8 @@ local function RestoreSet(setName)
-- Restore saved bindings -- Restore saved bindings
for command, keys in pairs(set) do for command, keys in pairs(set) do
if keys.key1 then if keys.key1 then SetBinding(keys.key1, command) end
SetBinding(keys.key1, command) if keys.key2 then SetBinding(keys.key2, command) end
end
if keys.key2 then
SetBinding(keys.key2, command)
end
end end
-- Save the changes -- Save the changes
@@ -164,12 +147,8 @@ local function ExportSet(setName)
local export = {} local export = {}
for command, keys in pairs(set) do for command, keys in pairs(set) do
if keys.key1 then if keys.key1 then table.insert(export, string.format("%s:%s", command, keys.key1)) end
table.insert(export, string.format("%s:%s", command, keys.key1)) if keys.key2 then table.insert(export, string.format("%s:%s", command, keys.key2)) end
end
if keys.key2 then
table.insert(export, string.format("%s:%s", command, keys.key2))
end
end end
local exportStr = table.concat(export, "\n") local exportStr = table.concat(export, "\n")
@@ -190,9 +169,7 @@ local function ImportSet(setName, importStr)
for _, line in ipairs(lines) do for _, line in ipairs(lines) do
local command, key = strsplit(":", line) local command, key = strsplit(":", line)
if command and key then if command and key then
if not set[command] then if not set[command] then set[command] = {} end
set[command] = {}
end
if not set[command].key1 then if not set[command].key1 then
set[command].key1 = key set[command].key1 = key
else else

View File

@@ -3,13 +3,11 @@ local ADDON_NAME, shared = ...
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED") frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, addon) frame:SetScript("OnEvent", function(self, event, addon)
if addon ~= ADDON_NAME then if addon ~= ADDON_NAME then return end
return
end
ActionBarSaverReloaded = ActionBarSaverReloaded or {} ActionBarSaverReloaded = ActionBarSaverReloaded or {}
ActionBarSaverReloaded.spellAliases = ActionBarSaverReloaded.spellAliases or {} ActionBarSaverReloaded.spellAliases = ActionBarSaverReloaded.spellAliases or {}
ActionBarSaverReloaded.sets = ActionBarSaverReloaded.sets or {} ActionBarSaverReloaded.sets = ActionBarSaverReloaded.sets or {}
end) end)
-- function ABS:OnInitialize() -- function ABS:OnInitialize()

View File

@@ -1 +1,12 @@
C:/Users/Administrator/Seafile/Games-WoW/Ruski/Interface/AddOns/ActionBarSaverReloaded/Meta/stylua.toml syntax = "All" # Specify a disambiguation for the style of Lua syntax being formatted. Possible options: All (default), Lua51, Lua52, Lua53, Lua54, LuaJIT, Luau, CfxLua
column_width = 120 # Approximate line length for printing. Used as a guide for line wrapping - this is not a hard requirement: lines may fall under or over the limit.
line_endings = "Windows" # Line endings type. Possible options: Unix (LF) or Windows (CRLF)
indent_type = "Tabs" # Indent type. Possible options: Tabs or Spaces
indent_width = 4 # Character size of single indentation. If indent_type is set to Tabs, this option is used as a heuristic to determine column width only.
quote_style = "AutoPreferDouble" # Quote style for string literals. Possible options: AutoPreferDouble, AutoPreferSingle, ForceDouble, ForceSingle. AutoPrefer styles will prefer the specified quote style, but fall back to the alternative if it has fewer string escapes. Force styles always use the specified style regardless of escapes.
call_parentheses = "Always" # Whether parentheses should be applied on function calls with a single string/table argument. Possible options: Always, NoSingleString, NoSingleTable, None, Input. Always applies parentheses in all cases. NoSingleString omits parentheses on calls with a single string argument. Similarly, NoSingleTable omits parentheses on calls with a single table argument. None omits parentheses in both cases. Note: parentheses are still kept in situations where removal can lead to obscurity (e.g. foo "bar".setup -> foo("bar").setup, since the index is on the call result, not the string). Input removes all automation and preserves parentheses only if they were present in input code: consistency is not enforced.
space_after_function_names = "Never" # Specify whether to add a space between the function name and parentheses. Possible options: Never, Definitions, Calls, or Always
collapse_simple_statement = "Always" # Specify whether to collapse simple statements. Possible options: Never, FunctionOnly, ConditionalOnly, or Always
[sort_requires]
enabled = false