Code format
This commit is contained in:
@@ -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
|
||||
12
.luarc.json
12
.luarc.json
@@ -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"
|
||||
]
|
||||
}
|
||||
|
||||
162
Actions.lua
162
Actions.lua
@@ -6,7 +6,7 @@ local typeMap = {
|
||||
macro = "M",
|
||||
companion = "C",
|
||||
equipmentset = "E",
|
||||
summonmount = "U"
|
||||
summonmount = "U",
|
||||
}
|
||||
local inverseTypeMap = {
|
||||
S = "spell",
|
||||
@@ -14,7 +14,7 @@ local inverseTypeMap = {
|
||||
M = "macro",
|
||||
C = "companion",
|
||||
E = "equipmentset",
|
||||
U = "summonmount"
|
||||
U = "summonmount",
|
||||
}
|
||||
|
||||
local function PickupEquipmentSet(setName)
|
||||
@@ -23,9 +23,7 @@ local function PickupEquipmentSet(setName)
|
||||
for i = 1, C_EquipmentSet.GetNumEquipmentSets() do
|
||||
local sn = C_EquipmentSet.GetEquipmentSetInfo(i)
|
||||
|
||||
if sn == setName then
|
||||
setIndex = i
|
||||
end
|
||||
if sn == setName then setIndex = i end
|
||||
end
|
||||
|
||||
C_EquipmentSet.PickupEquipmentSet(setIndex)
|
||||
@@ -37,7 +35,7 @@ local pickupActionButton = {
|
||||
macro = PickupMacro,
|
||||
companion = PickupSpell,
|
||||
equipmentset = PickupEquipmentSet,
|
||||
summonmount = C_MountJournal.Pickup
|
||||
summonmount = C_MountJournal.Pickup,
|
||||
}
|
||||
|
||||
local function RestoreActionButton(self, index, actionButton)
|
||||
@@ -46,9 +44,7 @@ local function RestoreActionButton(self, index, actionButton)
|
||||
ClearCursor()
|
||||
end
|
||||
|
||||
if not actionButton then
|
||||
return true, nil
|
||||
end
|
||||
if not actionButton then return true, nil end
|
||||
|
||||
local aliases = ActionBarSaverReloaded.spellAliases[actionButton.id] or {}
|
||||
table.insert(aliases, actionButton.id)
|
||||
@@ -67,9 +63,7 @@ local function RestoreActionButton(self, index, actionButton)
|
||||
return false
|
||||
end
|
||||
|
||||
local function IsMacro(actionButton)
|
||||
return actionButton and actionButton.type == "macro"
|
||||
end
|
||||
local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end
|
||||
|
||||
local function GetMacroDuplicates()
|
||||
local t = {}
|
||||
@@ -92,8 +86,10 @@ local function GetMacroDuplicates()
|
||||
end
|
||||
|
||||
local function AddWarning(warnings, macroName, usages)
|
||||
table.insert(warnings, string.format("Warning: Found %d macros named '%s'. Consider renaming them to avoid issues",
|
||||
usages, macroName))
|
||||
table.insert(
|
||||
warnings,
|
||||
string.format("Warning: Found %d macros named '%s'. Consider renaming them to avoid issues", usages, macroName)
|
||||
)
|
||||
end
|
||||
|
||||
function SaveSet(setName)
|
||||
@@ -112,17 +108,13 @@ function SaveSet(setName)
|
||||
if type == "macro" then
|
||||
-- use macro name as the ID
|
||||
id = GetMacroInfo(id)
|
||||
if duplicates[id] then
|
||||
AddWarning(warnings, id, duplicates[id])
|
||||
end
|
||||
if duplicates[id] then AddWarning(warnings, id, duplicates[id]) end
|
||||
end
|
||||
|
||||
if type and id then
|
||||
set[i] = type and {
|
||||
if type and id then set[i] = type and {
|
||||
type = type,
|
||||
id = id
|
||||
}
|
||||
end
|
||||
id = id,
|
||||
} end
|
||||
end
|
||||
|
||||
ActionBarSaverReloaded.sets[setName] = set
|
||||
@@ -164,12 +156,25 @@ function RestoreSet(setName)
|
||||
|
||||
local succeeded, restoredID = RestoreActionButton(self, i, actionButton)
|
||||
if not succeeded then
|
||||
table.insert(messages, string.format("Error: Unable to restore %s with id [%s] to slot %d",
|
||||
actionButton.type, actionButton.id or "", i))
|
||||
table.insert(
|
||||
messages,
|
||||
string.format(
|
||||
"Error: Unable to restore %s with id [%s] to slot %d",
|
||||
actionButton.type,
|
||||
actionButton.id or "",
|
||||
i
|
||||
)
|
||||
)
|
||||
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))
|
||||
table.insert(
|
||||
messages,
|
||||
string.format(
|
||||
"Info: Restored spell %d (%s) in place of spell %d",
|
||||
restoredID,
|
||||
GetSpellInfo(restoredID),
|
||||
actionButton.id
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -260,9 +265,12 @@ function ListAliases()
|
||||
return
|
||||
end
|
||||
|
||||
Dict.iter(ActionBarSaverReloaded.spellAliases, function(spellID, aliases)
|
||||
Dict.iter(
|
||||
ActionBarSaverReloaded.spellAliases,
|
||||
function(spellID, aliases)
|
||||
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(aliases, ", ")))
|
||||
end)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
---@param text string
|
||||
@@ -282,16 +290,12 @@ local function Partition(text, size, deliminer)
|
||||
if #currentChunk + #word + 1 <= size then
|
||||
currentChunk = currentChunk .. deliminer .. word
|
||||
else
|
||||
if #currentChunk > 0 then
|
||||
ret[#ret + 1] = currentChunk
|
||||
end
|
||||
if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
|
||||
currentChunk = word
|
||||
end
|
||||
end
|
||||
|
||||
if #currentChunk > 0 then
|
||||
ret[#ret + 1] = currentChunk
|
||||
end
|
||||
if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
|
||||
|
||||
return ret
|
||||
end
|
||||
@@ -314,8 +318,8 @@ importExportFrame:SetBackdrop({
|
||||
left = 4,
|
||||
right = 4,
|
||||
top = 4,
|
||||
bottom = 4
|
||||
}
|
||||
bottom = 4,
|
||||
},
|
||||
})
|
||||
importExportFrame:SetBackdropColor(0, 0, 0, 0.8)
|
||||
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:EnableMouse(true)
|
||||
importExportFrame:RegisterForDrag("LeftButton")
|
||||
importExportFrame:SetScript("OnDragStart", function(self)
|
||||
self:StartMoving()
|
||||
end)
|
||||
importExportFrame:SetScript("OnDragStop", function(self)
|
||||
self:StopMovingOrSizing()
|
||||
end)
|
||||
importExportFrame:SetScript("OnShow", function(self)
|
||||
self:SetScale(1)
|
||||
end)
|
||||
importExportFrame:SetScript("OnDragStart", function(self) self:StartMoving() end)
|
||||
importExportFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
|
||||
importExportFrame:SetScript("OnShow", function(self) self:SetScale(1) end)
|
||||
importExportFrame:Hide()
|
||||
|
||||
local importExportFrameTextBox = CreateFrame("EditBox", "ABSImportExportFrameTextBox", importExportFrame)
|
||||
@@ -346,12 +344,10 @@ importExportFrameTextBox:SetMaxLetters(1000000)
|
||||
importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
|
||||
importExportFrame:Hide()
|
||||
if importingSet then
|
||||
local lines = {strsplit("\n", self:GetText())}
|
||||
local lines = { strsplit("\n", self:GetText()) }
|
||||
for _, line in ipairs(lines) do
|
||||
line = strtrim(line)
|
||||
if line ~= "" then
|
||||
ImportSet(importingSet, line)
|
||||
end
|
||||
if line ~= "" then ImportSet(importingSet, line) end
|
||||
end
|
||||
importingSet = nil
|
||||
end
|
||||
@@ -371,13 +367,11 @@ function ExportSet(setName)
|
||||
print(string.format("Unknown action type '%s' in set '%s'", action.type, setName))
|
||||
return
|
||||
end
|
||||
stringified[#stringified + 1] = string.format("%s\\%s\\%s", tostring(slot), tostring(action.id),
|
||||
tostring(typeChar))
|
||||
stringified[#stringified + 1] =
|
||||
string.format("%s\\%s\\%s", tostring(slot), tostring(action.id), tostring(typeChar))
|
||||
if typeChar == "M" then
|
||||
local _, _, macro = GetMacroInfo(action.id)
|
||||
if macro then
|
||||
macros[action.id] = macro
|
||||
end
|
||||
if macro then macros[action.id] = macro end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -394,9 +388,7 @@ function ExportSet(setName)
|
||||
end
|
||||
|
||||
function ParseAction(action)
|
||||
if not action or action == "" then
|
||||
return nil
|
||||
end
|
||||
if not action or action == "" then return nil end
|
||||
action = strtrim(action)
|
||||
local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)")
|
||||
if not typeChar then
|
||||
@@ -424,7 +416,7 @@ function ParseAction(action)
|
||||
return {
|
||||
slot = slot,
|
||||
id = id,
|
||||
type = type
|
||||
type = type,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -470,15 +462,13 @@ function ImportSet(setName, str)
|
||||
-- end
|
||||
|
||||
str = strtrim(str)
|
||||
local data = {strsplit("ž", str)}
|
||||
local data = { strsplit("ž", str) }
|
||||
for _, action in ipairs(data) do
|
||||
local paction = ParseAction(action)
|
||||
if paction then
|
||||
set[paction.slot] = {
|
||||
if paction then set[paction.slot] = {
|
||||
type = paction.type,
|
||||
id = paction.id
|
||||
}
|
||||
end
|
||||
id = paction.id,
|
||||
} end
|
||||
end
|
||||
|
||||
-- /dump ActionBarSaverReloaded.sets["havoc"]
|
||||
@@ -512,39 +502,19 @@ function PrintUsage()
|
||||
end
|
||||
|
||||
SlashCmdList["ABS"] = function(argv)
|
||||
local args = {strsplit(" ", argv)}
|
||||
local args = { strsplit(" ", argv) }
|
||||
local cmd = args[1]
|
||||
|
||||
if cmd == "save" then
|
||||
SaveSet(args[2])
|
||||
end
|
||||
if cmd == "restore" then
|
||||
RestoreSet(args[2])
|
||||
end
|
||||
if cmd == "delete" then
|
||||
DeleteSet(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 == "save" then SaveSet(args[2]) end
|
||||
if cmd == "restore" then RestoreSet(args[2]) end
|
||||
if cmd == "delete" then DeleteSet(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
|
||||
PrintUsage()
|
||||
end
|
||||
if cmd == "" or not cmd then PrintUsage() end
|
||||
end
|
||||
SLASH_ABS1 = "/abs"
|
||||
|
||||
12
B64.lua
12
B64.lua
@@ -1,11 +1,9 @@
|
||||
if not B64 then
|
||||
B64 = {}
|
||||
end
|
||||
if not B64 then B64 = {} end
|
||||
local encode, decode = {}, {
|
||||
[strbyte("=")] = false
|
||||
[strbyte("=")] = false,
|
||||
}
|
||||
for value = 0, 63 do
|
||||
local char = strsub('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', value + 1, value + 1)
|
||||
local char = strsub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", value + 1, value + 1)
|
||||
encode[value] = char
|
||||
decode[strbyte(char)] = value
|
||||
end
|
||||
@@ -26,9 +24,7 @@ end
|
||||
|
||||
function B64.Decode(str)
|
||||
local j = 1
|
||||
if strlen(str) % 4 ~= 0 then
|
||||
str = str .. string.rep("=", 4 - strlen(str) % 4)
|
||||
end
|
||||
if strlen(str) % 4 ~= 0 then str = str .. string.rep("=", 4 - strlen(str) % 4) end
|
||||
assert(strlen(str) % 4 == 0, format("invalid data length: %d", strlen(str)))
|
||||
for i = 1, strlen(str), 4 do
|
||||
local ba, bb, bc, bd = strbyte(str, i, i + 3)
|
||||
|
||||
@@ -4,9 +4,7 @@ local ADDON_NAME, shared = ...
|
||||
local frame = CreateFrame("Frame")
|
||||
frame:RegisterEvent("ADDON_LOADED")
|
||||
frame:SetScript("OnEvent", function(self, event, addon)
|
||||
if addon ~= ADDON_NAME then
|
||||
return
|
||||
end
|
||||
if addon ~= ADDON_NAME then return end
|
||||
|
||||
KeybindSaverReloaded = KeybindSaverReloaded or {}
|
||||
KeybindSaverReloaded.sets = KeybindSaverReloaded.sets or {}
|
||||
@@ -39,15 +37,9 @@ importExportFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
||||
importExportFrame:SetMovable(true)
|
||||
importExportFrame:EnableMouse(true)
|
||||
importExportFrame:RegisterForDrag("LeftButton")
|
||||
importExportFrame:SetScript("OnDragStart", function(self)
|
||||
self:StartMoving()
|
||||
end)
|
||||
importExportFrame:SetScript("OnDragStop", function(self)
|
||||
self:StopMovingOrSizing()
|
||||
end)
|
||||
importExportFrame:SetScript("OnShow", function(self)
|
||||
self:SetScale(1)
|
||||
end)
|
||||
importExportFrame:SetScript("OnDragStart", function(self) self:StartMoving() end)
|
||||
importExportFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
|
||||
importExportFrame:SetScript("OnShow", function(self) self:SetScale(1) end)
|
||||
importExportFrame:Hide()
|
||||
|
||||
local importingSet = nil
|
||||
@@ -64,14 +56,11 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
|
||||
importExportFrame:Hide()
|
||||
if importingSet then
|
||||
local text = self:GetText()
|
||||
if text and text ~= "" then
|
||||
ImportSet(importingSet, text)
|
||||
end
|
||||
if text and text ~= "" then ImportSet(importingSet, text) end
|
||||
importingSet = nil
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
local function SaveSet(setName)
|
||||
if not setName or setName == "" then
|
||||
print("Set name cannot be empty")
|
||||
@@ -83,12 +72,10 @@ local function SaveSet(setName)
|
||||
|
||||
for i = 1, numBindings do
|
||||
local command, category, key1, key2 = GetBinding(i)
|
||||
if key1 or key2 then
|
||||
set[command] = {
|
||||
if key1 or key2 then set[command] = {
|
||||
key1 = key1,
|
||||
key2 = key2,
|
||||
}
|
||||
end
|
||||
} end
|
||||
end
|
||||
|
||||
KeybindSaverReloaded.sets[setName] = set
|
||||
@@ -112,12 +99,8 @@ local function RestoreSet(setName)
|
||||
|
||||
-- Restore saved bindings
|
||||
for command, keys in pairs(set) do
|
||||
if keys.key1 then
|
||||
SetBinding(keys.key1, command)
|
||||
end
|
||||
if keys.key2 then
|
||||
SetBinding(keys.key2, command)
|
||||
end
|
||||
if keys.key1 then SetBinding(keys.key1, command) end
|
||||
if keys.key2 then SetBinding(keys.key2, command) end
|
||||
end
|
||||
|
||||
-- Save the changes
|
||||
@@ -164,12 +147,8 @@ local function ExportSet(setName)
|
||||
|
||||
local export = {}
|
||||
for command, keys in pairs(set) do
|
||||
if keys.key1 then
|
||||
table.insert(export, string.format("%s:%s", command, keys.key1))
|
||||
end
|
||||
if keys.key2 then
|
||||
table.insert(export, string.format("%s:%s", command, keys.key2))
|
||||
end
|
||||
if keys.key1 then table.insert(export, string.format("%s:%s", command, keys.key1)) end
|
||||
if keys.key2 then table.insert(export, string.format("%s:%s", command, keys.key2)) end
|
||||
end
|
||||
|
||||
local exportStr = table.concat(export, "\n")
|
||||
@@ -190,9 +169,7 @@ local function ImportSet(setName, importStr)
|
||||
for _, line in ipairs(lines) do
|
||||
local command, key = strsplit(":", line)
|
||||
if command and key then
|
||||
if not set[command] then
|
||||
set[command] = {}
|
||||
end
|
||||
if not set[command] then set[command] = {} end
|
||||
if not set[command].key1 then
|
||||
set[command].key1 = key
|
||||
else
|
||||
|
||||
4
Main.lua
4
Main.lua
@@ -3,9 +3,7 @@ local ADDON_NAME, shared = ...
|
||||
local frame = CreateFrame("Frame")
|
||||
frame:RegisterEvent("ADDON_LOADED")
|
||||
frame:SetScript("OnEvent", function(self, event, addon)
|
||||
if addon ~= ADDON_NAME then
|
||||
return
|
||||
end
|
||||
if addon ~= ADDON_NAME then return end
|
||||
|
||||
ActionBarSaverReloaded = ActionBarSaverReloaded or {}
|
||||
ActionBarSaverReloaded.spellAliases = ActionBarSaverReloaded.spellAliases or {}
|
||||
|
||||
13
stylua.toml
13
stylua.toml
@@ -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
|
||||
Reference in New Issue
Block a user