annotate Turok.lua @ 1:766d8a40a1d6

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