Thoroughly refuck everything
This commit is contained in:
161
Actions.lua
161
Actions.lua
@@ -1,5 +1,3 @@
|
|||||||
local ADDON_LOADED, shared = ...
|
|
||||||
|
|
||||||
local typeMap = {
|
local typeMap = {
|
||||||
spell = "S",
|
spell = "S",
|
||||||
item = "I",
|
item = "I",
|
||||||
@@ -17,6 +15,8 @@ local inverseTypeMap = {
|
|||||||
U = "summonmount",
|
U = "summonmount",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
local function PickupEquipmentSet(setName)
|
local function PickupEquipmentSet(setName)
|
||||||
local setIndex = 0
|
local setIndex = 0
|
||||||
|
|
||||||
@@ -38,7 +38,10 @@ local pickupActionButton = {
|
|||||||
summonmount = C_MountJournal.Pickup,
|
summonmount = C_MountJournal.Pickup,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function RestoreActionButton(self, index, actionButton)
|
---@param index number
|
||||||
|
---@param actionButton {type: string, id: number|string}
|
||||||
|
---@return boolean, number?
|
||||||
|
local function RestoreActionButton(index, actionButton)
|
||||||
if GetActionInfo(index) then
|
if GetActionInfo(index) then
|
||||||
PickupAction(index)
|
PickupAction(index)
|
||||||
ClearCursor()
|
ClearCursor()
|
||||||
@@ -63,8 +66,11 @@ local function RestoreActionButton(self, index, actionButton)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param actionButton {type: string, id: number|string}
|
||||||
|
---@return boolean
|
||||||
local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end
|
local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end
|
||||||
|
|
||||||
|
---@return table<string, number>
|
||||||
local function GetMacroDuplicates()
|
local function GetMacroDuplicates()
|
||||||
local t = {}
|
local t = {}
|
||||||
local duplicates = {}
|
local duplicates = {}
|
||||||
@@ -85,6 +91,10 @@ local function GetMacroDuplicates()
|
|||||||
return duplicates
|
return duplicates
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param warnings table<string, number>
|
||||||
|
---@param macroName string
|
||||||
|
---@param usages number
|
||||||
|
---@return nil
|
||||||
local function AddWarning(warnings, macroName, usages)
|
local function AddWarning(warnings, macroName, usages)
|
||||||
table.insert(
|
table.insert(
|
||||||
warnings,
|
warnings,
|
||||||
@@ -92,6 +102,8 @@ local function AddWarning(warnings, macroName, usages)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
function SaveSet(setName)
|
function SaveSet(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")
|
||||||
@@ -99,7 +111,9 @@ function SaveSet(setName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local duplicates = GetMacroDuplicates()
|
local duplicates = GetMacroDuplicates()
|
||||||
|
---@type table<number, {type: string, id: number|string}>
|
||||||
local set = {}
|
local set = {}
|
||||||
|
---@type string[]
|
||||||
local warnings = {}
|
local warnings = {}
|
||||||
|
|
||||||
for i = 1, MAX_ACTION_BUTTONS do
|
for i = 1, MAX_ACTION_BUTTONS do
|
||||||
@@ -124,6 +138,8 @@ function SaveSet(setName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
function RestoreSet(setName)
|
function RestoreSet(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")
|
||||||
@@ -151,11 +167,12 @@ function RestoreSet(setName)
|
|||||||
local actionButton = set[i]
|
local actionButton = set[i]
|
||||||
|
|
||||||
if IsMacro(actionButton) and duplicates[actionButton.id] then
|
if IsMacro(actionButton) and duplicates[actionButton.id] then
|
||||||
|
---@cast actionButton {type: string, id: string}
|
||||||
AddWarning(messages, actionButton.id, duplicates[actionButton.id])
|
AddWarning(messages, actionButton.id, duplicates[actionButton.id])
|
||||||
end
|
end
|
||||||
|
|
||||||
local succeeded, restoredID = RestoreActionButton(self, i, actionButton)
|
local succeeded, restoredID = RestoreActionButton(i, actionButton)
|
||||||
if not succeeded then
|
if not succeeded or not restoredID then
|
||||||
table.insert(
|
table.insert(
|
||||||
messages,
|
messages,
|
||||||
string.format(
|
string.format(
|
||||||
@@ -184,6 +201,8 @@ function RestoreSet(setName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
function DeleteSet(setName)
|
function DeleteSet(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")
|
||||||
@@ -200,6 +219,7 @@ function DeleteSet(setName)
|
|||||||
print(string.format("Deleted set '%s'", setName))
|
print(string.format("Deleted set '%s'", setName))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function ListSets()
|
function ListSets()
|
||||||
local sets = {}
|
local sets = {}
|
||||||
for setName, foo in pairs(ActionBarSaverDaved.sets) do
|
for setName, foo in pairs(ActionBarSaverDaved.sets) do
|
||||||
@@ -211,93 +231,64 @@ function ListSets()
|
|||||||
print(not (not setsStr or setsStr == "") and setsStr or "No sets found")
|
print(not (not setsStr or setsStr == "") and setsStr or "No sets found")
|
||||||
end
|
end
|
||||||
|
|
||||||
function AliasSpell(args)
|
---@param of string
|
||||||
if not args or args == "" then
|
---@param to string
|
||||||
|
---@return nil
|
||||||
|
function AliasSpell(of, to)
|
||||||
|
if not of or not to then
|
||||||
print("Must provide args in the format 'spellID aliasID'")
|
print("Must provide args in the format 'spellID aliasID'")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local spellID, aliasID = string.match(args, "(%d+)%s+(%d+)")
|
local ofId = tonumber(of)
|
||||||
|
local toId = tonumber(to)
|
||||||
|
|
||||||
spellID = tonumber(spellID)
|
if not (ofId and toId) then
|
||||||
aliasID = tonumber(aliasID)
|
print(string.format("Could not parse %s and/or %s to numbers", of, to))
|
||||||
|
|
||||||
if not (spellID and aliasID) then
|
|
||||||
print(string.format("Could not parse spellID and aliasID from '%s'", args))
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local aliases = ActionBarSaverDaved.spellAliases[spellID] or {}
|
local aliases = ActionBarSaverDaved.spellAliases[ofId] or {}
|
||||||
|
|
||||||
for _, id in ipairs(aliases) do
|
for _, id in ipairs(aliases) do
|
||||||
if id == aliasID then
|
if id == toId then
|
||||||
print(string.format("Spell %d is already aliased by %d", spellID, aliasID))
|
print(string.format("Spell %d is already aliased by %d", ofId, toId))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(ActionBarSaverDaved.spellAliases[spellID], aliasID)
|
table.insert(ActionBarSaverDaved.spellAliases[ofId], toId)
|
||||||
print(string.format("Added %d as an alias for %d", aliasID, spellID))
|
print(string.format("Added %d as an alias for %d", toId, ofId))
|
||||||
end
|
end
|
||||||
|
|
||||||
function DeleteSpellAliases(spellID)
|
---@param of string
|
||||||
if not spellID or spellID == "" then
|
---@return nil
|
||||||
|
function DeleteSpellAliases(of)
|
||||||
|
if not of then
|
||||||
print("Must provide a valid spellID")
|
print("Must provide a valid spellID")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
spellID = tonumber(spellID)
|
local ofId = tonumber(of)
|
||||||
|
|
||||||
if not ActionBarSaverDaved.spellAliases[spellID] then
|
if not ofId then
|
||||||
print(string.format("No aliases to remove for spell with ID %d", spellID))
|
print(string.format("Could not parse spellID from '%s'", of))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ActionBarSaverDaved.spellAliases[spellID] = nil
|
if not ActionBarSaverDaved.spellAliases[ofId] then
|
||||||
|
print(string.format("No aliases to remove for spell with ID %d", ofId))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
print(string.format("Removed all aliases for spell with ID %d", spellID))
|
ActionBarSaverDaved.spellAliases[ofId] = nil
|
||||||
|
print(string.format("Removed all aliases for spell with ID %d", ofId))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function ListAliases()
|
function ListAliases()
|
||||||
local aliases = ActionBarSaverDaved.spellAliases
|
for spellID, spellAliases in pairs(ActionBarSaverDaved.spellAliases) do
|
||||||
|
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(spellAliases, ", ")))
|
||||||
if Dict.isEmpty(aliases) then
|
|
||||||
print("No aliases found")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Dict.iter(
|
|
||||||
ActionBarSaverDaved.spellAliases,
|
|
||||||
function(spellID, aliases)
|
|
||||||
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(aliases, ", ")))
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param text string
|
|
||||||
---@param size number
|
|
||||||
---@param deliminer string
|
|
||||||
---@return string[]
|
|
||||||
local function Partition(text, size, deliminer)
|
|
||||||
local words = {}
|
|
||||||
for word in text:gmatch("[^" .. deliminer .. "]+") do
|
|
||||||
words[#words + 1] = word
|
|
||||||
end
|
|
||||||
|
|
||||||
local ret = {}
|
|
||||||
local currentChunk = ""
|
|
||||||
|
|
||||||
for _, word in ipairs(words) do
|
|
||||||
if #currentChunk + #word + 1 <= size then
|
|
||||||
currentChunk = currentChunk .. deliminer .. word
|
|
||||||
else
|
|
||||||
if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
|
|
||||||
currentChunk = word
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
|
|
||||||
|
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local importingSet = nil
|
local importingSet = nil
|
||||||
@@ -353,6 +344,8 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
function ExportSet(setName)
|
function ExportSet(setName)
|
||||||
local set = ActionBarSaverDaved.sets[setName]
|
local set = ActionBarSaverDaved.sets[setName]
|
||||||
if not set then
|
if not set then
|
||||||
@@ -387,30 +380,39 @@ function ExportSet(setName)
|
|||||||
importExportFrameTextBox:SetFocus()
|
importExportFrameTextBox:SetFocus()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param action string
|
||||||
|
---@return {slot: number, id: number|string, type: string}
|
||||||
function ParseAction(action)
|
function ParseAction(action)
|
||||||
if not action or action == "" then return nil end
|
local ret = {
|
||||||
|
slot = 0,
|
||||||
|
id = 0,
|
||||||
|
type = "",
|
||||||
|
}
|
||||||
|
|
||||||
|
if not action or action == "" then return ret end
|
||||||
action = strtrim(action)
|
action = strtrim(action)
|
||||||
local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)")
|
local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)")
|
||||||
if not typeChar then
|
if not typeChar then
|
||||||
print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName)))
|
print(string.format("Unknown action type '%s'", tostring(typeChar)))
|
||||||
return
|
return ret
|
||||||
end
|
end
|
||||||
local type = inverseTypeMap[typeChar]
|
local type = inverseTypeMap[typeChar]
|
||||||
if not type then
|
if not type then
|
||||||
print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName)))
|
print(string.format("Unknown action type '%s'", tostring(typeChar)))
|
||||||
return
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
slot = tonumber(slot)
|
slot = tonumber(slot)
|
||||||
|
id = tonumber(id)
|
||||||
|
|
||||||
if not slot then
|
if not slot then
|
||||||
print(string.format("Unknown slot '%s' in set '%s'", tostring(slot), tostring(setName)))
|
print(string.format("Unknown slot '%s'", tostring(slot)))
|
||||||
return
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
if not id then
|
if not id then
|
||||||
print(string.format("Unknown id '%s' in set '%s'", tostring(id), tostring(setName)))
|
print(string.format("Unknown id '%s'", tostring(id)))
|
||||||
return
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -420,6 +422,8 @@ function ParseAction(action)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param importString string
|
||||||
|
---@return nil
|
||||||
function ImportMacro(importString)
|
function ImportMacro(importString)
|
||||||
if not importString or importString == "" then
|
if not importString or importString == "" then
|
||||||
print("Must provide a valid macro string")
|
print("Must provide a valid macro string")
|
||||||
@@ -437,14 +441,16 @@ function ImportMacro(importString)
|
|||||||
local reconstructed = B64.Decode(content)
|
local reconstructed = B64.Decode(content)
|
||||||
local macroIdx = GetMacroIndexByName(name)
|
local macroIdx = GetMacroIndexByName(name)
|
||||||
if macroIdx == 0 then
|
if macroIdx == 0 then
|
||||||
macroIdx = CreateMacro(name, "Inv_misc_questionmark", "")
|
CreateMacro(name, "Inv_misc_questionmark", "")
|
||||||
macroIdx = GetMacroIndexByName(name)
|
macroIdx = GetMacroIndexByName(name)
|
||||||
end
|
end
|
||||||
EditMacro(macroIdx, name, nil, reconstructed)
|
EditMacro(macroIdx, name, nil, reconstructed)
|
||||||
print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed))
|
print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed))
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@param str string
|
||||||
|
---@return nil
|
||||||
function ImportSet(setName, str)
|
function ImportSet(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")
|
||||||
@@ -471,12 +477,12 @@ function ImportSet(setName, str)
|
|||||||
} end
|
} end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- /dump ActionBarSaverDaved.sets["havoc"]
|
|
||||||
-- /dump ActionBarSaverDaved.sets["havoc2"]
|
|
||||||
ActionBarSaverDaved.sets[setName] = set
|
ActionBarSaverDaved.sets[setName] = set
|
||||||
print(string.format("Imported set '%s'", setName))
|
print(string.format("Imported set '%s'", setName))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param setName string
|
||||||
|
---@return nil
|
||||||
function ImportSetDialogue(setName)
|
function ImportSetDialogue(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")
|
||||||
@@ -488,6 +494,7 @@ function ImportSetDialogue(setName)
|
|||||||
importExportFrameTextBox:SetFocus()
|
importExportFrameTextBox:SetFocus()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return nil
|
||||||
function PrintUsage()
|
function PrintUsage()
|
||||||
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>")
|
||||||
|
|||||||
@@ -224,19 +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
|
if cmd == "save" then SaveSet(args[2]) end
|
||||||
SaveSet(args[2])
|
if cmd == "restore" then RestoreSet(args[2]) end
|
||||||
elseif cmd == "restore" then
|
if cmd == "delete" then DeleteSet(args[2]) end
|
||||||
RestoreSet(args[2])
|
if cmd == "list" then ListSets() end
|
||||||
elseif cmd == "delete" then
|
if cmd == "export" then ExportSet(args[2]) end
|
||||||
DeleteSet(args[2])
|
if cmd == "import" then ImportSetDialogue(args[2]) end
|
||||||
elseif cmd == "list" then
|
|
||||||
ListSets()
|
if cmd == "" or not cmd then PrintUsage() end
|
||||||
elseif cmd == "export" then
|
|
||||||
ExportSet(args[2])
|
|
||||||
elseif cmd == "import" then
|
|
||||||
ImportSetDialogue(args[2])
|
|
||||||
else
|
|
||||||
PrintUsage()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
1
Main.lua
1
Main.lua
@@ -7,6 +7,7 @@ frame:SetScript("OnEvent", function(self, event, addon)
|
|||||||
|
|
||||||
---@class ActionBarSaverDaved
|
---@class ActionBarSaverDaved
|
||||||
---@field spellAliases table<number, number[]>
|
---@field spellAliases table<number, number[]>
|
||||||
|
---@field sets table<string, table<number, {type: string, id: number|string}>>
|
||||||
ActionBarSaverDaved = ActionBarSaverDaved or {}
|
ActionBarSaverDaved = ActionBarSaverDaved or {}
|
||||||
ActionBarSaverDaved.spellAliases = ActionBarSaverDaved.spellAliases or {}
|
ActionBarSaverDaved.spellAliases = ActionBarSaverDaved.spellAliases or {}
|
||||||
ActionBarSaverDaved.sets = ActionBarSaverDaved.sets or {}
|
ActionBarSaverDaved.sets = ActionBarSaverDaved.sets or {}
|
||||||
|
|||||||
Reference in New Issue
Block a user