Remove unecessary garbage

Are you kidding me? Producing more trash than saving space
This commit is contained in:
2025-01-04 13:51:24 +01:00
parent 19a7052f75
commit 32d426ac38
5 changed files with 46 additions and 142 deletions

View File

@@ -6,7 +6,5 @@
## SavedVariables: ActionBarSaverReloaded
Constants.lua
StringHelpers.lua
TableHelpers.lua
Main.lua
Actions.lua

View File

@@ -31,7 +31,7 @@ local function RestoreActionButton(self, index, actionButton)
if not actionButton then return true, nil end
local aliases = self.db.class.spellAliases[actionButton.id] or {}
local aliases = ActionBarSaverReloaded.spellAliases[actionButton.id] or {}
local ids = Array.insert(aliases, actionButton.id, 1)
for _, id in ipairs(ids) do
@@ -80,8 +80,8 @@ local function AddWarning(warnings, macroName, usages)
end
function SaveSet(setName)
if Str.nullOrEmpty(setName) then
self:Print("Set name cannot be empty")
if not setName or setName == "" then
print("Set name cannot be empty")
return
end
@@ -106,25 +106,25 @@ function SaveSet(setName)
end
end
self.db.class.sets[setName] = set
self:Print(string.format("Saved set '%s'!", setName))
Array.iter(warnings, function(warning) self:Print(warning) end)
ActionBarSaverReloaded.sets[setName] = set
print(string.format("Saved set '%s'!", setName))
Array.iter(warnings, function(warning) print(warning) end)
end
function RestoreSet(setName)
if Str.nullOrEmpty(setName) then
self:Print("Set name cannot be empty")
if not setName or setName == "" then
print("Set name cannot be empty")
return
end
local set = self.db.class.sets[setName]
local set = ActionBarSaverReloaded.sets[setName]
if not set then
self:Print(string.format("No set with the name '%s' exists", setName))
print(string.format("No set with the name '%s' exists", setName))
return
end
if InCombatLockdown() then
self:Print("Cannot restore sets while in combat")
print("Cannot restore sets while in combat")
return
end
@@ -147,37 +147,37 @@ function RestoreSet(setName)
end
end
self:Print(string.format("Restored set '%s'", setName))
Array.iter(messages, function(warning) self:Print(warning) end)
print(string.format("Restored set '%s'", setName))
Array.iter(messages, function(warning) print(warning) end)
end
function DeleteSet(setName)
if Str.nullOrEmpty(setName) then
self:Print("Set name cannot be empty")
if not setName or setName == "" then
print("Set name cannot be empty")
return
end
if not self.db.class.sets[setName] then
self:Print(string.format("No set with the name '%s' exists", setName))
if not ActionBarSaverReloaded.sets[setName] then
print(string.format("No set with the name '%s' exists", setName))
return
end
self.db.class.sets[setName] = nil
ActionBarSaverReloaded.sets[setName] = nil
self:Print(string.format("Deleted set '%s'", setName))
print(string.format("Deleted set '%s'", setName))
end
function ListSets()
local sets = Dict.keysAsArray(self.db.class.sets)
local sets = Dict.keysAsArray(ActionBarSaverReloaded.sets)
table.sort(sets)
local setsStr = table.concat(sets, ", ")
self:Print(not Str.nullOrEmpty(setsStr) and setsStr or "No sets found")
print(not Str.nullOrEmpty(setsStr) and setsStr or "No sets found")
end
function AliasSpell(args)
if Str.nullOrEmpty(args) then
self:Print("Must provide args in the format 'spellID aliasID'")
if not args or args == "" then
print("Must provide args in the format 'spellID aliasID'")
return
end
local spellID, aliasID = string.match(args, "(%d+)%s+(%d+)")
@@ -186,63 +186,63 @@ function AliasSpell(args)
aliasID = tonumber(aliasID)
if not (spellID and aliasID) then
self:Print(string.format("Could not parse spellID and aliasID from '%s'", args))
print(string.format("Could not parse spellID and aliasID from '%s'", args))
return
end
local aliases = self.db.class.spellAliases[spellID] or {}
local aliases = ActionBarSaverReloaded.spellAliases[spellID] or {}
if Array.contains(aliases, aliasID) then
self:Print(string.format("Spell %d is already aliased by %d", spellID, aliasID))
print(string.format("Spell %d is already aliased by %d", spellID, aliasID))
return
end
table.insert(aliases, aliasID)
self.db.class.spellAliases[spellID] = aliases
ActionBarSaverReloaded.spellAliases[spellID] = aliases
self:Print(string.format("Added %d as an alias for %d", aliasID, spellID))
print(string.format("Added %d as an alias for %d", aliasID, spellID))
end
function DeleteSpellAliases(spellID)
if Str.nullOrEmpty(spellID) then
self:Print("Must provide a valid spellID")
if not spellID or spellID == "" then
print("Must provide a valid spellID")
return
end
spellID = tonumber(spellID)
if not self.db.class.spellAliases[spellID] then
self:Print(string.format("No aliases to remove for spell with ID %d", spellID))
if not ActionBarSaverReloaded.spellAliases[spellID] then
print(string.format("No aliases to remove for spell with ID %d", spellID))
return
end
self.db.class.spellAliases[spellID] = nil
ActionBarSaverReloaded.spellAliases[spellID] = nil
self:Print(string.format("Removed all aliases for spell with ID %d", spellID))
print(string.format("Removed all aliases for spell with ID %d", spellID))
end
function ListAliases()
local aliases = self.db.class.spellAliases
local aliases = ActionBarSaverReloaded.spellAliases
if Dict.isEmpty(aliases) then
self:Print("No aliases found")
print("No aliases found")
return
end
Dict.iter(self.db.class.spellAliases, function(spellID, aliases)
self:Print(string.format("Spell %d is aliased by: %s", spellID, table.concat(aliases, ", ")))
Dict.iter(ActionBarSaverReloaded.spellAliases, function(spellID, aliases)
print(string.format("Spell %d is aliased by: %s", spellID, table.concat(aliases, ", ")))
end)
end
function PrintUsage()
self:Print("ABS Slash commands")
self:Print("/abs save <set> - Saves your current action bar setup under the given <set>")
self:Print("/abs restore <set> - Restores the saved <set>")
self:Print("/abs delete <set> - Deletes the saved <set>")
self:Print("/abs list - Lists all saved sets")
self:Print("/abs alias <spellID> <aliasID> - Adds an alias with <aliasID> to <spellID>")
self:Print("/abs unalias <spellID> - Removes all aliases associated with <spellID>")
self:Print("/abs aliases - List all spell aliases")
print("ABS Slash commands")
print("/abs save <set> - Saves your current action bar setup under the given <set>")
print("/abs restore <set> - Restores the saved <set>")
print("/abs delete <set> - Deletes the saved <set>")
print("/abs list - Lists all saved sets")
print("/abs alias <spellID> <aliasID> - Adds an alias with <aliasID> to <spellID>")
print("/abs unalias <spellID> - Removes all aliases associated with <spellID>")
print("/abs aliases - List all spell aliases")
end
SlashCmdList["ABS"] = function(argv)

View File

@@ -1,9 +0,0 @@
Str = {}
function Str.toLower(s) return string.lower(s or "") end
function Str.nullOrEmpty(s) return not s or s == "" end
function Str.split(s, delimiter, max)
---@diagnostic disable-next-line: undefined-field
return string.split(delimiter, s, max)
end

View File

@@ -1,84 +0,0 @@
Array = {}
Dict = {}
function Array.iter(arr, fn)
for _,v in ipairs(arr) do
fn(v)
end
end
function Array.map(arr, fn)
local t = {}
for _,v in ipairs(arr) do
table.insert(t, fn(v))
end
return t
end
function Array.mapRange(start, stop, fn)
local arr = {}
for i = start, stop do
arr[i] = fn(i)
end
return arr
end
function Array.iterRange(start, stop, fn)
for i = start, stop do
fn(i)
end
end
function Array.contains(arr, value)
for _,v in ipairs(arr) do
if v == value then return true end
end
return false
end
function Array.insert(arr, value, index)
local t = {}
for _, v in ipairs(arr) do
table.insert(t, v)
end
table.insert(t, index, value)
return t
end
function Dict.iter(t, fn)
for k,v in pairs(t) do
fn(k,v)
end
end
function Dict.map(t, fn)
local nt = {}
for k,v in pairs(t) do
nt[k] = fn(k,v)
end
return nt
end
function Dict.keysAsArray(t)
local nt = {}
for k,_ in pairs(t) do
table.insert(nt, k)
end
return nt
end
function Dict.isEmpty(t)
return next(t) == nil
end

View File

@@ -1,3 +1,2 @@
ADDON_NAME = "ActionBarSaverReloaded"
MAX_MACROS = 138
MAX_ACTION_BUTTONS = 132