Rename all functions to reduce duplication
This commit is contained in:
32
Actions.lua
32
Actions.lua
@@ -104,7 +104,7 @@ end
|
|||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@return nil
|
---@return nil
|
||||||
function SaveSet(setName)
|
function SaveActionbarSet(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
|
||||||
@@ -140,7 +140,7 @@ end
|
|||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@return nil
|
---@return nil
|
||||||
function RestoreSet(setName)
|
function RestoreActionbarSet(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
|
||||||
@@ -203,7 +203,7 @@ end
|
|||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@return nil
|
---@return nil
|
||||||
function DeleteSet(setName)
|
function DeleteActionbarSet(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
|
||||||
@@ -220,7 +220,7 @@ function DeleteSet(setName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
function ListSets()
|
function ListActionbarSets()
|
||||||
local sets = {}
|
local sets = {}
|
||||||
for setName, foo in pairs(ActionBarSaverDaved.sets) do
|
for setName, foo in pairs(ActionBarSaverDaved.sets) do
|
||||||
sets[#sets + 1] = setName
|
sets[#sets + 1] = setName
|
||||||
@@ -338,7 +338,7 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
|
|||||||
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 ImportSet(importingSet, line) end
|
if line ~= "" then ImportActionbarSet(importingSet, line) end
|
||||||
end
|
end
|
||||||
importingSet = nil
|
importingSet = nil
|
||||||
end
|
end
|
||||||
@@ -346,7 +346,7 @@ end)
|
|||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@return nil
|
---@return nil
|
||||||
function ExportSet(setName)
|
function ExportActionbarSet(setName)
|
||||||
local set = ActionBarSaverDaved.sets[setName]
|
local set = ActionBarSaverDaved.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))
|
||||||
@@ -451,7 +451,7 @@ end
|
|||||||
---@param setName string
|
---@param setName string
|
||||||
---@param str string
|
---@param str string
|
||||||
---@return nil
|
---@return nil
|
||||||
function ImportSet(setName, str)
|
function ImportActionbarSet(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
|
||||||
@@ -483,7 +483,7 @@ end
|
|||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@return nil
|
---@return nil
|
||||||
function ImportSetDialogue(setName)
|
function ImportActionbarSetDialogue(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
|
||||||
@@ -495,7 +495,7 @@ function ImportSetDialogue(setName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
function PrintUsage()
|
function PrintActionbarUsage()
|
||||||
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>")
|
||||||
@@ -512,16 +512,16 @@ SlashCmdList["ABS"] = function(argv)
|
|||||||
local args = { strsplit(" ", argv) }
|
local args = { strsplit(" ", argv) }
|
||||||
local cmd = args[1]
|
local cmd = args[1]
|
||||||
|
|
||||||
if cmd == "save" then SaveSet(args[2]) end
|
if cmd == "save" then SaveActionbarSet(args[2]) end
|
||||||
if cmd == "restore" then RestoreSet(args[2]) end
|
if cmd == "restore" then RestoreActionbarSet(args[2]) end
|
||||||
if cmd == "delete" then DeleteSet(args[2]) end
|
if cmd == "delete" then DeleteActionbarSet(args[2]) end
|
||||||
if cmd == "list" then ListSets() end
|
if cmd == "list" then ListActionbarSets() end
|
||||||
if cmd == "alias" then AliasSpell(args[2], args[3]) end
|
if cmd == "alias" then AliasSpell(args[2], args[3]) end
|
||||||
if cmd == "unalias" then DeleteSpellAliases(args[2]) end
|
if cmd == "unalias" then DeleteSpellAliases(args[2]) end
|
||||||
if cmd == "aliases" then ListAliases() end
|
if cmd == "aliases" then ListAliases() end
|
||||||
if cmd == "export" then ExportSet(args[2]) end
|
if cmd == "export" then ExportActionbarSet(args[2]) end
|
||||||
if cmd == "import" then ImportSetDialogue(args[2]) end
|
if cmd == "import" then ImportActionbarSetDialogue(args[2]) end
|
||||||
|
|
||||||
if cmd == "" or not cmd then PrintUsage() end
|
if cmd == "" or not cmd then PrintActionbarUsage() end
|
||||||
end
|
end
|
||||||
SLASH_ABS1 = "/abs"
|
SLASH_ABS1 = "/abs"
|
||||||
|
248
KeybindSaver.lua
248
KeybindSaver.lua
@@ -10,6 +10,119 @@ frame:SetScript("OnEvent", function(self, event, addon)
|
|||||||
KeybindSaverDaved.sets = KeybindSaverDaved.sets or {}
|
KeybindSaverDaved.sets = KeybindSaverDaved.sets or {}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
|
local function SaveKeybindSet(setName)
|
||||||
|
if not setName or setName == "" then
|
||||||
|
print("Set name cannot be empty")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type table<string, {key1: string, key2: string?}>
|
||||||
|
local set = {}
|
||||||
|
local numBindings = GetNumBindings()
|
||||||
|
|
||||||
|
for i = 1, numBindings do
|
||||||
|
local command, _, key1, key2 = GetBinding(i)
|
||||||
|
if key1 or key2 then set[command] = {
|
||||||
|
key1 = key1,
|
||||||
|
key2 = key2,
|
||||||
|
} end
|
||||||
|
end
|
||||||
|
|
||||||
|
KeybindSaverDaved.sets[setName] = set
|
||||||
|
print(string.format("Saved keybind set '%s'!", setName))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
|
local function RestoreKeybindSet(setName)
|
||||||
|
if not setName or setName == "" then
|
||||||
|
print("Set name cannot be empty")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local set = KeybindSaverDaved.sets[setName]
|
||||||
|
if not set then
|
||||||
|
print(string.format("No set with the name '%s' exists", setName))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clear all current bindings first
|
||||||
|
ClearOverrideBindings(frame)
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Save the changes
|
||||||
|
SaveBindings(GetCurrentBindingSet())
|
||||||
|
print(string.format("Restored keybind set '%s'", setName))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
|
local function DeleteKeybindSet(setName)
|
||||||
|
if not setName or setName == "" then
|
||||||
|
print("Set name cannot be empty")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not KeybindSaverDaved.sets[setName] then
|
||||||
|
print(string.format("No set with the name '%s' exists", setName))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
KeybindSaverDaved.sets[setName] = nil
|
||||||
|
print(string.format("Deleted keybind set '%s'", setName))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
|
local function ListKeybindSets()
|
||||||
|
local sets = {}
|
||||||
|
for setName in pairs(KeybindSaverDaved.sets) do
|
||||||
|
table.insert(sets, setName)
|
||||||
|
end
|
||||||
|
table.sort(sets)
|
||||||
|
|
||||||
|
if #sets == 0 then
|
||||||
|
print("No keybind sets found")
|
||||||
|
else
|
||||||
|
print("Saved keybind sets:")
|
||||||
|
print(table.concat(sets, ", "))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@param importStr string
|
||||||
|
---@return nil
|
||||||
|
local function ImportKeybindSet(setName, importStr)
|
||||||
|
if not setName or setName == "" then
|
||||||
|
print("Set name cannot be empty")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local set = {}
|
||||||
|
local lines = { strsplit("\n", 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].key1 then
|
||||||
|
set[command].key1 = key
|
||||||
|
else
|
||||||
|
set[command].key2 = key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
KeybindSaverDaved.sets[setName] = set
|
||||||
|
print(string.format("Imported keybind set '%s'", setName))
|
||||||
|
end
|
||||||
|
|
||||||
-- Create the import/export frame
|
-- Create the import/export frame
|
||||||
local importExportFrame = CreateFrame("Frame", "KBSImportExportFrame", UIParent)
|
local importExportFrame = CreateFrame("Frame", "KBSImportExportFrame", UIParent)
|
||||||
importExportFrame:SetSize(512, 512)
|
importExportFrame:SetSize(512, 512)
|
||||||
@@ -56,99 +169,14 @@ 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 ImportSet(importingSet, text) end
|
if text and text ~= "" then ImportKeybindSet(importingSet, text) end
|
||||||
importingSet = nil
|
importingSet = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@return nil
|
---@return nil
|
||||||
local function SaveSet(setName)
|
local function ExportKeybindSet(setName)
|
||||||
if not setName or setName == "" then
|
|
||||||
print("Set name cannot be empty")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type table<string, {key1: string, key2: string?}>
|
|
||||||
local set = {}
|
|
||||||
local numBindings = GetNumBindings()
|
|
||||||
|
|
||||||
for i = 1, numBindings do
|
|
||||||
local command, _, key1, key2 = GetBinding(i)
|
|
||||||
if key1 or key2 then set[command] = {
|
|
||||||
key1 = key1,
|
|
||||||
key2 = key2,
|
|
||||||
} end
|
|
||||||
end
|
|
||||||
|
|
||||||
KeybindSaverDaved.sets[setName] = set
|
|
||||||
print(string.format("Saved keybind set '%s'!", setName))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param setName string
|
|
||||||
---@return nil
|
|
||||||
local function RestoreSet(setName)
|
|
||||||
if not setName or setName == "" then
|
|
||||||
print("Set name cannot be empty")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local set = KeybindSaverDaved.sets[setName]
|
|
||||||
if not set then
|
|
||||||
print(string.format("No set with the name '%s' exists", setName))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Clear all current bindings first
|
|
||||||
ClearOverrideBindings(frame)
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Save the changes
|
|
||||||
SaveBindings(GetCurrentBindingSet())
|
|
||||||
print(string.format("Restored keybind set '%s'", setName))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param setName string
|
|
||||||
---@return nil
|
|
||||||
local function DeleteSet(setName)
|
|
||||||
if not setName or setName == "" then
|
|
||||||
print("Set name cannot be empty")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not KeybindSaverDaved.sets[setName] then
|
|
||||||
print(string.format("No set with the name '%s' exists", setName))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
KeybindSaverDaved.sets[setName] = nil
|
|
||||||
print(string.format("Deleted keybind set '%s'", setName))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@return nil
|
|
||||||
local function ListSets()
|
|
||||||
local sets = {}
|
|
||||||
for setName in pairs(KeybindSaverDaved.sets) do
|
|
||||||
table.insert(sets, setName)
|
|
||||||
end
|
|
||||||
table.sort(sets)
|
|
||||||
|
|
||||||
if #sets == 0 then
|
|
||||||
print("No keybind sets found")
|
|
||||||
else
|
|
||||||
print("Saved keybind sets:")
|
|
||||||
print(table.concat(sets, ", "))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param setName string
|
|
||||||
---@return nil
|
|
||||||
local function ExportSet(setName)
|
|
||||||
local set = KeybindSaverDaved.sets[setName]
|
local set = KeybindSaverDaved.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))
|
||||||
@@ -168,36 +196,8 @@ local function ExportSet(setName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param setName string
|
---@param setName string
|
||||||
---@param importStr string
|
|
||||||
---@return nil
|
---@return nil
|
||||||
local function ImportSet(setName, importStr)
|
local function ImportKeybindSetDialogue(setName)
|
||||||
if not setName or setName == "" then
|
|
||||||
print("Set name cannot be empty")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local set = {}
|
|
||||||
local lines = { strsplit("\n", 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].key1 then
|
|
||||||
set[command].key1 = key
|
|
||||||
else
|
|
||||||
set[command].key2 = key
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
KeybindSaverDaved.sets[setName] = set
|
|
||||||
print(string.format("Imported keybind set '%s'", setName))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param setName string
|
|
||||||
---@return nil
|
|
||||||
local function ImportSetDialogue(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
|
||||||
@@ -209,7 +209,7 @@ local function ImportSetDialogue(setName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
local function PrintUsage()
|
local function PrintKeybindUsage()
|
||||||
print("Keybind Saver Slash Commands:")
|
print("Keybind Saver Slash Commands:")
|
||||||
print("/kbs save <set> - Saves your current keybinds under the given <set>")
|
print("/kbs save <set> - Saves your current keybinds under the given <set>")
|
||||||
print("/kbs restore <set> - Restores the saved <set>")
|
print("/kbs restore <set> - Restores the saved <set>")
|
||||||
@@ -224,12 +224,12 @@ SlashCmdList["KBS"] = function(argv)
|
|||||||
local args = { strsplit(" ", argv) }
|
local args = { strsplit(" ", argv) }
|
||||||
local cmd = args[1]
|
local cmd = args[1]
|
||||||
|
|
||||||
if cmd == "save" then SaveSet(args[2]) end
|
if cmd == "save" then SaveKeybindSet(args[2]) end
|
||||||
if cmd == "restore" then RestoreSet(args[2]) end
|
if cmd == "restore" then RestoreKeybindSet(args[2]) end
|
||||||
if cmd == "delete" then DeleteSet(args[2]) end
|
if cmd == "delete" then DeleteKeybindSet(args[2]) end
|
||||||
if cmd == "list" then ListSets() end
|
if cmd == "list" then ListKeybindSets() end
|
||||||
if cmd == "export" then ExportSet(args[2]) end
|
if cmd == "export" then ExportKeybindSet(args[2]) end
|
||||||
if cmd == "import" then ImportSetDialogue(args[2]) end
|
if cmd == "import" then ImportKeybindSetDialogue(args[2]) end
|
||||||
|
|
||||||
if cmd == "" or not cmd then PrintUsage() end
|
if cmd == "" or not cmd then PrintKeybindUsage() end
|
||||||
end
|
end
|
||||||
|
2
Main.lua
2
Main.lua
@@ -17,3 +17,5 @@ frame:SetScript("OnEvent", function(self, event, addon)
|
|||||||
KeybindSaverDaved = KeybindSaverDaved or {}
|
KeybindSaverDaved = KeybindSaverDaved or {}
|
||||||
KeybindSaverDaved.sets = KeybindSaverDaved.sets or {}
|
KeybindSaverDaved.sets = KeybindSaverDaved.sets or {}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- TODO: Fix equipment sets (saving reloading exporting importing...)
|
Reference in New Issue
Block a user