Update libs

This commit is contained in:
robin 2021-05-01 13:46:52 +02:00
parent ff9d9efde5
commit ccc1969e57
4 changed files with 31 additions and 44 deletions

View File

@ -1,4 +1,4 @@
local lib = LibStub:NewLibrary("zzAddOn", 5)
local lib = LibStub:NewLibrary("zzAddOn", 7)
if not lib then return end
local config = LibStub:GetLibrary("zzConfig")
lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
@ -8,7 +8,6 @@ local function errormsg(err)
print(format("|cffff0000Error:|r %s",err))
end
local mixins = {'NewAddOn', 'GetAddOn', 'AddChild', 'HasChild', 'IsChild', 'HasParent', 'GetParent', 'GetOptions', 'RegisterEvent','UnregisterEvent','IsClassic', 'GetSpecs', 'Fire'}
local events = lib['events']
function lib:Fire(...)
lib['callbacks']:Fire(...)
end
@ -44,7 +43,6 @@ local function joinTables(tab1, tab2, prefix)
end
end
function lib:AddChild(child)
local childName = child['specs']['name']
child['parent'] = self
self['children'] = self['children'] or {}
self['children'][#self['children'] + 1] = child
@ -55,7 +53,6 @@ end
function lib:RegisterEvent(event, globalfunc)
if(type(event) == 'table') then
for k, v in pairs(event) do
-- print("[zza] Registertab CB", type(ev),ev)
local ev = k
local func = v
if(type(v) == 'string') then
@ -68,7 +65,6 @@ function lib:RegisterEvent(event, globalfunc)
self:RegisterEvent(ev, func)
end
elseif(type(event) == 'string') then
-- print("[zza] Register CB", type(event),event)
if(not lib['events']:IsEventRegistered(event)) then
lib['events']:RegisterEvent(event)
end
@ -79,13 +75,12 @@ function lib:RegisterEvent(event, globalfunc)
end
function lib:UnregisterEvent(event)
if(type(event) == 'table') then
for key, ev in pairs(event) do
for _, ev in pairs(event) do
self:UnregisterEvent(ev)
end
else
lib['UnregisterCallback'](self, event)
end
-- print('unreg', event)
end
function lib:IsClassic()
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
@ -93,7 +88,7 @@ end
function lib:NewAddOn(addonName, addonTable)
local specs = self['specs']
local childName = specs['name']
if(lib['addons'][childName]) then
--[[ if(lib['addons'][childName]) then
local oldchild = lib['addons'][childName]
local parent = oldchild:GetParent()
if(parent) then
@ -102,7 +97,7 @@ function lib:NewAddOn(addonName, addonTable)
errormsg(format("|%s already loaded", childName))
end
return
end
end ]]
if(type(childName) == 'string') then
self.GetAddOnTable = function() return addonTable end
lib['addons'][childName] = self
@ -131,17 +126,14 @@ for _, target in pairs(lib['addons']) do
end
lib['events']:RegisterEvent('ADDON_LOADED')
local function addLDB(...)
-- print('addLDB', ...)
return LibStub:GetLibrary("zzLDB"):AddLDB(...)
end
local function addConfig(addonName, child, specs)
local at = child:GetAddOnTable()
if(addonName == child['specs']['name']) then
-- print("init options", addonName)
config:InitConfig(child, addonName)
child['options']['args']['profile'] = LibStub("AceDBOptions-3.0"):GetOptionsTable(at['db'])
else
-- print('add child options', specs['name'], addonName)
config:AddConfig(child, addonName)
end
if(type(specs['cfgReset']) == 'function') then
@ -152,17 +144,13 @@ end
local function SetupSpecs(addonName, child)
local specs = child['specs']
if(specs and specs['sv'] and not child['db']) then
-- print('dbname',type(specs['sv']),type(specs['sv']) == 'boolean' and addonName or specs['sv'])
local dbname = format('%sDB', type(specs['sv']) == 'boolean' and addonName or specs['sv'])
local at = child:GetAddOnTable()
at['db'] = LibStub("AceDB-3.0"):New(dbname, type(specs['defaults']) == 'table' and specs['defaults'] or {}, 'Default')
-- print('setup parent ldb')
if(specs['ldb']) then
local ldbobj = addLDB(specs['name'], specs['ldb'], at['db'])
-- print(' result parent ldb', specs['name'])
addLDB(specs['name'], specs['ldb'], at['db'])
end
if(specs['cfg']) then
-- print(' spec parent addcfg', addonName, specs['name'])
addConfig(addonName, child, specs)
end
if(child:HasChild()) then
@ -170,13 +158,10 @@ local function SetupSpecs(addonName, child)
local child = child['children'][i]
local childSpecs = child['specs']
-- print("Add child", childSpecs['name'])
if(childSpecs['ldb']) then
-- print(" Add ldb", childSpecs['name'])
local ldbobj = addLDB(childSpecs['name'], childSpecs['ldb'], at['db'])
addLDB(childSpecs['name'], childSpecs['ldb'], at['db'])
end
if(childSpecs['cfg']) then
-- print(' spec child addcfg', addonName, childSpecs['name'])
addConfig(addonName, child, childSpecs)
end
end
@ -185,7 +170,6 @@ local function SetupSpecs(addonName, child)
end
lib['events']:SetScript("OnEvent", function(self, event, ...)
-- print("[zza]", self, event, ...)
local addonName = ...
local child = lib['addons'][addonName]
if(child) then
@ -193,6 +177,5 @@ lib['events']:SetScript("OnEvent", function(self, event, ...)
SetupSpecs(addonName, child)
end
end
-- print("[zza] Fire", event, ...)
lib['callbacks']:Fire(event, self, event, ...)
end)

View File

@ -1,6 +1,5 @@
local lib = LibStub:NewLibrary("zzConfig", 3)
local lib = LibStub:NewLibrary("zzConfig", 6)
if not lib then return end
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
local mixins = {'AddConfigMenu', 'AddConfigEntry', 'InitConfig', 'GetDefaultHandler'}
lib['configs'] = lib['configs'] or {}
@ -15,7 +14,7 @@ local function getDB(objname)
end
return db
else
print("noicon", objname)
-- print("noicon", objname)
end
end
return {}
@ -137,7 +136,7 @@ function lib:AddConfigMenu(options, parentName, order, handler, more)
['name'] = parentName,
['type'] = 'group',
['handler'] = handler or self['handler'],
['childGroups'] =' tab',
['childGroups'] = 'tab',
['order'] = order or 1,
['args'] = {}
}
@ -149,8 +148,14 @@ function lib:AddConfigMenu(options, parentName, order, handler, more)
options['args'][parentName] = menu
return options['args'][parentName]
end
lib.AddedToBlizz = lib.AddedToBlizz or {}
local function addToBlizz(pName, cName)
if(not lib['AddedToBlizz'][pName]) then
lib['AddedToBlizz'][pName] = true
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(pName, pName, cName)
end
end
function lib:InitConfig(child, parentName, gp, sp)
local pp = child['specs']['name'] == parentName
child['options'] = {
['name'] = parentName,
['type'] = 'group',
@ -164,7 +169,7 @@ function lib:InitConfig(child, parentName, gp, sp)
local par = self:AddConfigMenu(options, parentName)
self:AddLDBIconOptions(par, 'minimap')
LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(parentName, parentName, child['parentName'])
addToBlizz(parentName, child['parentName'])
return options
end
function lib:AddConfig(child, parentName, gp, sp)
@ -181,7 +186,7 @@ function lib:AddConfig(child, parentName, gp, sp)
local par = self:AddConfigMenu(child['options'], specs['name'])
self:AddLDBIconOptions(par, 'minimap')
LibStub("AceConfig-3.0"):RegisterOptionsTable(specs['name'], child['options'])
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(specs['name'], specs['name'], parentName)
addToBlizz(specs['name'], parentName)
return child['options']
end
function lib:Embed(target)

View File

@ -1,4 +1,4 @@
local lib = LibStub:NewLibrary("zzHelper", 2)
local lib = LibStub:NewLibrary("zzHelper", 3)
if not lib then return end
lib['targets'] = lib['targets'] or {}
local mixins = {'colorize', 'round', 'sortArray', 'IsTwink', 'classcolor', 'MoneyString', 'MoneyStringSetString', 'MoneyStringSetSize'}
@ -95,13 +95,13 @@ end
*** Arrayfunctions ***
]]
function lib:sortArray(tmp,dir)
function lib:sortArray(tmp, dir)
local newtmp = {}
local n = 1
local cnt = 0
local maximum = 0
local first
for k,v in pairs(tmp) do
for k, v in pairs(tmp) do
cnt = cnt + 1
if(v > maximum) then
maximum = v + 1
@ -109,15 +109,15 @@ function lib:sortArray(tmp,dir)
first = first or k
end
while(cnt > 0) do
local mx, mn = dir and maximum or 0,first
for k,v in pairs(tmp) do
local mx, mn = dir and maximum or 0, first
for k, v in pairs(tmp) do
if(dir) then
if(tonumber(v)<=tonumber(mx)) then
if(tonumber(v) <= tonumber(mx)) then
mx = v
mn = k
end
else
if(tonumber(v)>=tonumber(mx)) then
if(tonumber(v) >= tonumber(mx)) then
mx = v
mn = k
end
@ -126,7 +126,7 @@ function lib:sortArray(tmp,dir)
newtmp[n] = mn
tmp[mn] = nil
cnt = 0
for k,v in pairs(tmp) do
for _ in pairs(tmp) do
cnt = cnt + 1
end
n = n + 1
@ -146,8 +146,8 @@ function lib:IsTwink(name)
local realm = GetRealmName()
local _
if(db['sv']['profileKeys']) then
for k,v in pairs(db['sv']['profileKeys']) do
local n,m = strsplit(" - ",k,2)
for k, _ in pairs(db['sv']['profileKeys']) do
local n, m = strsplit(" - ", k, 2)
_,m = strsplit(" ",m,2)
if(n) then
if(n == name and m == realm) then

View File

@ -1,17 +1,16 @@
local lib, oldminor = LibStub:NewLibrary("zzLDB", 4)
local lib = LibStub:NewLibrary("zzLDB", 4)
if not lib then return end
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
oldminor = oldminor or 0
local mixins = {'AddLDB', 'GetLDB', 'DefaultOnClick', 'DefaultOnText'}
local defaults = {
['hide'] = false,
}
lib['ldbs'] = lib['ldbs'] or {}
local function proto_OnClick(self, button)
print("onclick required", self, button)
-- print("onclick required", self, button)
end
function lib:DefaultOnClick(dummy, button, addon, childName)
function lib:DefaultOnClick(_, button, addon, childName)
if(IsShiftKeyDown() and button == "LeftButton") then
local sb = addon['db']['global']['ldbicons']
sb[childName]['hide'] = not sb[childName]['hide']