Clean up the code in general a bit

This commit is contained in:
2025-05-06 22:15:08 +02:00
parent 24e56078bd
commit 38b5dbccb1
6 changed files with 42 additions and 68 deletions

View File

@@ -1,4 +1,4 @@
local ADDON_NAME, shared = ...
local ADDON_NAME = ...
-- Initialize saved variables
local frame = CreateFrame("Frame")
@@ -61,17 +61,20 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
end
end)
---@param setName string
---@return nil
local function SaveSet(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, category, key1, key2 = GetBinding(i)
local command, _, key1, key2 = GetBinding(i)
if key1 or key2 then set[command] = {
key1 = key1,
key2 = key2,
@@ -82,6 +85,8 @@ local function SaveSet(setName)
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")
@@ -108,6 +113,8 @@ local function RestoreSet(setName)
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")
@@ -123,6 +130,7 @@ local function DeleteSet(setName)
print(string.format("Deleted keybind set '%s'", setName))
end
---@return nil
local function ListSets()
local sets = {}
for setName in pairs(KeybindSaverDaved.sets) do
@@ -138,6 +146,8 @@ local function ListSets()
end
end
---@param setName string
---@return nil
local function ExportSet(setName)
local set = KeybindSaverDaved.sets[setName]
if not set then
@@ -157,6 +167,9 @@ local function ExportSet(setName)
importExportFrameTextBox:SetFocus()
end
---@param setName string
---@param importStr string
---@return nil
local function ImportSet(setName, importStr)
if not setName or setName == "" then
print("Set name cannot be empty")
@@ -182,6 +195,8 @@ local function ImportSet(setName, importStr)
print(string.format("Imported keybind set '%s'", setName))
end
---@param setName string
---@return nil
local function ImportSetDialogue(setName)
if not setName or setName == "" then
print("Set name cannot be empty")
@@ -193,6 +208,7 @@ local function ImportSetDialogue(setName)
importExportFrameTextBox:SetFocus()
end
---@return nil
local function PrintUsage()
print("Keybind Saver Slash Commands:")
print("/kbs save <set> - Saves your current keybinds under the given <set>")
@@ -203,7 +219,6 @@ local function PrintUsage()
print("/kbs import <set> - Opens a window to import a keybind set")
end
-- Register slash commands
SLASH_KBS1 = "/kbs"
SlashCmdList["KBS"] = function(argv)
local args = { strsplit(" ", argv) }