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

@@ -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] = {
key1 = key1,
key2 = key2,
}
end
if key1 or key2 then set[command] = {
key1 = key1,
key2 = key2,
} 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