Files
ShagaTweaks/main.lua
T

136 lines
4.4 KiB
Lua

local _G = _G or getfenv(0)
SLASH_RELOAD1 = '/rl'
function SlashCmdList.RELOAD(msg, editbox) ReloadUI() end
message = function(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00" .. ( msg or "nil" ))
end
print = message
error = function(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000".. (msg or "nil" ))
end
seterrorhandler(error)
ShaguTweaks = CreateFrame("Frame")
ShaguTweaks.mods = {}
ShaguTweaks.overwrites = {}
-- flag official modules
local official = true
-- load translation tables
ShaguTweaks.L = (ShaguTweaks_locale[GetLocale()] or ShaguTweaks_locale["enUS"])
ShaguTweaks.T = (ShaguTweaks_translation[GetLocale()] or ShaguTweaks_translation["enUS"])
-- use table index key as translation fallback
ShaguTweaks.T = setmetatable(ShaguTweaks.T, { __index = function(tab,key)
local value = tostring(key)
rawset(tab, key, value)
return value
end})
ShaguTweaks:RegisterEvent("ADDON_LOADED")
ShaguTweaks:RegisterEvent("VARIABLES_LOADED")
ShaguTweaks:SetScript("OnEvent", function()
-- flag all external modules as unofficial
if event == "ADDON_LOADED" then
ShaguTweaks.provider = nil
official = false
return
end
-- load current expansion
local expansion = ShaguTweaks:GetExpansion()
-- initialize empty config
if not ShaguTweaks_config then ShaguTweaks_config = {} end
-- read all registered mods
for title, mod in pairs(ShaguTweaks.mods) do
-- write initial default config
if not ShaguTweaks_config[title] then
ShaguTweaks_config[title] = mod.enabled and 1 or 0
end
-- load possible overwrites
if mod.config then
for name, value in pairs(mod.config) do
ShaguTweaks.overwrites[name] = value
end
end
-- apply custom overwrites
if mod.config and ShaguTweaks_config.overwrites then
for name, value in pairs(ShaguTweaks_config.overwrites) do
ShaguTweaks.overwrites[name] = value
mod.config[name] = value
end
end
-- load enabled mods
if mod.expansions[expansion] and ShaguTweaks_config[title] == 1 then
mod:enable()
end
end
end)
ShaguTweaks.register = function(self, mod)
-- add fallback captions and providers to categories
local provider = ShaguTweaks.provider or "|cffFF5555Mods:|r"
local category = mod.category or ShaguTweaks.T["General"]
mod.category = official and category or provider .. " " .. category
-- register mod
ShaguTweaks.mods[mod.title] = mod
return ShaguTweaks.mods[mod.title]
end
local GetConfigValue = function(conf)
if type(conf) == "table" and conf.r and conf.g and conf.b then
return string.format("%s,%s,%s,%s", conf.r, conf.g, conf.b, (conf.a or 1))
elseif type(conf) == "number" or type(conf) == "string" then
return conf
end
return ""
end
SLASH_STWEAKS1, SLASH_STWEAKS2, SLASH_STWEAKS3 = "/st", "/stweaks", "/shagutweaks"
SlashCmdList["STWEAKS"] = function(msg)
local cmd = { ShaguTweaks.strsplit(" ", msg) }
if cmd[1] == "reset" then
ShaguTweaks_config.overwrites = {}
ReloadUI()
elseif cmd[1] and cmd[2] then
local value
local rgba, _, r, g, b, a = string.find(cmd[2], "(.+),(.+),(.+),(.+)")
local index = cmd[1]
-- detect best value format
value = rgba and { r = r, g = g, b = b, a = a }
value = value or tonumber(cmd[2]) and tonumber(cmd[2])
value = value or cmd[2]
-- validate input and set config
if not ShaguTweaks.overwrites[index] then
local text = "|cffff5555Error:|r Overwrite |cffffcc00%s|r does not exists.|r"
DEFAULT_CHAT_FRAME:AddMessage(string.format(text, index), 1, 1, 1, 1)
elseif type(ShaguTweaks.overwrites[index]) ~= type(value) then
local text = "|cffff5555Error:|r Overwrite |cffffcc00%s|r requires to be type: |cffffcc00%s|r"
DEFAULT_CHAT_FRAME:AddMessage(string.format(text, index, type(ShaguTweaks.overwrites[index])), 1, 1, 1, 1)
else
ShaguTweaks_config.overwrites[index] = value
local text = "Overwrite |cffffcc00%s|r is now set to: |cffffcc00%s|r"
DEFAULT_CHAT_FRAME:AddMessage(string.format(text, index, cmd[2]), 1, 1, 1, 1)
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cffffcc00Shagu|rTweaks overwrites:", 1, 1, 1, 1)
for name, value in ShaguTweaks.spairs(ShaguTweaks.overwrites) do
DEFAULT_CHAT_FRAME:AddMessage(" |cffaaaaaa/st|r " .. name .. " |cffffcc00" .. GetConfigValue(value), 1, 1, 1, 1)
end
DEFAULT_CHAT_FRAME:AddMessage(" |cffaaaaaa/st|r reset", 1, 1, 1, 1)
end
end