Thoroughly refuck everything

This commit is contained in:
2025-05-06 22:42:57 +02:00
parent 38b5dbccb1
commit 3bd12c8ca8
3 changed files with 93 additions and 92 deletions

View File

@@ -1,5 +1,3 @@
local ADDON_LOADED, shared = ...
local typeMap = {
spell = "S",
item = "I",
@@ -17,6 +15,8 @@ local inverseTypeMap = {
U = "summonmount",
}
---@param setName string
---@return nil
local function PickupEquipmentSet(setName)
local setIndex = 0
@@ -38,7 +38,10 @@ local pickupActionButton = {
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
PickupAction(index)
ClearCursor()
@@ -63,8 +66,11 @@ local function RestoreActionButton(self, index, actionButton)
return false
end
---@param actionButton {type: string, id: number|string}
---@return boolean
local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end
---@return table<string, number>
local function GetMacroDuplicates()
local t = {}
local duplicates = {}
@@ -85,6 +91,10 @@ local function GetMacroDuplicates()
return duplicates
end
---@param warnings table<string, number>
---@param macroName string
---@param usages number
---@return nil
local function AddWarning(warnings, macroName, usages)
table.insert(
warnings,
@@ -92,6 +102,8 @@ local function AddWarning(warnings, macroName, usages)
)
end
---@param setName string
---@return nil
function SaveSet(setName)
if not setName or setName == "" then
print("Set name cannot be empty")
@@ -99,7 +111,9 @@ function SaveSet(setName)
end
local duplicates = GetMacroDuplicates()
---@type table<number, {type: string, id: number|string}>
local set = {}
---@type string[]
local warnings = {}
for i = 1, MAX_ACTION_BUTTONS do
@@ -124,6 +138,8 @@ function SaveSet(setName)
end
end
---@param setName string
---@return nil
function RestoreSet(setName)
if not setName or setName == "" then
print("Set name cannot be empty")
@@ -151,11 +167,12 @@ function RestoreSet(setName)
local actionButton = set[i]
if IsMacro(actionButton) and duplicates[actionButton.id] then
---@cast actionButton {type: string, id: string}
AddWarning(messages, actionButton.id, duplicates[actionButton.id])
end
local succeeded, restoredID = RestoreActionButton(self, i, actionButton)
if not succeeded then
local succeeded, restoredID = RestoreActionButton(i, actionButton)
if not succeeded or not restoredID then
table.insert(
messages,
string.format(
@@ -184,6 +201,8 @@ function RestoreSet(setName)
end
end
---@param setName string
---@return nil
function DeleteSet(setName)
if not setName or setName == "" then
print("Set name cannot be empty")
@@ -200,6 +219,7 @@ function DeleteSet(setName)
print(string.format("Deleted set '%s'", setName))
end
---@return nil
function ListSets()
local sets = {}
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")
end
function AliasSpell(args)
if not args or args == "" then
---@param of string
---@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'")
return
end
local spellID, aliasID = string.match(args, "(%d+)%s+(%d+)")
local ofId = tonumber(of)
local toId = tonumber(to)
spellID = tonumber(spellID)
aliasID = tonumber(aliasID)
if not (spellID and aliasID) then
print(string.format("Could not parse spellID and aliasID from '%s'", args))
if not (ofId and toId) then
print(string.format("Could not parse %s and/or %s to numbers", of, to))
return
end
local aliases = ActionBarSaverDaved.spellAliases[spellID] or {}
local aliases = ActionBarSaverDaved.spellAliases[ofId] or {}
for _, id in ipairs(aliases) do
if id == aliasID then
print(string.format("Spell %d is already aliased by %d", spellID, aliasID))
if id == toId then
print(string.format("Spell %d is already aliased by %d", ofId, toId))
return
end
end
table.insert(ActionBarSaverDaved.spellAliases[spellID], aliasID)
print(string.format("Added %d as an alias for %d", aliasID, spellID))
table.insert(ActionBarSaverDaved.spellAliases[ofId], toId)
print(string.format("Added %d as an alias for %d", toId, ofId))
end
function DeleteSpellAliases(spellID)
if not spellID or spellID == "" then
---@param of string
---@return nil
function DeleteSpellAliases(of)
if not of then
print("Must provide a valid spellID")
return
end
spellID = tonumber(spellID)
local ofId = tonumber(of)
if not ActionBarSaverDaved.spellAliases[spellID] then
print(string.format("No aliases to remove for spell with ID %d", spellID))
if not ofId then
print(string.format("Could not parse spellID from '%s'", of))
return
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
---@return nil
function ListAliases()
local aliases = ActionBarSaverDaved.spellAliases
if Dict.isEmpty(aliases) then
print("No aliases found")
return
for spellID, spellAliases in pairs(ActionBarSaverDaved.spellAliases) do
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(spellAliases, ", ")))
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
local importingSet = nil
@@ -353,6 +344,8 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
end
end)
---@param setName string
---@return nil
function ExportSet(setName)
local set = ActionBarSaverDaved.sets[setName]
if not set then
@@ -387,30 +380,39 @@ function ExportSet(setName)
importExportFrameTextBox:SetFocus()
end
---@param action string
---@return {slot: number, id: number|string, type: string}
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)
local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)")
if not typeChar then
print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName)))
return
print(string.format("Unknown action type '%s'", tostring(typeChar)))
return ret
end
local type = inverseTypeMap[typeChar]
if not type then
print(string.format("Unknown action type '%s' in set '%s'", tostring(typeChar), tostring(setName)))
return
print(string.format("Unknown action type '%s'", tostring(typeChar)))
return ret
end
slot = tonumber(slot)
id = tonumber(id)
if not slot then
print(string.format("Unknown slot '%s' in set '%s'", tostring(slot), tostring(setName)))
return
print(string.format("Unknown slot '%s'", tostring(slot)))
return ret
end
if not id then
print(string.format("Unknown id '%s' in set '%s'", tostring(id), tostring(setName)))
return
print(string.format("Unknown id '%s'", tostring(id)))
return ret
end
return {
@@ -420,6 +422,8 @@ function ParseAction(action)
}
end
---@param importString string
---@return nil
function ImportMacro(importString)
if not importString or importString == "" then
print("Must provide a valid macro string")
@@ -437,14 +441,16 @@ function ImportMacro(importString)
local reconstructed = B64.Decode(content)
local macroIdx = GetMacroIndexByName(name)
if macroIdx == 0 then
macroIdx = CreateMacro(name, "Inv_misc_questionmark", "")
CreateMacro(name, "Inv_misc_questionmark", "")
macroIdx = GetMacroIndexByName(name)
end
EditMacro(macroIdx, name, nil, reconstructed)
print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed))
return
end
---@param setName string
---@param str string
---@return nil
function ImportSet(setName, str)
if not setName or setName == "" then
print("Must provide a valid set name")
@@ -471,12 +477,12 @@ function ImportSet(setName, str)
} end
end
-- /dump ActionBarSaverDaved.sets["havoc"]
-- /dump ActionBarSaverDaved.sets["havoc2"]
ActionBarSaverDaved.sets[setName] = set
print(string.format("Imported set '%s'", setName))
end
---@param setName string
---@return nil
function ImportSetDialogue(setName)
if not setName or setName == "" then
print("Must provide a valid set name")
@@ -488,6 +494,7 @@ function ImportSetDialogue(setName)
importExportFrameTextBox:SetFocus()
end
---@return nil
function PrintUsage()
print("ABS Slash commands")
print("/abs save <set> - Saves your current action bar setup under the given <set>")

View File

@@ -224,19 +224,12 @@ SlashCmdList["KBS"] = function(argv)
local args = { strsplit(" ", argv) }
local cmd = args[1]
if cmd == "save" then
SaveSet(args[2])
elseif cmd == "restore" then
RestoreSet(args[2])
elseif cmd == "delete" then
DeleteSet(args[2])
elseif cmd == "list" then
ListSets()
elseif cmd == "export" then
ExportSet(args[2])
elseif cmd == "import" then
ImportSetDialogue(args[2])
else
PrintUsage()
end
if cmd == "save" then SaveSet(args[2]) end
if cmd == "restore" then RestoreSet(args[2]) end
if cmd == "delete" then DeleteSet(args[2]) end
if cmd == "list" then ListSets() end
if cmd == "export" then ExportSet(args[2]) end
if cmd == "import" then ImportSetDialogue(args[2]) end
if cmd == "" or not cmd then PrintUsage() end
end

View File

@@ -7,6 +7,7 @@ frame:SetScript("OnEvent", function(self, event, addon)
---@class ActionBarSaverDaved
---@field spellAliases table<number, number[]>
---@field sets table<string, table<number, {type: string, id: number|string}>>
ActionBarSaverDaved = ActionBarSaverDaved or {}
ActionBarSaverDaved.spellAliases = ActionBarSaverDaved.spellAliases or {}
ActionBarSaverDaved.sets = ActionBarSaverDaved.sets or {}