Mercurial > wow > buffalo2
diff Veneer.lua @ 54:ed74c5cabe98
Core
- updated comment notes
Objectives
- force hide blocks when their tracker is hidden
Clock
- convert clock into its own module
- display zone coordinates alongside time
author | Nenue |
---|---|
date | Wed, 01 Jun 2016 20:48:14 -0400 |
parents | 16465f3fd919 |
children | dd9b5f59632c |
line wrap: on
line diff
--- a/Veneer.lua Fri Apr 29 17:06:48 2016 -0400 +++ b/Veneer.lua Wed Jun 01 20:48:14 2016 -0400 @@ -1,43 +1,53 @@ ---- Modulizer framework +-------------------------------------------- +-- Veneer +-- Core +-- author: Krakyn +-- @project-revision@ @project-hash@ +-- @file-revision@ @file-hash@ +-- Created: 4/27/2016 1:02 AM +-------------------------------------------- +--- Implemented methods -- OnInitialize -- OnUpdate --- OnEnable -- run when GetSpecialization() returns true +-- OnEnable -- runs as soon as GetSpecialization() returns valid data local ADDON, A = ... -Veneer = Veneer or CreateFrame('Frame', 'Veneer', UIParent) -local B = Veneer local wipe, min, max, random, tinsert, tremove = table.wipe, math.min, math.max, math.random, table.insert, table.remove local pairs, ipairs, select, unpack, _G = pairs, ipairs, select, unpack, _G local type, tostring, format = type, tostring, string.format -A.frame = B ---- Cache tables -local initOnced -local modules = {} -local queuedModules = {} -local checkForConfig = {} -local moduleStack = { -} +--- Establish presence +Veneer = Veneer or CreateFrame('Frame', 'Veneer', UIParent) +local V = Veneer +A.frame = V + +--- Work variables +local modules = {} -- module collector +local queuedModules = {} -- indicates modules that were encountered out of dependency order +local checkForConfig = {} -- indicates frames created from XML that use their own namespace for position control +local moduleStack = {} -- dictates the order in which module methods are fired +local initOnced -- internal check for doing bottom-up SV retrieval --- Utilities -B.wipeall = function (...) +V.wipeall = function (...) for i = 1, select('#', ...) do wipe(select(i, ...)) end end --- Various region categories -B.displays = {} -B.configLayers = {} -B.configLayersRef = {} +V.displays = {} +V.configLayers = {} +V.configLayersRef = {} ---@debug@ ---- Generates a print handler pointing to a static channel signature --- @usage func = B.print(sig) +--- Returns a debug hook for adding generic module information to each message +-- @usage func = V.print(sig) -- @param sig channel name or number +local debugstack = _G.debugstack +local Devian = _G.Devian local printfuncs = {} -B.print = function(pref, ...) +V.print = function(pref, ...) if Devian and Devian.InWorkspace() then printfuncs[pref] = printfuncs[pref] or function(...) print(pref, ...) end @@ -47,6 +57,7 @@ end end +--@debug@ local rgb = {} local getcolor = function() local n, p = 0, 4 @@ -63,12 +74,12 @@ local color = {} local fprints = {} -B.fprint = function() +--- Attempts to generate a debug printer based on the local scope. Results vary by where the originator was invoked. +V.fprint = function() if not (Devian and Devian.InWorkspace()) then return function() end end - local sig = debugstack(2,1) if fprints[sig] then return fprints[sig] @@ -88,14 +99,14 @@ color[sig] = color[sig] or format('|cFF%02X%02X%02X%s|r', r, g, b, func) --print(color[func] .. ' ( ' .. table.concat(args, ', ')..' )' ) - func = B.print(func) + func = V.print(func) fprints[sig] = func return func end --@end-debug@ --[=[@non-debug@ -B.print = function() end +V.print = function() end --@end-non-debug@]=] -- for the Mikk script @@ -105,16 +116,17 @@ -- GLOBALS: CONSOLIDATED_BUFFS_PER_ROW, CONSOLIDATED_BUFF_ROW_HEIGHT, NUM_TEMP_ENCHANT_FRAMES -- GLOBALS: BUFF_BUTTON_HEIGHT, BUFF_FRAME_BASE_EXTENT, BUFF_HORIZ_SPACING -local print = B.print('Bfl') +local print = V.print('Bfl') --- Template for making perpendicular traversals of the displays structure; also makes sure the table is there -B.Abstract = function(dest, key, table) +local setmetatable = setmetatable +V.Abstract = function(dest, key, table) if table then for _, v in pairs(dest) do v[key] = {} end end - B[key] = setmetatable({}, { + V[key] = setmetatable({}, { __index = function(t, k) return dest[k][key] end, @@ -126,26 +138,21 @@ }) - return B[key] + return V[key] end ---- localize for speed - +--- internal local ModulesCall = function(func, flag) - local n = 0 for i = 1, #moduleStack do print('calling level '..i) local stackset = moduleStack[i] - for name, module in pairs(stackset) do n = n + 1 - - if module[func] then -- nil = pass - if not flag or module.Conf[flag] then + if not flag or (module.Conf and module.Conf[flag]) then if (flag) then print(' check', flag, '=', module.Conf[flag]) end @@ -153,7 +160,6 @@ print(' ',n..' '..name..'.'..func..'()') module[func](module, module.Conf) end - end end end @@ -168,7 +174,7 @@ end -local layers, refs, displays = B.configLayers, B.configLayersRef, B.displays +local layers, refs, displays = V.configLayers, V.configLayersRef, V.displays --- Things that happen immediately upon entering world local InitOnce = function() print('entering world first time') @@ -181,7 +187,7 @@ end print('Veneer defaults being used.') end - B.Conf = setmetatable(VeneerData, {__index = function(_, k) return defaults[k] end}) + V.Conf = setmetatable(VeneerData, {__index = function(_, k) return defaults[k] end}) -- To ensure that modules are run in controlled order, walk the dependency list; if the dep shows up -- in the loaded manifest, remove the value. If the dep list isn't empty, move that module to the next @@ -267,8 +273,8 @@ if #checkForConfig >= 1 then local queuedFrame = tremove(checkForConfig) while queuedFrame do - B.SetConfigLayers(queuedFrame) - B.UpdateXMLFrame(queuedFrame) + V.SetConfigLayers(queuedFrame) + V.UpdateXMLFrame(queuedFrame) queuedFrame = tremove(checkForConfig) end end @@ -276,13 +282,13 @@ --- Fires an update to all modules local lastUpdate -function B.UpdateAll(...) +function V.UpdateAll(...) lastUpdate = GetTime() ModulesCall('OnUpdate') end -B:RegisterEvent('PLAYER_ENTERING_WORLD') -B:SetScript('OnEvent', function(self, event) +V:RegisterEvent('PLAYER_ENTERING_WORLD') +V:SetScript('OnEvent', function(self, event) if event == 'PLAYER_ENTERING_WORLD' then if not initOnced then InitOnce() @@ -293,23 +299,23 @@ print(GetSpecialization(), 'enabling') ModulesCall('OnEnable', 'enabled') - B:SetScript('OnUpdate', nil) + V:SetScript('OnUpdate', nil) end end) end end - B.UpdateAll() + V.UpdateAll() if event == 'PLAYER_ENTERING_WORLD' then - B.UpdateConfigLayers() + V.UpdateConfigLayers() end end) --- Modulizer method -- -function B:RegisterModule (name, module, ...) +function V:RegisterModule (name, module, ...) if modules[name] then print('pulling modules[|cFFFF8800'.. tostring(name) ..'|r]') return modules[name] @@ -321,10 +327,10 @@ error("Module table for '"..tostring(name).."' already exists.") end else - module = CreateFrame('Frame', 'Veneer' .. tostring(name) .. 'Handler', B, 'VeneerHandlerTemplate') + module = CreateFrame('Frame', 'Veneer' .. tostring(name) .. 'Handler', V, 'VeneerHandlerTemplate') end modules[name] = module - B[name] = module + V[name] = module if select('#', ...) >= 1 then local numDeps = select('#', ...) print(' '..numDeps..' deps detected') @@ -340,8 +346,8 @@ end -B.SetConfigLayers = function(frame) - local print = B.fprint() +V.SetConfigLayers = function(frame) + local print = V.fprint() if not frame.config then --print(frame:GetName(), 'has no config layers') return @@ -359,9 +365,9 @@ end end -B.RemoveConfigLayers = function(frame) +V.RemoveConfigLayers = function(frame) - local print = B.fprint() + local print = V.fprint() print('|cFFFF0000RemoveConfigLayers', frame:GetName()) for i, subframe in pairs(layers) do if subframe:GetParent() == frame then @@ -373,9 +379,9 @@ end end -B.ToggleGuideLayers = function() - local print = B.fprint() - local func = B.Conf.GuidesMode and 'Show' or 'Hide' +V.ToggleGuideLayers = function() + local print = V.fprint() + local func = V.Conf.GuidesMode and 'Show' or 'Hide' local numAnchors = 0 for id, region in pairs(layers) do @@ -385,17 +391,17 @@ --print('['..func..'] updated', #layers, 'regions,', numAnchors, 'frames') end -B.UpdateConfigLayers = function() +V.UpdateConfigLayers = function() print('|cFFFF0000', debugstack()) - B.ToggleGuideLayers() + V.ToggleGuideLayers() end local XMLFrame_Enable = function(self, value) local name = self:GetName() - local print = B.print('XML') + local print = V.print('XML') - if not B.Conf[name] then - B.Conf[name] = { + if not V.Conf[name] then + V.Conf[name] = { enabled = true } end @@ -403,12 +409,12 @@ print() local enabled if value == nil then - if B.Conf[name].enabled == nil then + if V.Conf[name].enabled == nil then print('toggle based on visibility') enabled = (not self:IsVisible()) and true or false else - print('toggle a config value =', B.Conf[name].enabled) - enabled = B.Conf[name].enabled + print('toggle a config value =', V.Conf[name].enabled) + enabled = V.Conf[name].enabled end enabled = (enabled ~= true) and true or false @@ -417,9 +423,9 @@ enabled = value end - print('arg =', value, 'conf =', B.Conf[name].enabled, 'result=', enabled) + print('arg =', value, 'conf =', V.Conf[name].enabled, 'result=', enabled) - B.Conf[name].enabled = enabled + V.Conf[name].enabled = enabled local stateFunc = enabled and 'Show' or 'Hide' local eventFunc = enabled and 'OnToggle' or 'OnToggle' @@ -431,10 +437,10 @@ end --- toggle action if self.OnToggle then - self:OnToggle(B.Conf[name].enabled) + self:OnToggle(V.Conf[name].enabled) end --- do enable - if B.Conf[name].enabled then + if V.Conf[name].enabled then if self.OnEnable then self:OnEnable() end @@ -445,10 +451,9 @@ end end --- Generic handlers for keeping track of XML-defined frames -local print = B.print('XML') -B.prototypes = {} -B.prototypes.OnDragStart = function(self) - local print = B.print('XML') +local print = V.print('XML') +local prototypes = {} +prototypes.OnDragStart = function(self) self.xA = self:GetLeft() self.yA = self:GetBottom() self.anchorTo, self.relativeTo, self.relativePoint, self.x, self.y = self:GetPoint(1) @@ -457,36 +462,33 @@ self:StartMoving() end -B.prototypes.OnDragStop = function(self) - local print = B.print('XML') +prototypes.OnDragStop = function(self) local name = self:GetName() print(name, 'stop moving ('..self:GetLeft()..', '..self:GetBottom()..')') local xB = self:GetLeft() - self.xA local yB = self:GetBottom() - self.yA print('storing anchor point', self.anchorTo, self.relativePoint, self.x + xB, self.y + yB) - self:StopMovingOrSizing() - B.Conf[name].position = {self.anchorTo, self.relativePoint, self.x + xB, self.y + yB} - B.UpdateXMLFrame(self) + V.Conf[name].position = {self.anchorTo, self.relativePoint, self.x + xB, self.y + yB} + V.UpdateXMLFrame(self) end -B.RegisterModuleFrame = function(self, moduleName) - local print = B.print('XML') +V.RegisterModuleFrame = function(self, moduleName) local name = self:GetName() tinsert(checkForConfig, self) self.Enable = XMLFrame_Enable self.moduleName = moduleName print('|cFF00FF00XML stuff related to '.. tostring(moduleName) .. ':', self:GetName()) ------------------------------------------------------------------------------------------ - if not B[name] then + if not V[name] then return end local scriptTypes = {'OnUpdate', 'OnEvent', 'OnDragStart', 'OnDragStop'} for script in next(scriptTypes) do - if B[name][script] then - self:SetScript(script, B[name][script]) + if V[name][script] then + self:SetScript(script, V[name][script]) end end @@ -494,34 +496,34 @@ local XMLFrame_OnDragStart = function() end local XMLFrame_OnDragStop = function() end -B.UpdateXMLFrame = function(self) - local print = B.print('XML') +V.UpdateXMLFrame = function(self) + local print = V.print('XML') local name = self:GetName() if self.drag then self:RegisterForDrag('LeftButton') - self:SetScript('OnDragStart', XMLFrame_OnDragStart) + self:SetScript('OnDragStart', prototypes.OnDragStart) if self.OnDragStop then self:SetScript('OnDragStop', function(self, ...) print('|cFFFF0088end of dragging') self:OnDragStop(self, ...) - XMLFrame_OnDragStop(self, ...) + prototypes.OnDragStop(self, ...) end) else - self:SetScript('OnDragStop', XMLFrame_OnDragStop) + self:SetScript('OnDragStop', prototypes.OnDragStop) end else self:EnableMouse(false) end - if not B.Conf[name] then - B.Conf[name] = { + if not V.Conf[name] then + V.Conf[name] = { enabled = self.enabled, } end - local c = B.Conf[name] + local c = V.Conf[name] if not c.position then local anchor, _, point, x, y = self:GetPoint(1)