annotate Turok.lua @ 5:8a9a6637f082

focusbar data collection tracking db info declarations to main chunk
author Nenue
date Tue, 15 Dec 2015 10:10:22 -0500
parents 62f9b057c91b
children
rev   line source
Nenue@1 1
Nenue@1 2 -- GLOBALS: DEFAULT_CHAT_FRAME, SlashCmdList, hash_SlashCmdList
Nenue@1 3 local T = LibStub("AceAddon-3.0"):NewAddon("Turok", "AceConsole-3.0", "AceEvent-3.0")
Nenue@1 4 local _G = _G
Nenue@1 5 local rawset = _G.rawset
Nenue@1 6 _G.Turok = T
Nenue@1 7 local print = function(...)
Nenue@1 8 --_G.print('Core', ...)
Nenue@1 9 end
Nenue@1 10
Nenue@1 11
Nenue@1 12 T.mods = {}
Nenue@1 13 T:SetDefaultModuleState(true)
Nenue@1 14 T:SetDefaultModuleLibraries("AceEvent-3.0")
Nenue@1 15 T:SetDefaultModulePrototype({OnInitialize = function(mod)
Nenue@1 16 print('CORE', mod:GetName().. ' found')
Nenue@1 17 end})
Nenue@1 18
Nenue@1 19 -- propagates parameter data around
Nenue@1 20 function T:LinkTable(parent, child, pname, cname)
Nenue@1 21 local mt = {
Nenue@1 22 __index = function(t,k)
Nenue@1 23 if parent[k] then
Nenue@1 24 t[k] = parent[k]
Nenue@1 25 end
Nenue@1 26 print('|cFFFF8800'.. pname ..'.' .. cname .. '|r.|cFFFFFF00'.. k ..'|r inheriting value at |cFFFF8800' .. pname ..'|r.|cFFFFFF00'.. k..'|r')
Nenue@1 27 return parent[k]
Nenue@1 28 end,
Nenue@1 29 __newindex = function (t, k, v)
Nenue@1 30 rawset(t,k,v)
Nenue@1 31 if type(v) == 'table' then
Nenue@1 32 T:LinkTable(child, v, pname, k)
Nenue@1 33 print('|cFFFF8800'.. pname ..'.' .. cname .. '|r.|cFFFFFF00'.. k ..'|r sub-table created')
Nenue@1 34 end
Nenue@1 35 end
Nenue@1 36 }
Nenue@1 37 print('|cFFFF8800'.. pname ..'.|cFFFFFF00'.. cname ..'|r sub-tables will be retconned')
Nenue@1 38 setmetatable(child, mt)
Nenue@1 39 for k, v in pairs(child) do
Nenue@1 40 if type(v) == 'table' then
Nenue@1 41 T:LinkTable(child, v, cname, k)
Nenue@1 42 end
Nenue@1 43 end
Nenue@1 44 end
Nenue@1 45
Nenue@1 46 function T:OnInitialize()
Nenue@1 47
Nenue@1 48 local defaults = {
Nenue@1 49 background_color = {0,0,0,0},
Nenue@1 50 background_blend = 'BLEND',
Nenue@1 51 foreground_color = {1,1,1,0.5},
Nenue@1 52 foreground_blend = 'BLEND',
Nenue@1 53 foreground_inset = -1,
Nenue@1 54 width = 250,
Nenue@1 55 height = 100,
Nenue@1 56 alpha = 1,
Nenue@1 57 alpha_ooc = 0.1,
Nenue@1 58 strata = 'LOW',
Nenue@1 59 label_strata = 'HIGH',
Nenue@1 60 label_justifyH = 'LEFT',
Nenue@1 61 label_color = {1, 1, 1, 1},
Nenue@1 62 label_font = 'turok',
Nenue@1 63 label_size = 14,
Nenue@1 64 label_inset = -2,
Nenue@1 65 label_point = 'LEFT',
Nenue@1 66 label_outline = 'OUTLINE',
Nenue@1 67 anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
Nenue@1 68 focusbar = {
Nenue@1 69 foreground_color = {1, 1, 1, 0.7},
Nenue@1 70 background_color = {0,0,0,0.8},
Nenue@1 71 width = 300, height = 24,
Nenue@1 72 posX = 0, posY = -150,
Nenue@1 73 },
Nenue@1 74 }
Nenue@1 75 _G.TurokData = defaults
Nenue@1 76 if not _G.TurokData then
Nenue@1 77 _G.TurokData = defaults
Nenue@1 78 end
Nenue@1 79
Nenue@1 80 T.db = _G.TurokData
Nenue@1 81 local db = T.db
Nenue@1 82 for k, v in pairs(db) do
Nenue@1 83 if type(v) == 'table' then
Nenue@1 84 T:LinkTable(db, v, 'db', k)
Nenue@1 85 end
Nenue@1 86 end
Nenue@1 87 setmetatable(db,
Nenue@1 88 {__newindex = function (t, k, v)
Nenue@1 89 rawset(t,k,v)
Nenue@1 90 if type(v) == 'table' then
Nenue@1 91 T:LinkTable(db, v, 'db', k)
Nenue@1 92 print('CFG', '|cFFFF0000db|r.|cFF00FFFF' .. k ..'|r created at bottom level')
Nenue@1 93 end
Nenue@1 94 end})
Nenue@1 95
Nenue@1 96 options = {
Nenue@1 97 type = 'group',
Nenue@1 98 name = 'Turok',
Nenue@1 99 handler = T,
Nenue@1 100 set = function(info,value)
Nenue@1 101 local k = db[info[1]]
Nenue@1 102 for i = 2, #info-1 do
Nenue@1 103 if type(k[i]) ~= 'table' then
Nenue@1 104 print('fart')
Nenue@1 105 end
Nenue@1 106
Nenue@1 107 k = k[i]
Nenue@1 108 end
Nenue@1 109 k[info[#info]] = value
Nenue@1 110 end,
Nenue@1 111 get = function(info)
Nenue@1 112 local k = db[info[1]]
Nenue@1 113 for i = 2, #info-1 do
Nenue@1 114 if type(k[i]) ~= 'table' then
Nenue@1 115 print('fart')
Nenue@1 116 end
Nenue@1 117
Nenue@1 118 k = k[i]
Nenue@1 119 end
Nenue@1 120 return k[info[#info]]
Nenue@1 121 end,
Nenue@1 122 desc = '"Dinosaur" Hunter',
Nenue@1 123 args = {
Nenue@1 124 background_color = {
Nenue@1 125 type = 'color',
Nenue@1 126 name = 'Background Color',
Nenue@1 127 hasAlpha = true,
Nenue@1 128 }
Nenue@1 129 }
Nenue@1 130 }
Nenue@1 131 LibStub("AceConfig-3.0"):RegisterOptionsTable('Turok', options, {"tk"})
Nenue@1 132
Nenue@1 133 end
Nenue@1 134
Nenue@1 135
Nenue@1 136 function T:OnEnable()
Nenue@1 137 local db = _G.TurokData
Nenue@1 138
Nenue@1 139 print('I... am Turok')
Nenue@1 140
Nenue@5 141 self.stats = {
Nenue@5 142 maxpower = UnitPowerMax('player')
Nenue@5 143 }
Nenue@1 144
Nenue@1 145
Nenue@1 146 T.focusbar = T:CreateBar('TkFocusBar', db.focusbar)
Nenue@1 147 local fb = T.focusbar
Nenue@1 148 T:AddLabel(fb, db.focusbar)
Nenue@1 149 fb:Update(UnitPower("player"), 0, UnitPowerMax("player"))
Nenue@1 150 T:Bar_SetUpdateHandler(fb, function(self)
Nenue@5 151 local pp = UnitPower("player")
Nenue@5 152 if pp == T.stats.maxpower and not T.stats.capped then
Nenue@5 153 T.stats.capped = true
Nenue@5 154 elseif T.stats.capped then
Nenue@5 155 T.stats.capped = false
Nenue@5 156 end
Nenue@5 157 T.Bar_Update(fb, pp)
Nenue@1 158 end)
Nenue@1 159 end