Compare commits
7 Commits
53e201e414
...
master
Author | SHA1 | Date | |
---|---|---|---|
1759ebfab6 | |||
798043c7aa | |||
396ef0437f | |||
d92fe23d8a | |||
1b09f262d5 | |||
f17078c8a8 | |||
3e85b9933e |
@@ -1,6 +1,6 @@
|
||||
## Interface: 70300
|
||||
## Title: ActionBarSaver: Daved
|
||||
## Version: 1.1.2
|
||||
## Version: 1.2.3
|
||||
## Notes: Manage, save, restore, import and export action bar and keybind profiles
|
||||
## Author: Phat phuck dave
|
||||
## SavedVariables: ActionBarSaverDaved, KeybindSaverDaved
|
||||
|
13
Actions.lua
13
Actions.lua
@@ -39,13 +39,19 @@ local pickupActionButton = {
|
||||
}
|
||||
|
||||
---@param index number
|
||||
---@param actionButton {type: string, id: number|string}
|
||||
---@return boolean, number?
|
||||
local function RestoreActionButton(index, actionButton)
|
||||
---@return nil
|
||||
local function ClearActionButton(index)
|
||||
if GetActionInfo(index) then
|
||||
PickupAction(index)
|
||||
ClearCursor()
|
||||
end
|
||||
end
|
||||
|
||||
---@param index number
|
||||
---@param actionButton {type: string, id: number|string}
|
||||
---@return boolean, number?
|
||||
local function RestoreActionButton(index, actionButton)
|
||||
ClearActionButton(index)
|
||||
|
||||
if not actionButton then return true, nil end
|
||||
|
||||
@@ -174,6 +180,7 @@ function RestoreActionbarSet(setName)
|
||||
|
||||
for i = 1, MAX_ACTION_BUTTONS do
|
||||
local actionButton = set[i]
|
||||
ClearActionButton(i)
|
||||
if actionButton then
|
||||
if IsMacro(actionButton) and duplicates[actionButton.id] then
|
||||
---@cast actionButton {type: string, id: string}
|
||||
|
@@ -24,6 +24,10 @@ local function SaveKeybindSet(setName)
|
||||
|
||||
for i = 1, numBindings do
|
||||
local command, _, key1, key2 = GetBinding(i)
|
||||
if string.find(command, "CLICK ") then
|
||||
-- What a stupid fucking api, so fucking idiotic, retarded
|
||||
command, key2 = strsplit(":", command)
|
||||
end
|
||||
if key1 or key2 then set[command] = {
|
||||
key1 = key1,
|
||||
key2 = key2,
|
||||
@@ -34,6 +38,21 @@ local function SaveKeybindSet(setName)
|
||||
print(string.format("Saved keybind set '%s'!", setName))
|
||||
end
|
||||
|
||||
---@param command string
|
||||
---@return nil
|
||||
local function UnbindCommand(command)
|
||||
if not command or command == "" then
|
||||
print("Cannot unbind an empty command")
|
||||
return
|
||||
end
|
||||
|
||||
local keys = { GetBindingKey(command) }
|
||||
for _, key in ipairs(keys) do
|
||||
-- print("Unbinding", key)
|
||||
SetBinding(key)
|
||||
end
|
||||
end
|
||||
|
||||
---@param setName string
|
||||
---@return nil
|
||||
local function RestoreKeybindSet(setName)
|
||||
@@ -53,12 +72,27 @@ local function RestoreKeybindSet(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
|
||||
UnbindCommand(command)
|
||||
-- This fucking catastrophe binds a KEY(2) to CLICK A BUTTON (command) as a MOUSE BUTTON (key1)
|
||||
if string.find(command, "CLICK ") and keys.key2 then
|
||||
command = string.gsub(command, "CLICK ", "")
|
||||
local ok = SetBindingClick(keys.key2, command, keys.key1)
|
||||
if not ok then print("Failed to bind click", keys.key1, command) end
|
||||
else
|
||||
if keys.key1 then
|
||||
local ok = SetBinding(keys.key1, command)
|
||||
if not ok then print("Failed to bind", keys.key1, command) end
|
||||
end
|
||||
if keys.key2 then
|
||||
local ok = SetBinding(keys.key2, command)
|
||||
if not ok then print("Failed to bind", keys.key2, command) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Save the changes
|
||||
SaveBindings(GetCurrentBindingSet())
|
||||
SaveBindings(1)
|
||||
print(string.format("Restored keybind set '%s'", setName))
|
||||
end
|
||||
|
||||
@@ -108,14 +142,18 @@ local function ImportKeybindSet(setName, importStr)
|
||||
local lines = { strsplit("\n", importStr) }
|
||||
|
||||
for _, line in ipairs(lines) do
|
||||
local command, key = strsplit(":", line)
|
||||
local command, key, key2 = 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
|
||||
if string.find(command, "CLICK ") then
|
||||
-- I can't believe we have to do this bullshit...
|
||||
local tmp = key
|
||||
key = key2
|
||||
key2 = tmp
|
||||
end
|
||||
if not set[command] then set[command] = {
|
||||
key1 = key,
|
||||
key2 = key2,
|
||||
} end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -185,9 +223,14 @@ local function ExportKeybindSet(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 command and keys and (keys.key1 or keys.key2) then
|
||||
local formatted = command
|
||||
if keys.key1 then formatted = formatted .. ":" .. keys.key1 end
|
||||
if keys.key2 then formatted = formatted .. ":" .. keys.key2 end
|
||||
export[#export + 1] = formatted
|
||||
end
|
||||
end
|
||||
table.sort(export)
|
||||
|
||||
local exportStr = table.concat(export, "\n")
|
||||
importExportFrame:Show()
|
||||
|
2
Meta
2
Meta
Submodule Meta updated: 51a48175fa...9aae83307e
Reference in New Issue
Block a user