Update libs
This commit is contained in:
parent
faff81f7ae
commit
76b0683572
|
@ -1,4 +1,4 @@
|
||||||
local lib = LibStub:NewLibrary("zzAddOn", 5)
|
local lib = LibStub:NewLibrary("zzAddOn", 7)
|
||||||
if not lib then return end
|
if not lib then return end
|
||||||
local config = LibStub:GetLibrary("zzConfig")
|
local config = LibStub:GetLibrary("zzConfig")
|
||||||
lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
|
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))
|
print(format("|cffff0000Error:|r %s",err))
|
||||||
end
|
end
|
||||||
local mixins = {'NewAddOn', 'GetAddOn', 'AddChild', 'HasChild', 'IsChild', 'HasParent', 'GetParent', 'GetOptions', 'RegisterEvent','UnregisterEvent','IsClassic', 'GetSpecs', 'Fire'}
|
local mixins = {'NewAddOn', 'GetAddOn', 'AddChild', 'HasChild', 'IsChild', 'HasParent', 'GetParent', 'GetOptions', 'RegisterEvent','UnregisterEvent','IsClassic', 'GetSpecs', 'Fire'}
|
||||||
local events = lib['events']
|
|
||||||
function lib:Fire(...)
|
function lib:Fire(...)
|
||||||
lib['callbacks']:Fire(...)
|
lib['callbacks']:Fire(...)
|
||||||
end
|
end
|
||||||
|
@ -44,7 +43,6 @@ local function joinTables(tab1, tab2, prefix)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function lib:AddChild(child)
|
function lib:AddChild(child)
|
||||||
local childName = child['specs']['name']
|
|
||||||
child['parent'] = self
|
child['parent'] = self
|
||||||
self['children'] = self['children'] or {}
|
self['children'] = self['children'] or {}
|
||||||
self['children'][#self['children'] + 1] = child
|
self['children'][#self['children'] + 1] = child
|
||||||
|
@ -55,7 +53,6 @@ end
|
||||||
function lib:RegisterEvent(event, globalfunc)
|
function lib:RegisterEvent(event, globalfunc)
|
||||||
if(type(event) == 'table') then
|
if(type(event) == 'table') then
|
||||||
for k, v in pairs(event) do
|
for k, v in pairs(event) do
|
||||||
-- print("[zza] Registertab CB", type(ev),ev)
|
|
||||||
local ev = k
|
local ev = k
|
||||||
local func = v
|
local func = v
|
||||||
if(type(v) == 'string') then
|
if(type(v) == 'string') then
|
||||||
|
@ -68,7 +65,6 @@ function lib:RegisterEvent(event, globalfunc)
|
||||||
self:RegisterEvent(ev, func)
|
self:RegisterEvent(ev, func)
|
||||||
end
|
end
|
||||||
elseif(type(event) == 'string') then
|
elseif(type(event) == 'string') then
|
||||||
-- print("[zza] Register CB", type(event),event)
|
|
||||||
if(not lib['events']:IsEventRegistered(event)) then
|
if(not lib['events']:IsEventRegistered(event)) then
|
||||||
lib['events']:RegisterEvent(event)
|
lib['events']:RegisterEvent(event)
|
||||||
end
|
end
|
||||||
|
@ -79,13 +75,12 @@ function lib:RegisterEvent(event, globalfunc)
|
||||||
end
|
end
|
||||||
function lib:UnregisterEvent(event)
|
function lib:UnregisterEvent(event)
|
||||||
if(type(event) == 'table') then
|
if(type(event) == 'table') then
|
||||||
for key, ev in pairs(event) do
|
for _, ev in pairs(event) do
|
||||||
self:UnregisterEvent(ev)
|
self:UnregisterEvent(ev)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
lib['UnregisterCallback'](self, event)
|
lib['UnregisterCallback'](self, event)
|
||||||
end
|
end
|
||||||
-- print('unreg', event)
|
|
||||||
end
|
end
|
||||||
function lib:IsClassic()
|
function lib:IsClassic()
|
||||||
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
|
return WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
|
||||||
|
@ -93,7 +88,7 @@ end
|
||||||
function lib:NewAddOn(addonName, addonTable)
|
function lib:NewAddOn(addonName, addonTable)
|
||||||
local specs = self['specs']
|
local specs = self['specs']
|
||||||
local childName = specs['name']
|
local childName = specs['name']
|
||||||
if(lib['addons'][childName]) then
|
--[[ if(lib['addons'][childName]) then
|
||||||
local oldchild = lib['addons'][childName]
|
local oldchild = lib['addons'][childName]
|
||||||
local parent = oldchild:GetParent()
|
local parent = oldchild:GetParent()
|
||||||
if(parent) then
|
if(parent) then
|
||||||
|
@ -102,7 +97,7 @@ function lib:NewAddOn(addonName, addonTable)
|
||||||
errormsg(format("|%s already loaded", childName))
|
errormsg(format("|%s already loaded", childName))
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end ]]
|
||||||
if(type(childName) == 'string') then
|
if(type(childName) == 'string') then
|
||||||
self.GetAddOnTable = function() return addonTable end
|
self.GetAddOnTable = function() return addonTable end
|
||||||
lib['addons'][childName] = self
|
lib['addons'][childName] = self
|
||||||
|
@ -131,17 +126,14 @@ for _, target in pairs(lib['addons']) do
|
||||||
end
|
end
|
||||||
lib['events']:RegisterEvent('ADDON_LOADED')
|
lib['events']:RegisterEvent('ADDON_LOADED')
|
||||||
local function addLDB(...)
|
local function addLDB(...)
|
||||||
-- print('addLDB', ...)
|
|
||||||
return LibStub:GetLibrary("zzLDB"):AddLDB(...)
|
return LibStub:GetLibrary("zzLDB"):AddLDB(...)
|
||||||
end
|
end
|
||||||
local function addConfig(addonName, child, specs)
|
local function addConfig(addonName, child, specs)
|
||||||
local at = child:GetAddOnTable()
|
local at = child:GetAddOnTable()
|
||||||
if(addonName == child['specs']['name']) then
|
if(addonName == child['specs']['name']) then
|
||||||
-- print("init options", addonName)
|
|
||||||
config:InitConfig(child, addonName)
|
config:InitConfig(child, addonName)
|
||||||
child['options']['args']['profile'] = LibStub("AceDBOptions-3.0"):GetOptionsTable(at['db'])
|
child['options']['args']['profile'] = LibStub("AceDBOptions-3.0"):GetOptionsTable(at['db'])
|
||||||
else
|
else
|
||||||
-- print('add child options', specs['name'], addonName)
|
|
||||||
config:AddConfig(child, addonName)
|
config:AddConfig(child, addonName)
|
||||||
end
|
end
|
||||||
if(type(specs['cfgReset']) == 'function') then
|
if(type(specs['cfgReset']) == 'function') then
|
||||||
|
@ -152,17 +144,13 @@ end
|
||||||
local function SetupSpecs(addonName, child)
|
local function SetupSpecs(addonName, child)
|
||||||
local specs = child['specs']
|
local specs = child['specs']
|
||||||
if(specs and specs['sv'] and not child['db']) then
|
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 dbname = format('%sDB', type(specs['sv']) == 'boolean' and addonName or specs['sv'])
|
||||||
local at = child:GetAddOnTable()
|
local at = child:GetAddOnTable()
|
||||||
at['db'] = LibStub("AceDB-3.0"):New(dbname, type(specs['defaults']) == 'table' and specs['defaults'] or {}, 'Default')
|
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
|
if(specs['ldb']) then
|
||||||
local ldbobj = addLDB(specs['name'], specs['ldb'], at['db'])
|
addLDB(specs['name'], specs['ldb'], at['db'])
|
||||||
-- print(' result parent ldb', specs['name'])
|
|
||||||
end
|
end
|
||||||
if(specs['cfg']) then
|
if(specs['cfg']) then
|
||||||
-- print(' spec parent addcfg', addonName, specs['name'])
|
|
||||||
addConfig(addonName, child, specs)
|
addConfig(addonName, child, specs)
|
||||||
end
|
end
|
||||||
if(child:HasChild()) then
|
if(child:HasChild()) then
|
||||||
|
@ -170,13 +158,10 @@ local function SetupSpecs(addonName, child)
|
||||||
local child = child['children'][i]
|
local child = child['children'][i]
|
||||||
|
|
||||||
local childSpecs = child['specs']
|
local childSpecs = child['specs']
|
||||||
-- print("Add child", childSpecs['name'])
|
|
||||||
if(childSpecs['ldb']) then
|
if(childSpecs['ldb']) then
|
||||||
-- print(" Add ldb", childSpecs['name'])
|
addLDB(childSpecs['name'], childSpecs['ldb'], at['db'])
|
||||||
local ldbobj = addLDB(childSpecs['name'], childSpecs['ldb'], at['db'])
|
|
||||||
end
|
end
|
||||||
if(childSpecs['cfg']) then
|
if(childSpecs['cfg']) then
|
||||||
-- print(' spec child addcfg', addonName, childSpecs['name'])
|
|
||||||
addConfig(addonName, child, childSpecs)
|
addConfig(addonName, child, childSpecs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -185,7 +170,6 @@ local function SetupSpecs(addonName, child)
|
||||||
end
|
end
|
||||||
|
|
||||||
lib['events']:SetScript("OnEvent", function(self, event, ...)
|
lib['events']:SetScript("OnEvent", function(self, event, ...)
|
||||||
-- print("[zza]", self, event, ...)
|
|
||||||
local addonName = ...
|
local addonName = ...
|
||||||
local child = lib['addons'][addonName]
|
local child = lib['addons'][addonName]
|
||||||
if(child) then
|
if(child) then
|
||||||
|
@ -193,6 +177,5 @@ lib['events']:SetScript("OnEvent", function(self, event, ...)
|
||||||
SetupSpecs(addonName, child)
|
SetupSpecs(addonName, child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- print("[zza] Fire", event, ...)
|
|
||||||
lib['callbacks']:Fire(event, self, event, ...)
|
lib['callbacks']:Fire(event, self, event, ...)
|
||||||
end)
|
end)
|
|
@ -1,6 +1,5 @@
|
||||||
local lib = LibStub:NewLibrary("zzConfig", 3)
|
local lib = LibStub:NewLibrary("zzConfig", 6)
|
||||||
if not lib then return end
|
if not lib then return end
|
||||||
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
|
|
||||||
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
|
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
|
||||||
local mixins = {'AddConfigMenu', 'AddConfigEntry', 'InitConfig', 'GetDefaultHandler'}
|
local mixins = {'AddConfigMenu', 'AddConfigEntry', 'InitConfig', 'GetDefaultHandler'}
|
||||||
lib['configs'] = lib['configs'] or {}
|
lib['configs'] = lib['configs'] or {}
|
||||||
|
@ -15,7 +14,7 @@ local function getDB(objname)
|
||||||
end
|
end
|
||||||
return db
|
return db
|
||||||
else
|
else
|
||||||
print("noicon", objname)
|
-- print("noicon", objname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return {}
|
return {}
|
||||||
|
@ -137,7 +136,7 @@ function lib:AddConfigMenu(options, parentName, order, handler, more)
|
||||||
['name'] = parentName,
|
['name'] = parentName,
|
||||||
['type'] = 'group',
|
['type'] = 'group',
|
||||||
['handler'] = handler or self['handler'],
|
['handler'] = handler or self['handler'],
|
||||||
['childGroups'] =' tab',
|
['childGroups'] = 'tab',
|
||||||
['order'] = order or 1,
|
['order'] = order or 1,
|
||||||
['args'] = {}
|
['args'] = {}
|
||||||
}
|
}
|
||||||
|
@ -149,8 +148,14 @@ function lib:AddConfigMenu(options, parentName, order, handler, more)
|
||||||
options['args'][parentName] = menu
|
options['args'][parentName] = menu
|
||||||
return options['args'][parentName]
|
return options['args'][parentName]
|
||||||
end
|
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)
|
function lib:InitConfig(child, parentName, gp, sp)
|
||||||
local pp = child['specs']['name'] == parentName
|
|
||||||
child['options'] = {
|
child['options'] = {
|
||||||
['name'] = parentName,
|
['name'] = parentName,
|
||||||
['type'] = 'group',
|
['type'] = 'group',
|
||||||
|
@ -164,7 +169,7 @@ function lib:InitConfig(child, parentName, gp, sp)
|
||||||
local par = self:AddConfigMenu(options, parentName)
|
local par = self:AddConfigMenu(options, parentName)
|
||||||
self:AddLDBIconOptions(par, 'minimap')
|
self:AddLDBIconOptions(par, 'minimap')
|
||||||
LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, options)
|
LibStub("AceConfig-3.0"):RegisterOptionsTable(parentName, options)
|
||||||
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(parentName, parentName, child['parentName'])
|
addToBlizz(parentName, child['parentName'])
|
||||||
return options
|
return options
|
||||||
end
|
end
|
||||||
function lib:AddConfig(child, parentName, gp, sp)
|
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'])
|
local par = self:AddConfigMenu(child['options'], specs['name'])
|
||||||
self:AddLDBIconOptions(par, 'minimap')
|
self:AddLDBIconOptions(par, 'minimap')
|
||||||
LibStub("AceConfig-3.0"):RegisterOptionsTable(specs['name'], child['options'])
|
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']
|
return child['options']
|
||||||
end
|
end
|
||||||
function lib:Embed(target)
|
function lib:Embed(target)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local lib = LibStub:NewLibrary("zzHelper", 2)
|
local lib = LibStub:NewLibrary("zzHelper", 3)
|
||||||
if not lib then return end
|
if not lib then return end
|
||||||
lib['targets'] = lib['targets'] or {}
|
lib['targets'] = lib['targets'] or {}
|
||||||
local mixins = {'colorize', 'round', 'sortArray', 'IsTwink', 'classcolor', 'MoneyString', 'MoneyStringSetString', 'MoneyStringSetSize'}
|
local mixins = {'colorize', 'round', 'sortArray', 'IsTwink', 'classcolor', 'MoneyString', 'MoneyStringSetString', 'MoneyStringSetSize'}
|
||||||
|
@ -95,13 +95,13 @@ end
|
||||||
*** Arrayfunctions ***
|
*** Arrayfunctions ***
|
||||||
]]
|
]]
|
||||||
|
|
||||||
function lib:sortArray(tmp,dir)
|
function lib:sortArray(tmp, dir)
|
||||||
local newtmp = {}
|
local newtmp = {}
|
||||||
local n = 1
|
local n = 1
|
||||||
local cnt = 0
|
local cnt = 0
|
||||||
local maximum = 0
|
local maximum = 0
|
||||||
local first
|
local first
|
||||||
for k,v in pairs(tmp) do
|
for k, v in pairs(tmp) do
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
if(v > maximum) then
|
if(v > maximum) then
|
||||||
maximum = v + 1
|
maximum = v + 1
|
||||||
|
@ -109,15 +109,15 @@ function lib:sortArray(tmp,dir)
|
||||||
first = first or k
|
first = first or k
|
||||||
end
|
end
|
||||||
while(cnt > 0) do
|
while(cnt > 0) do
|
||||||
local mx, mn = dir and maximum or 0,first
|
local mx, mn = dir and maximum or 0, first
|
||||||
for k,v in pairs(tmp) do
|
for k, v in pairs(tmp) do
|
||||||
if(dir) then
|
if(dir) then
|
||||||
if(tonumber(v)<=tonumber(mx)) then
|
if(tonumber(v) <= tonumber(mx)) then
|
||||||
mx = v
|
mx = v
|
||||||
mn = k
|
mn = k
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if(tonumber(v)>=tonumber(mx)) then
|
if(tonumber(v) >= tonumber(mx)) then
|
||||||
mx = v
|
mx = v
|
||||||
mn = k
|
mn = k
|
||||||
end
|
end
|
||||||
|
@ -126,7 +126,7 @@ function lib:sortArray(tmp,dir)
|
||||||
newtmp[n] = mn
|
newtmp[n] = mn
|
||||||
tmp[mn] = nil
|
tmp[mn] = nil
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for k,v in pairs(tmp) do
|
for _ in pairs(tmp) do
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
end
|
end
|
||||||
n = n + 1
|
n = n + 1
|
||||||
|
@ -146,8 +146,8 @@ function lib:IsTwink(name)
|
||||||
local realm = GetRealmName()
|
local realm = GetRealmName()
|
||||||
local _
|
local _
|
||||||
if(db['sv']['profileKeys']) then
|
if(db['sv']['profileKeys']) then
|
||||||
for k,v in pairs(db['sv']['profileKeys']) do
|
for k, _ in pairs(db['sv']['profileKeys']) do
|
||||||
local n,m = strsplit(" - ",k,2)
|
local n, m = strsplit(" - ", k, 2)
|
||||||
_,m = strsplit(" ",m,2)
|
_,m = strsplit(" ",m,2)
|
||||||
if(n) then
|
if(n) then
|
||||||
if(n == name and m == realm) then
|
if(n == name and m == realm) then
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
local lib, oldminor = LibStub:NewLibrary("zzLDB", 4)
|
local lib = LibStub:NewLibrary("zzLDB", 4)
|
||||||
if not lib then return end
|
if not lib then return end
|
||||||
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
|
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
|
||||||
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
|
local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0")
|
||||||
oldminor = oldminor or 0
|
|
||||||
local mixins = {'AddLDB', 'GetLDB', 'DefaultOnClick', 'DefaultOnText'}
|
local mixins = {'AddLDB', 'GetLDB', 'DefaultOnClick', 'DefaultOnText'}
|
||||||
local defaults = {
|
local defaults = {
|
||||||
['hide'] = false,
|
['hide'] = false,
|
||||||
}
|
}
|
||||||
lib['ldbs'] = lib['ldbs'] or {}
|
lib['ldbs'] = lib['ldbs'] or {}
|
||||||
local function proto_OnClick(self, button)
|
local function proto_OnClick(self, button)
|
||||||
print("onclick required", self, button)
|
-- print("onclick required", self, button)
|
||||||
end
|
end
|
||||||
function lib:DefaultOnClick(dummy, button, addon, childName)
|
function lib:DefaultOnClick(_, button, addon, childName)
|
||||||
if(IsShiftKeyDown() and button == "LeftButton") then
|
if(IsShiftKeyDown() and button == "LeftButton") then
|
||||||
local sb = addon['db']['global']['ldbicons']
|
local sb = addon['db']['global']['ldbicons']
|
||||||
sb[childName]['hide'] = not sb[childName]['hide']
|
sb[childName]['hide'] = not sb[childName]['hide']
|
||||||
|
|
Loading…
Reference in New Issue